o
    5caK                     @  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mZ d dlmZmZmZmZmZ d dlmZmZmZ d dlmZmZ d d	lmZ d d
lmZmZ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/Z0 d dl-m1Z1 d dl2m3Z3 d dl4m5Z5m6Z6 d dl7m8Z8 d dl9m:Z: e;e0j<Z<e<=ddi ddiZ>dd Z?e8g de%j@ e%dde8ddge%G dd de3ZA	d%d&d#d$ZBdS )'    )annotations)datetime	timedelta)HashableN)indexlib)
BaseOffsetNaTPeriod
ResolutionTick)DtypeDtypeObjnpt)cache_readonlydoc)find_stack_level)is_datetime64_any_dtype
is_integerpandas_dtype)PeriodDtype)is_valid_na_for_dtype)PeriodArrayperiod_arrayraise_on_incompatiblevalidate_dtype_freq)maybe_extract_name)DatetimeIndexOpsMixin)DatetimeIndexIndex)inherit_names)
Int64Indextarget_klasszPeriodIndex or list of Periodsklassr   c                 K  sN   | d}|jdkr| dd }t||d}| j|fi |S | |fi |S )Ndataint64freqr&   )popdtyper   _simple_new)clsdvaluesr&    r.   P/var/www/html/gps/gps/lib/python3.10/site-packages/pandas/core/indexes/period.py_new_PeriodIndexD   s   

r0   )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	dSddZ
edTddZeejfdddedUdVddZeejdWdXddZe	eejjdYddZe	eejjdYd d!Ze	eejjdYd"d#Z					$	dZd[d*d+Ze	d\d-d.Zd]d0d1Zd^d3d4Zd_ fd9d:Zeejd	ejfd` fd;d<Ze	dad=d>Ze	dbd?d@Z fdAdBZ dcdCdDZ!dddGdHZ"dIdJ Z#ee$j%ejfde fdLdMZ%dfdQdRZ&  Z'S )g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/   rB      s   zPeriodIndex._resolution_objzpandas.arrays.PeriodArray)other
other_nameNEhowstrc                 C  s"   | j ||}t| j|| jdS Nname)r9   asfreqtyper*   rJ   r@   r&   rF   arrr.   r.   r/   rK      s   zPeriodIndex.asfreqstartr   c                 C  s   | j ||}tj|| jdS rH   )r9   to_timestampr   r*   rJ   rM   r.   r.   r/   rP      s   zPeriodIndex.to_timestampr!   c                 C     t | jj| jdS rH   )r!   r9   hourrJ   r?   r.   r.   r/   rR         zPeriodIndex.hourc                 C  rQ   rH   )r!   r9   minuterJ   r?   r.   r.   r/   rT      rS   zPeriodIndex.minutec                 C  rQ   rH   )r!   r9   secondrJ   r?   r.   r.   r/   rU      rS   zPeriodIndex.secondFDtype | NonecopyboolrJ   r   c                 K  s
  h d}t ||stt || d }	td|	 t||| }|d u rE|d u rE|s1| d td d d ||\}}
|
}t||d}n3t||}|r[t	|| r[|j
|kr[||}|d u rr|d urrtj|tjd}t||d}nt||d}|r~| }| j||dS )N>   dayrR   yearmonthrT   rU   quarterr   z-__new__() got an unexpected keyword argument r'   r)   )r$   r&   rI   )setissubsetlist	TypeErrorr   _scalar_data_errorr   _generate_ranger   
isinstancer&   rK   npasarrayr%   r   rW   r*   )r+   r$   ordinalr&   r)   rW   rJ   fieldsvalid_field_setargumentfreq2r.   r.   r/   __new__   s*   



zPeriodIndex.__new__
np.ndarrayc                 C  s   t j| tdS )Nr]   )re   rf   objectr?   r.   r.   r/   r-     s   zPeriodIndex.valuesint | npt.NDArray[np.int64]c                 C  sr   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|r4|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)rd   r   re   timedelta64r   ndarrayr&   r9    _check_timedeltalike_freq_compatr   basenr   r   )r@   rC   deltar.   r.   r/   _maybe_convert_timedelta  s   


z$PeriodIndex._maybe_convert_timedeltar   c                 C  s2   t |tsdS |j}| j}|j|jko|j|jkS )zF
        Can we compare values of the given dtype to our own?
        F)rd   r   r&   _period_dtype_codert   )r@   r)   r&   own_freqr.   r.   r/   _is_comparable_dtypeC  s   

