o
    ŀg"J                     @  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Zd dl	m
Z d dlmZmZmZmZmZ d dl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  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/m0Z0 d dl1m2Z2m3Z3 d dl4m5Z5 erd dl6m7Z7 d dl8m9Z9m:Z:m;Z;m<Z< e=e-j>Z>e>?ddi ddiZ@dd ZAe5g de"jB e"dde5dge"G dd  d e0ZC					d(d)d&d'ZDdS )*    )annotations)datetime	timedelta)TYPE_CHECKINGN)index)
BaseOffsetNaTPeriod
ResolutionTick)OFFSET_TO_PERIOD_FREQSTR)cache_readonlydoc)find_stack_level)
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.   N/var/www/html/myenv/lib/python3.10/site-packages/pandas/core/indexes/period.py_new_PeriodIndexD   s   

r0   )strftime
start_timeend_timeT)wrapis_leap_yearc                
      s  e Zd ZU dZdZded< ded< ded< eZd	Ze	d_ddZ
ed`ddZeejfdddedadbddZeejdcddddZe	eejjdedd Ze	eejjded!d"Ze	eejjded#d$Z					%	dfdgd+d,Zeddddddddd-dhd.d/Zedd0dhd1d2Ze	did4d5Zdjd7d8Zdkd:d;Zdl fd@dAZe	dmdBdCZe	dndDdEZ fdFdGZdHdI Z dodMdNZ!dpdQdRZ"ee#j$dq fdTdUZ$drdXdYZ%ee#j&dsdtd]d^Z&  Z'S )u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

        .. deprecated:: 2.2.0
           Use PeriodIndex.from_fields instead.
    month : int, array, or Series, default None

        .. deprecated:: 2.2.0
           Use PeriodIndex.from_fields instead.
    quarter : int, array, or Series, default None

        .. deprecated:: 2.2.0
           Use PeriodIndex.from_fields instead.
    day : int, array, or Series, default None

        .. deprecated:: 2.2.0
           Use PeriodIndex.from_fields instead.
    hour : int, array, or Series, default None

        .. deprecated:: 2.2.0
           Use PeriodIndex.from_fields instead.
    minute : int, array, or Series, default None

        .. deprecated:: 2.2.0
           Use PeriodIndex.from_fields instead.
    second : int, array, or Series, default None

        .. deprecated:: 2.2.0
           Use PeriodIndex.from_fields instead.
    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
    from_fields
    from_ordinals

    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.from_fields(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/   rA      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)r8   asfreqtyper*   rI   r?   r&   rE   arrr.   r.   r/   rJ      s   zPeriodIndex.asfreqstartr   c                 C  s   | j ||}tj|| jdS rG   )r8   to_timestampr   r*   rI   rL   r.   r.   r/   rO      s   zPeriodIndex.to_timestampr   c                 C     t | jj| jdS rG   )r   r8   hourrI   r>   r.   r.   r/   rQ         zPeriodIndex.hourc                 C  rP   rG   )r   r8   minuterI   r>   r.   r.   r/   rS      rR   zPeriodIndex.minutec                 C  rP   rG   )r   r8   secondrI   r>   r.   r.   r/   rT      rR   zPeriodIndex.secondFDtype | NonecopyboolrI   Hashable | Nonec                 K  s  h d}d }	|st |ttfr|j}	t||s*ttt|| }
td|
 t	|r7t
jdtt d |d urDt
jdtt d t||| }|d u ri|d u ri|sY| d  | jdi |d|ij}d}nQ|rw|d urstdtd	t||}|rt || r|j|kr||}|d u r|d urtj|tjd
}t|}t||d
}n|d ur|d urtdt||d}|r| }| j|||	dS )N>   dayrQ   yearmonthrS   rT   quarterz-__new__() got an unexpected keyword argument zXConstructing PeriodIndex from fields is deprecated. Use PeriodIndex.from_fields instead.)
stacklevelzThe 'ordinal' keyword in PeriodIndex is deprecated and will be removed in a future version. Use PeriodIndex.from_ordinals instead.r&   Fz Cannot pass both data and fieldsz#Cannot pass both ordinal and fieldsr'   z!Cannot pass both data and ordinal)r$   r&   )rI   refsr.   )
isinstancer   r   _referencessetissubsetnextiter	TypeErrorlenwarningswarnFutureWarningr   r   _raise_scalar_data_errorfrom_fieldsr8   
ValueErrorr   r&   rJ   npasarrayr%   r   r   r   rV   r*   )r+   r$   ordinalr&   r(   rV   rI   fieldsvalid_field_setr^   argumentr.   r.   r/   __new__   sT   




zPeriodIndex.__new__)rZ   r\   r[   rY   rQ   rS   rT   r&   c                C  s>   |||||||d}	dd |	  D }	tj|	|d}
| |
S )N)rZ   r\   r[   rY   rQ   rS   rT   c                 S  s   i | ]\}}|d ur||qS r;   r.   ).0keyvaluer.   r.   r/   
<dictcomp>W  s    z+PeriodIndex.from_fields.<locals>.<dictcomp>)rp   r&   )itemsr   _from_fieldsr*   )r+   rZ   r\   r[   rY   rQ   rS   rT   r&   rp   rM   r.   r.   r/   rk   A  s   	
zPeriodIndex.from_fieldsrH   c                C  s4   t j|t jd}t|}tj||d}| j||dS )Nr'   rH   )rm   rn   r%   r   r   r*   )r+   ordinalsr&   rI   r(   r$   r.   r.   r/   from_ordinals[  s   zPeriodIndex.from_ordinalsnpt.NDArray[np.object_]c                 C  s   t j| tdS )Nr'   )rm   rn   objectr>   r.   r.   r/   r-   e  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   rm   timedelta64r   ndarrayr&   r8    _check_timedeltalike_freq_compatr   basenr   r   int)r?   rB   deltar.   r.   r/   _maybe_convert_timedeltai  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   r6   _valuesr&   re   super	asof_locs)r?   r   r   	__class__r.   r/   r     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   )rf   is_monotonic_increasingrl   asi8rW   all)r?   r-   r.   r.   r/   is_full  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(   r   )r?   	tolerancetargetr   r.   r/   r     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_   rF   _parse_with_resorl   KeyError_can_partial_date_slice_partial_date_slicerA   _cast_partial_indexing_scalarr	   _disallow_mismatched_indexingr   r   get_loc)r?   ru   orig_keyparsedresoerrr.   r.   r/   r     s@   







zPeriodIndex.get_locru   r	   Nonec                 C  s   |j | jkr
t|d S r;   )_dtyper(   r   )r?   ru   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&   rl   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|j}t||d}|j| jdd|j| jddfS )Nr   rN   )rE   end)r   getattr_abbrevr	   rJ   r&   )r?   r   r   r&   ivr.   r.   r/   _parsed_string_to_bounds  s    z$PeriodIndex._parsed_string_to_boundsr   periodsr   c                 C  s&   |d urt dt| j d| | S )Nz%`freq` argument is not supported for z.shift)re   rK   __name__)r?   r   r&   r.   r.   r/   shift  s
   zPeriodIndex.shift)r9   r:   )r9   r
   )NrD   )rE   rF   r9   r    )NrN   )rE   rF   r9   r   )r9   r   )NNNNFN)r(   rU   rV   rW   rI   rX   r9   r    )r9   r    )r9   r|   )r9   r~   )r(   r   r9   rW   )r   r   r   r   r9   r   )r9   rW   )r9   rF   )ru   r	   r9   r   )r   r   r9   r	   )r   rF   )r   r
   r   r   )r   N)r   r   r9   r    )(r   
__module____qualname____doc___typ__annotations__r   	_data_cls!_supports_partial_string_indexingpropertyr@   r   rA   r   rJ   _shared_doc_kwargsrO   rQ   fgetrS   rT   rs   classmethodrk   r{   r-   r   r   r   r   r   r   r   r   r   r   r   r   r   __classcell__r.   r.   r   r/   r6   P   s   
 \


W	

"	
>

r6   r   
int | NonerI   rX   r9   c                 C  sn   t | ||dkrtd|du rt| tst|tsd}t| |||\}}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Dr'   rH   )	comcount_not_nonerl   r_   r	   r   _generate_ranger   r6   )rN   r   r   r&   rI   r$   r(   r.   r.   r/   period_range#  s   8r   )NNNNN)r   r   rI   rX   r9   r6   )E
__future__r   r   r   typingr   rg   numpyrm   pandas._libsr   r<   pandas._libs.tslibsr   r   r	   r
   r   pandas._libs.tslibs.dtypesr   pandas.util._decoratorsr   r   pandas.util._exceptionsr   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indexesr   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   r0   
_field_opsr6   r   r.   r.   r.   r/   <module>   sZ    

   Q