o
    ҷh@                     @  s  d dl mZ d dlmZmZ d dlmZ d dlZd dlm	Z
 d dlmZmZmZmZmZ d dlmZmZ d dlmZ d d	lmZ d d
lmZ d dlmZ d dlmZmZmZm Z  d dl!m"  m#Z$ d dl%m"  m&  m'Z( d dl%m)Z) d dl*m+Z+ d dl,m-Z-m.Z. d dl/m0Z0 erd dl1m2Z2 d dl3m4Z4m5Z5m6Z6m7Z7 e8e(j9Z9e9:ddi ddiZ;dd Z<e0g dej= edde0ddgeG dd de+Z>					d'd(d%d&Z?dS ))    )annotations)datetime	timedelta)TYPE_CHECKINGN)index)
BaseOffsetNaTPeriod
ResolutionTick)cache_readonlydoc)
is_integer)PeriodDtype)	ABCSeries)is_valid_na_for_dtype)PeriodArrayperiod_arrayraise_on_incompatiblevalidate_dtype_freq)maybe_extract_name)DatetimeIndexOpsMixin)DatetimeIndexIndex)inherit_names)Hashable)DtypeDtypeObjSelfnpttarget_klasszPeriodIndex or list of Periodsklassr   c                 K  sV   | d}|jdkr#| dd }t|}t||d}| j|fi |S | |fi |S )Ndataint64freqdtype)popr&   r   r   _simple_new)clsdvaluesr$   r&    r,   M/var/www/html/venv/lib/python3.10/site-packages/pandas/core/indexes/period.py_new_PeriodIndexA   s   

r.   )strftime
start_timeend_timeT)wrapis_leap_year_format_native_typesc                      s  e Zd ZU dZdZded< ded< ded< eZd	Ze	dYddZ
edZddZeejfddded[d\ddZeejd]d^ddZe	eejjd_dd Ze	eejjd_d!d"Ze	eejjd_d#d$Z					%	d`dad+d,Ze	dbd.d/Zdcd1d2Zddd4d5Zde fd:d;Ze	dfd<d=Ze	dgd>d?Z fd@dAZdBdC ZdhdGdHZdidKdLZee j!dj fdNdOZ!dkdRdSZ"ee j#dldmdWdXZ#  Z$S )nPeriodIndexa  
    Immutable ndarray holding ordinal values indicating regular periods in time.

    Index keys are boxed to Period objects which carries the metadata (eg,
    frequency information).

    Parameters
    ----------
    data : array-like (1d int np.ndarray or PeriodArray), optional
        Optional period-like data to construct index with.
    copy : bool
        Make a copy of input ndarray.
    freq : str or period object, optional
        One of pandas period strings or corresponding objects.
    year : int, array, or Series, default None
    month : int, array, or Series, default None
    quarter : int, array, or Series, default None
    day : int, array, or Series, default None
    hour : int, array, or Series, default None
    minute : int, array, or Series, default None
    second : int, array, or Series, default None
    dtype : str or PeriodDtype, default None

    Attributes
    ----------
    day
    dayofweek
    day_of_week
    dayofyear
    day_of_year
    days_in_month
    daysinmonth
    end_time
    freq
    freqstr
    hour
    is_leap_year
    minute
    month
    quarter
    qyear
    second
    start_time
    week
    weekday
    weekofyear
    year

    Methods
    -------
    asfreq
    strftime
    to_timestamp

    See Also
    --------
    Index : The base pandas Index type.
    Period : Represents a period of time.
    DatetimeIndex : Index with datetime64 data.
    TimedeltaIndex : Index of timedelta64 data.
    period_range : Create a fixed-frequency PeriodIndex.

    Examples
    --------
    >>> idx = pd.PeriodIndex(year=[2000, 2002], quarter=[1, 3])
    >>> idx
    PeriodIndex(['2000Q1', '2002Q3'], dtype='period[Q-DEC]')
    periodindexr   _datar   r$   r   r&   Treturntype[libindex.PeriodEngine]c                 C  s   t jS N)libindexPeriodEngineselfr,   r,   r-   _engine_type   s   zPeriodIndex._engine_typer
   c                 C  s   | j jS r:   )r&   _resolution_objr=   r,   r,   r-   r@      s   zPeriodIndex._resolution_objzpandas.arrays.PeriodArray)other
other_nameNEhowstrr   c                 C  s"   | j ||}t| j|| jdS Nname)r7   asfreqtyper(   rH   r>   r$   rD   arrr,   r,   r-   rI      s   zPeriodIndex.asfreqstartr   c                 C  s   | j ||}tj|| jdS rF   )r7   to_timestampr   r(   rH   rK   r,   r,   r-   rN      s   zPeriodIndex.to_timestampr   c                 C     t | jj| jdS rF   )r   r7   hourrH   r=   r,   r,   r-   rP         zPeriodIndex.hourc                 C  rO   rF   )r   r7   minuterH   r=   r,   r,   r-   rR      rQ   zPeriodIndex.minutec                 C  rO   rF   )r   r7   secondrH   r=   r,   r,   r-   rS      rQ   zPeriodIndex.secondFDtype | NonecopyboolrH   Hashable | Nonec                 K  s8  h d}d }	|st |ttfr|j}	t||s*ttt|| }
td|
 t	||| }|d u rW|d u rW|s?| 
