a
    Of"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rXd 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ZCd&d!d"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nptZtarget_klasszPeriodIndex or list of Periodsklassr   c                 K  sZ   | d}|jdkrF| dd }t|}t||d}| j|fi |S | |fi |S d S )Ndataint64freqdtype)popr'   r   r   _simple_new)clsdvaluesr%   r'    r-   S/var/www/ai-form-bot/venv/lib/python3.9/site-packages/pandas/core/indexes/period.py_new_PeriodIndexD   s    

r/   )strftime
start_timeZend_timeT)wrapZis_leap_yearc                
      s8  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dZ
eddddZeejfddded]dddddZeejd^dddddZe	eejjdddd Ze	eejjddd!d"Ze	eejjddd#d$Zd_d&d'd(dd)d*d+Zeddddddddd,ddd-d.Zedd/ddd0d1Ze	d2dd3d4Zd5dd6d7Zd8d'd9d:d;Zdd<d=d> fd?d@Ze	d'ddAdBZe	dddCdDZ fdEdFZdGdH Z dIdJdKdLdMZ!dNdIdOdPdQZ"ee#j$ddR fdSdTZ$ddNdUdVdWZ%ee#j&d`dYddZd[d\Z&  Z'S )a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]')
    Zperiodindexr   _datar   r%   r   r'   Tztype[libindex.PeriodEngine])returnc                 C  s   t jS N)libindexZPeriodEngineselfr-   r-   r.   _engine_type   s    zPeriodIndex._engine_typer
   c                 C  s   | j jS r6   )r'   _resolution_objr8   r-   r-   r.   r;      s    zPeriodIndex._resolution_objzpandas.arrays.PeriodArray)otherZ
other_nameNEstrr    )howr5   c                 C  s"   | j ||}t| j|| jdS Nname)r4   asfreqtyper)   rB   r9   r%   r?   arrr-   r-   r.   rC      s    zPeriodIndex.asfreqstartr   c                 C  s   | j ||}tj|| jdS r@   )r4   to_timestampr   r)   rB   rE   r-   r-   r.   rH      s    zPeriodIndex.to_timestampr   c                 C  s   t | jj| jdS r@   )r   r4   hourrB   r8   r-   r-   r.   rI      s    zPeriodIndex.hourc                 C  s   t | jj| jdS r@   )r   r4   minuterB   r8   r-   r-   r.   rJ      s    zPeriodIndex.minutec                 C  s   t | jj| jdS r@   )r   r4   secondrB   r8   r-   r-   r.   rK      s    zPeriodIndex.secondFzDtype | NoneboolHashable | None)r'   copyrB   r5   c                 K  s  h d}d }	|s$t |ttfr$|j}	t||sVttt|| }
td|
 nt	|rpt
jdtt d |d urt
jdtt d t||| }|d u r|d u r|s| d  | jf i |d|ij}d}n|r|d urtdtd	nt||}|r$t || r$|j|kr$||}|d u r^|d ur^tj|tjd
}t|}t||d
}n*|d ur||d ur|tdnt||d}|r| }| j|||	dS )N>   rI   yearrK   monthquarterrJ   dayz-__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%   )rB   refs)
isinstancer   r   Z_referencessetissubsetnextiter	TypeErrorlenwarningswarnFutureWarningr   r   Z_raise_scalar_data_errorfrom_fieldsr4   
ValueErrorr   r%   rC   npasarrayr$   r   r   r   rN   r)   )r*   r#   Zordinalr%   r'   rN   rB   fieldsZvalid_field_setrT   argumentr-   r-   r.   __new__   sT    






zPeriodIndex.__new__)rO   rQ   rP   rR   rI   rJ   rK   r%   c                C  s>   |||||||d}	dd |	  D }	tj|	|d}
| |
S )N)rO   rQ   rP   rR   rI   rJ   rK   c                 S  s   i | ]\}}|d ur||qS r6   r-   ).0keyvaluer-   r-   r.   
<dictcomp>W      z+PeriodIndex.from_fields.<locals>.<dictcomp>)rc   r%   )itemsr   Z_from_fieldsr)   )r*   rO   rQ   rP   rR   rI   rJ   rK   r%   rc   rF   r-   r-   r.   r_   A  s    	zPeriodIndex.from_fieldsrA   c                C  s4   t j|t jd}t|}tj||d}| j||dS )Nr&   rA   )ra   rb   r$   r   r   r)   )r*   Zordinalsr%   rB   r'   r#   r-   r-   r.   from_ordinals[  s    zPeriodIndex.from_ordinalsznpt.NDArray[np.object_]c                 C  s   t j| tdS )Nr&   )ra   rb   objectr8   r-   r-   r.   r,   e  s    zPeriodIndex.valueszint | npt.NDArray[np.int64]c                 C  s   t |ttjttjfr4t | jtrx| j|}|S nDt |t	r^|j
| jj
krR|jS t| |nt|rxt |tstJ |S t| ddS )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)rU   r   ra   Ztimedelta64r   Zndarrayr%   r4   Z _check_timedeltalike_freq_compatr   basenr   r   int)r9   r<   deltar-   r-   r.   _maybe_convert_timedeltai  s    
z$PeriodIndex._maybe_convert_timedeltar   )r'   r5   c                 C  s
   | j |kS )zF
        Can we compare values of the given dtype to our own?
        r&   )r9   r'   r-   r-   r.   _is_comparable_dtype  s    z PeriodIndex._is_comparable_dtypeznpt.NDArray[np.bool_]z