z PeriodIndex._is_comparable_dtypewherer   masknpt.NDArray[np.bool_]c                   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)rd   r   r7   _valuesr&   ra   super	asof_locs)r@   rz   r{   	__class__r.   r/   r   Y  s
   

zPeriodIndex.asof_locsc                   s`   t |}|tjurtjdtt d nd}t|r(t|dd }| j	|d
|S t j||dS )NzThe 'how' keyword in PeriodIndex.astype is deprecated and will be removed in a future version. Use index.to_timestamp(how=how) instead.)
stacklevelrO   tzrF   )rW   )r   r   
no_defaultwarningswarnFutureWarningr   r   getattrrP   tz_localizer~   astype)r@   r)   rW   rF   r   r   r.   r/   r   f  s   
zPeriodIndex.astypec                 C  sD   t | dkrdS | jstd| j}|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asi8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)   rv   )r@   	tolerancetargetr   r.   r/   r     s   
zPeriodIndex._convert_tolerancec           	   
   C  sR  |}|  | t|| jrt}n~t|trtz	| |\}}W n ty3 } z	td| d|d}~ww | 	|rRz| 
||W S  tyQ } zt||d}~ww || jkrf| |}| j|||d}|S |du rnt|| |}nt|tr| |}nt|tr| |}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)methodr   )_check_indexing_errorr   r)   r	   rd   rG   _parse_with_resor   KeyError_can_partial_date_slice_partial_date_slicerB   _cast_partial_indexing_scalarget_locr
   _maybe_cast_for_get_locr   r   )	r@   keyr   r   orig_keyparsedresoerrlocr.   r.   r/   r     sH   








zPeriodIndex.get_locr   r
   c                 C  s0   | j }|j }|j|jkr|j|jkst||S r<   )r&   rt   rw   r   )r@   r   sfreqkfreqr.   r.   r/   r     s   

z#PeriodIndex._maybe_cast_for_get_locc              
   C  s8   z
t || jd}W |S  ty } zt||d }~ww )Nr'   )r
   r&   r   r   )r@   labelr   r   r.   r.   r/   r     s   
z)PeriodIndex._cast_partial_indexing_scalarsidec                   s&   t |tr
| |}t j|||dS )N)kind)rd   r   r   r~   _maybe_cast_slice_bound)r@   r   r   r   r   r.   r/   r     s   

z#PeriodIndex._maybe_cast_slice_boundr   r   r   c                 C  s.   t ||jd}|j| jdd|j| jddfS )Nr'   rO   r   end)r
   attr_abbrevrK   r&   )r@   r   r   ivr.   r.   r/   _parsed_string_to_bounds	  s    z$PeriodIndex._parsed_string_to_bounds)r:   r;   )r:   r   )NrE   )rF   rG   r:   r7   )NrO   )rF   rG   r:   r   )r:   r!   )NNNNFN)r)   rV   rW   rX   rJ   r   r:   r7   )r:   rm   )r:   ro   )r)   r   r:   rX   )rz   r   r{   r|   r:   rm   )rW   rX   )r:   rX   )r:   rG   )NN)r   r
   r:   r
   )r   rG   )r   r   r   r   )(__name__
__module____qualname____doc___typ__annotations__r   	_data_cls!_supports_partial_string_indexingpropertyrA   r   rB   r   rK   _shared_doc_kwargsrP   rR   fgetrT   rU   rl   r-   rv   ry   r   r   r   r   r   r   r   r   r   r   r   r   r   r   __classcell__r.   r.   r   r/   r7   O   sr   
 E


B

$

Fr7   periods
int | Noner:   c                 C  sj   t | ||dkrtd|du rt| tst|tsd}tj| |||i d\}}t||d}t||dS )a  
    Return a fixed frequency PeriodIndex.

    The day (calendar) is the default frequency.

    Parameters
    ----------
    start : str or period-like, default None
        Left bound for generating periods.
    end : str 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)rh   r'   rI   )comcount_not_noner   rd   r
   r   rc   r7   )rO   r   r   r&   rJ   r$   r.   r.   r/   period_range  s   4r   )NNNNN)r   r   r:   r7   )C
__future__r   r   r   typingr   r   numpyre   pandas._libsr   r=   r   pandas._libs.tslibsr   r	   r
   r   r   pandas._typingr   r   r   pandas.util._decoratorsr   r   pandas.util._exceptionsr   pandas.core.dtypes.commonr   r   r   pandas.core.dtypes.dtypesr   pandas.core.dtypes.missingr   pandas.core.arrays.periodr   r   r   r   pandas.core.commoncorecommonr   pandas.core.indexes.baseindexesrs   ibaser    pandas.core.indexes.datetimeliker   pandas.core.indexes.datetimesr   r   pandas.core.indexes.extensionr    pandas.core.indexes.numericr!   dict_index_doc_kwargsupdater   r0   
_field_opsr7   r   r.   r.   r.   r/   <module>   sL    
   =