d  td d d ||\}}|}t|}t||d}n7t||}|rmt || rm|j|krm||}|d u r|d urtj|tjd}t|}t||d}nt||d}|r| }| j|||	dS )N>   dayrP   yearmonthrR   rS   quarterz-__new__() got an unexpected keyword argument r%   )r"   r$   )rH   refs)
isinstancer   r   _referencessetissubsetnextiter	TypeErrorr   _raise_scalar_data_errorr   _generate_ranger   r   r$   rI   npasarrayr#   r   rU   r(   )r)   r"   ordinalr$   r&   rU   rH   fieldsvalid_field_setr\   argumentfreq2r,   r,   r-   __new__   s4   




zPeriodIndex.__new__npt.NDArray[np.object_]c                 C  s   t j| tdS )Nr%   )rf   rg   objectr=   r,   r,   r-   r+     s   zPeriodIndex.valuesint | npt.NDArray[np.int64]c                 C  s   t |ttjttjfrt | jtr| j|}|S n!t |t	r.|j
| jj
kr)|jS t| |t|r;t |ts9J |S t| d)a  
        Convert timedelta-like input to an integer multiple of self.freq

        Parameters
        ----------
        other : timedelta, np.timedelta64, DateOffset, int, np.ndarray

        Returns
        -------
        converted : int, np.ndarray[int64]

        Raises
        ------
        IncompatibleFrequency : if the input cannot be written as a multiple
            of self.freq.  Note IncompatibleFrequency subclasses ValueError.
        N)r]   r   rf   timedelta64r   ndarrayr$   r7    _check_timedeltalike_freq_compatr   basenr   r   int)r>   rA   deltar,   r,   r-   _maybe_convert_timedelta  s   


z$PeriodIndex._maybe_convert_timedeltar   c                 C  s
   | j |kS )zF
        Can we compare values of the given dtype to our own?
        r%   )r>   r&   r,   r,   r-   _is_comparable_dtype=  s   
z PeriodIndex._is_comparable_dtypewheremasknpt.NDArray[np.bool_]
np.ndarrayc                   s<   t |trt|j| jd}n	t |tstdt ||S )z
        where : array of timestamps
        mask : np.ndarray[bool]
            Array of booleans where data is not NA.
        r$   z6asof_locs `where` must be DatetimeIndex or PeriodIndex)r]   r   r5   _valuesr$   rc   super	asof_locs)r>   rz   r{   	__class__r,   r-   r   F  s
   

zPeriodIndex.asof_locsc                 C  sH   t | dkrdS | jstd| j}t|dd |dd  dk  S )z
        Returns True if this PeriodIndex is range-like in that all Periods
        between start and end are present, in order.
        r   TzIndex is not monotonic   N   )lenis_monotonic_increasing