np.ndarray)wheremaskr5   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)rU   r   r3   Z_valuesr%   rZ   super	asof_locs)r9   rt   ru   	__class__r-   r.   rx     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   )r[   Zis_monotonic_increasingr`   Zasi8rL   all)r9   r,   r-   r-   r.   is_full  s    zPeriodIndex.is_fullc                 C  s   dS )Nperiodr-   r8   r-   r-   r.   inferred_type  s    zPeriodIndex.inferred_typec                   s(   t  ||}| j|jkr$| |}|S r6   )rw   _convert_tolerancer'   rr   )r9   Z	tolerancetargetry   r-   r.   r     s    
zPeriodIndex._convert_tolerancec              
   C  sV  |}|  | t|| jr t}nt|trz| |\}}W n6 tyr } ztd| d|W Y d}~n
d}~0 0 | 	|rz| 
||W S  ty } zt||W Y d}~n
d}~0 0 || jkr| |}nt|n6t|tr| | n t|tr
| |}nt|zt| |W S  tyP } zt||W Y d}~n
d}~0 0 dS )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)Z_check_indexing_errorr   r'   r   rU   r>   Z_parse_with_resor`   KeyErrorZ_can_partial_date_sliceZ_partial_date_slicer;   _cast_partial_indexing_scalarr	   _disallow_mismatched_indexingr   r   get_loc)r9   rg   orig_keyparsedresoerrr-   r-   r.   r     s4    

(
 


zPeriodIndex.get_locr	   None)rg   r5   c                 C  s   |j | jkrt|d S r6   )Z_dtyper'   r   )r9   rg   r-   r-   r.   r     s    z)PeriodIndex._disallow_mismatched_indexingr   )labelr5   c              
   C  sF   zt || jd}W n. ty@ } zt||W Y d }~n
d }~0 0 |S )Nrv   )r	   r%   r`   r   )r9   r   r   r   r-   r-   r.   r     s
     z)PeriodIndex._cast_partial_indexing_scalar)sidec                   s"   t |tr| |}t ||S r6   )rU   r   r   rw   _maybe_cast_slice_bound)r9   r   r   ry   r-   r.   r     s    

z#PeriodIndex._maybe_cast_slice_bound)r   r   c                 C  s<   t |j|j}t||d}|j| jdd|j| jddfS )Nrv   rG   )r?   end)r   getZattr_abbrevr	   rC   r%   )r9   r   r   r%   Zivr-   r-   r.   _parsed_string_to_bounds  s    z$PeriodIndex._parsed_string_to_boundsr{   rp   )periodsr5   c                 C  s&   |d urt dt| j d| | S )Nz%`freq` argument is not supported for z.shift)rZ   rD   __name__)r9   r   r%   r-   r-   r.   shift  s
    zPeriodIndex.shift)Nr=   )NrG   )NNNNFN)r{   N)(r   
__module____qualname____doc__Z_typ__annotations__r   Z	_data_clsZ!_supports_partial_string_indexingpropertyr:   r   r;   r   rC   _shared_doc_kwargsrH   rI   fgetrJ   rK   re   classmethodr_   rl   r,   rr   rs   rx   r   r   r   r   r   r   r   r   r   r   __classcell__r-   r-   ry   r.   r3   P   s   
\


      W	"	>r3   z
int | NonerM   )r   rB   r5   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&   rA   )	comZcount_not_noner`   rU   r	   r   Z_generate_ranger   r3   )rG   r   r   r%   rB   r#   r'   r-   r-   r.   period_range#  s    8r   )NNNNN)E
__future__r   r   r   typingr   r\   numpyra   Zpandas._libsr   r7   Zpandas._libs.tslibsr   r   r	   r
   r   Zpandas._libs.tslibs.dtypesr   Zpandas.util._decoratorsr   r   Zpandas.util._exceptionsr   Zpandas.core.dtypes.commonr   Zpandas.core.dtypes.dtypesr   Zpandas.core.dtypes.genericr   Zpandas.core.dtypes.missingr   Zpandas.core.arrays.periodr   r   r   r   Zpandas.core.commoncorecommonr   Zpandas.core.indexes.baseZindexesrn   Zibaser   Z pandas.core.indexes.datetimeliker   Zpandas.core.indexes.datetimesr   r   Zpandas.core.indexes.extensionr   collections.abcr   Zpandas._typingr   r   r    r!   dictZ_index_doc_kwargsupdater   r/   Z
_field_opsr3   r   r-   r-   r-   r.   <module>   sX   

   Q     