ValueErrorasi8rV   all)r>   r+   r,   r,   r-   is_fullS  s   $zPeriodIndex.is_fullc                 C  s   dS )Nperiodr,   r=   r,   r,   r-   inferred_type`  s   zPeriodIndex.inferred_typec                   s(   t  ||}| j|jkr| |}|S r:   )r   _convert_tolerancer&   rx   )r>   	tolerancetargetr   r,   r-   r   i  s   
zPeriodIndex._convert_tolerancec              
   C  s(  |}|  | t|| jrt}nkt|traz	| |\}}W n ty3 } z	td| d|d}~ww | 	|rRz| 
||W S  tyQ } zt||d}~ww || jkr]| |}nt|t|trl| | nt|trw| |}nt|zt| |W S  ty } zt||d}~ww )a  
        Get integer location for requested label.

        Parameters
        ----------
        key : Period, NaT, str, or datetime
            String or datetime key must be parsable as Period.

        Returns
        -------
        loc : int or ndarray[int64]

        Raises
        ------
        KeyError
            Key is not present in the index.
        TypeError
            If key is listlike or otherwise not hashable.
        zCannot interpret 'z' as periodN)_check_indexing_errorr   r&   r   r]   rE   _parse_with_resor   KeyError_can_partial_date_slice_partial_date_slicer@   _cast_partial_indexing_scalarr	   _disallow_mismatched_indexingr   r   get_loc)r>   keyorig_keyparsedresoerrr,   r,   r-   r   v  s@   







zPeriodIndex.get_locr   r	   Nonec                 C  s   |j | jkr
t|d S r:   )_dtyper&   r   )r>   r   r,   r,   r-   r     s   z)PeriodIndex._disallow_mismatched_indexinglabelr   c              
   C  s8   z
t || jd}W |S  ty } zt||d }~ww )Nr~   )r	   r$   r   r   )r>   r   r   r   r,   r,   r-   r     s   
z)PeriodIndex._cast_partial_indexing_scalarsidec                   s"   t |tr
| |}t ||S r:   )r]   r   r   r   _maybe_cast_slice_bound)r>   r   r   r   r,   r-   r     s   

z#PeriodIndex._maybe_cast_slice_boundr   r   c                 C  s.   t ||jd}|j| jdd|j| jddfS )Nr~   rM   )rD   end)r	   attr_abbrevrI   r$   )r>   r   r   ivr,   r,   r-   _parsed_string_to_bounds  s    z$PeriodIndex._parsed_string_to_boundsr   periodsrv   c                 C  s&   |d urt dt| j d| | S )Nz%`freq` argument is not supported for z.shift)rc   rJ   __name__)r>   r   r$   r,   r,   r-   shift  s
   zPeriodIndex.shift)r8   r9   )r8   r
   )NrC   )rD   rE   r8   r   )NrM   )rD   rE   r8   r   )r8   r   )NNNNFN)r&   rT   rU   rV   rH   rW   r8   r   )r8   rn   )r8   rp   )r&   r   r8   rV   )rz   r   r{   r|   r8   r}   )r8   rV   )r8   rE   )r   r	   r8   r   )r   r   r8   r	   )r   rE   )r   r
   r   r   )r   N)r   rv   r8   r   )%r   
__module____qualname____doc___typ__annotations__r   	_data_cls!_supports_partial_string_indexingpropertyr?   r   r@   r   rI   _shared_doc_kwargsrN   rP   fgetrR   rS   rm   r+   rx   ry   r   r   r   r   r   r   r   r   r   r   r   __classcell__r,   r,   r   r-   r5   M   sr   
 E


G

"	
>

r5   r   
int | NonerH   rW   r8   c                 C  sr   t | ||dkrtd|du rt| tst|tsd}tj| |||i d\}}t|}t||d}t||dS )a  
    Return a fixed frequency PeriodIndex.

    The day (calendar) is the default frequency.

    Parameters
    ----------
    start : str, datetime, date, pandas.Timestamp, or period-like, default None
        Left bound for generating periods.
    end : str, datetime, date, pandas.Timestamp, or period-like, default None
        Right bound for generating periods.
    periods : int, default None
        Number of periods to generate.
    freq : str or DateOffset, optional
        Frequency alias. By default the freq is taken from `start` or `end`
        if those are Period objects. Otherwise, the default is ``"D"`` for
        daily frequency.
    name : str, default None
        Name of the resulting PeriodIndex.

    Returns
    -------
    PeriodIndex

    Notes
    -----
    Of the three parameters: ``start``, ``end``, and ``periods``, exactly two
    must be specified.

    To learn more about the frequency strings, please see `this link
    <https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#offset-aliases>`__.

    Examples
    --------
    >>> pd.period_range(start='2017-01-01', end='2018-01-01', freq='M')
    PeriodIndex(['2017-01', '2017-02', '2017-03', '2017-04', '2017-05', '2017-06',
             '2017-07', '2017-08', '2017-09', '2017-10', '2017-11', '2017-12',
             '2018-01'],
            dtype='period[M]')

    If ``start`` or ``end`` are ``Period`` objects, they will be used as anchor
    endpoints for a ``PeriodIndex`` with frequency matching that of the
    ``period_range`` constructor.

    >>> pd.period_range(start=pd.Period('2017Q1', freq='Q'),
    ...                 end=pd.Period('2017Q2', freq='Q'), freq='M')
    PeriodIndex(['2017-03', '2017-04', '2017-05', '2017-06'],
                dtype='period[M]')
    r   zOOf the three parameters: start, end, and periods, exactly two must be specifiedND)ri   r%   rG   )	comcount_not_noner   r]   r	   r   re   r   r5   )rM   r   r   r$   rH   r"   r&   r,   r,   r-   period_range  s   8r   )NNNNN)r   r   rH   rW   r8   r5   )@
__future__r   r   r   typingr   numpyrf   pandas._libsr   r;   pandas._libs.tslibsr   r   r	   r
   r   pandas.util._decoratorsr   r   pandas.core.dtypes.commonr   pandas.core.dtypes.dtypesr   pandas.core.dtypes.genericr   pandas.core.dtypes.missingr   pandas.core.arrays.periodr   r   r   r   pandas.core.commoncorecommonr   pandas.core.indexes.baseindexesrt   ibaser    pandas.core.indexes.datetimeliker   pandas.core.indexes.datetimesr   r   pandas.core.indexes.extensionr   collections.abcr   pandas._typingr   r   r   r   dict_index_doc_kwargsupdater   r.   
_field_opsr5   r   r,   r,   r,   r-   <module>   sT    
   