
    Eg"J                    J   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'c m(Z) d dl*m'c m+c m,Z- d dl*m.Z. d dl/m0Z0 d dl1m2Z2m3Z3 d dl4m5Z5 erd dl6m7Z7 d dl8m9Z9m:Z:m;Z;m<Z<  e=e-j>                  Z>e>?                    ddi           ddiZ@d ZA e5g de"jB        z   e"d           e5dge"           G d de0                                  ZC	 	 	 	 	 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                    |                     d          }|j        dk    rD|                     dd           }t          |          }t          ||          } | j        |fi |S  | |fi |S )Ndataint64freqdtype)popr*   r   r   _simple_new)clsdvaluesr(   r*   s        O/var/www/sysmax/venv/lib/python3.11/site-packages/pandas/core/indexes/period.py_new_PeriodIndexr1   D   s    UU6]]F|wuuVT""D!!V5111sv+++++s6Q    )strftime
start_timeend_timeT)wrapis_leap_yearc            
      &    e Zd ZU dZdZded<   ded<   ded<   eZd	Ze	dHd            Z
edId            Z eej        fdddedJdKd            Z eej                  dLdMd            Ze	 eej        j                  dNd                        Ze	 eej        j                  dNd                        Ze	 eej        j                  dNd                        Z	 	 	 	 	 	 dOdPd$Zeddddddddd%dQd&            Zedd'dQd(            Ze	dRd*            ZdSd,ZdTd.ZdU fd3Ze	dVd4            Ze	dWd5            Z fd6Zd7 Z dXd;Z!dYd>Z" ee#j$                  dZ fd@            Z$d[dCZ% ee#j&                  d\d]dG            Z& xZ'S )^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                    t           j        S N)libindexPeriodEngineselfs    r0   _engine_typezPeriodIndex._engine_type   s    $$r2   r   c                    | j         j        S r?   )r*   _resolution_objrB   s    r0   rF   zPeriodIndex._resolution_obj   s     z))r2   zpandas.arrays.PeriodArray)other
other_nameNEhowstrr!   c                    | j                             ||          }t          |                               || j                  S Nname)r;   asfreqtyper,   rO   rC   r(   rJ   arrs       r0   rP   zPeriodIndex.asfreq   s<     jc**Dzz%%c	%:::r2   startr   c                n    | j                             ||          }t          j        || j                  S rM   )r;   to_timestampr   r,   rO   rR   s       r0   rV   zPeriodIndex.to_timestamp   s1    j%%dC00(49====r2   r   c                B    t          | j        j        | j                  S rM   )r   r;   hourrO   rB   s    r0   rX   zPeriodIndex.hour   s     TZ_495555r2   c                B    t          | j        j        | j                  S rM   )r   r;   minuterO   rB   s    r0   rZ   zPeriodIndex.minute        TZ&TY7777r2   c                B    t          | j        j        | j                  S rM   )r   r;   secondrO   rB   s    r0   r]   zPeriodIndex.second   r[   r2   FDtype | NonecopyboolrO   Hashable | Nonec                Z   h d}d }	|s#t          |t          t          f          r|j        }	t	          |                              |          s>t          t          t	          |          |z
                      }
t          d|
           t          |          r(t          j        dt          t                                 |(t          j        dt          t                                 t          |||           }|2|0|s|                     d             | j        di |d|ij        }d}n|r |t%          d          t%          d	          t'          ||          }|r0t          ||           r |j        |k    r|                    |          }|C|At-          j        |t,          j        
          }t3          |          }t5          ||
          }n$||t%          d          t7          ||          }|r|                                }|                     |||	          S )N>   dayrX   yearmonthrZ   r]   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(   )rO   refs )
isinstancer   r   _referencessetissubsetnextiter	TypeErrorlenwarningswarnFutureWarningr   r   _raise_scalar_data_errorfrom_fieldsr;   
ValueErrorr   r(   rP   npasarrayr'   r   r   r   r_   r,   )r-   r&   ordinalr(   r*   r_   rO   fieldsvalid_field_setrh   arguments              r0   __new__zPeriodIndex.__new__   sv   
 
 
  	$
4%);<< 	$#D6{{##O44 
	DV!>??@@HVHVVWWW[[ 	M3+--	    M +--    "$c22<GO 3,,T222"3?77V77$777=DDD 	: !CDDDBCCC 'ud33D
  )
4-- )$)t2C2C {{4((| 3*WBH===#D))"7%888!g&9 !DEEE $D999 	99;;Dt$T:::r2   )rd   rf   re   rc   rX   rZ   r]   r(   c                   |||||||d}	d |	                                 D             }	t          j        |	|          }
|                     |
          S )N)rd   rf   re   rc   rX   rZ   r]   c                    i | ]
\  }}|||S r?   ri   ).0keyvalues      r0   
<dictcomp>z+PeriodIndex.from_fields.<locals>.<dictcomp>W  s#    SSSeAR#uARARARr2   )r{   r(   )itemsr   _from_fieldsr,   )r-   rd   rf   re   rc   rX   rZ   r]   r(   r{   rS   s              r0   rv   zPeriodIndex.from_fieldsA  sj     
 
 TSv||~~SSS&f4@@@s###r2   rN   c                   t          j        |t           j                  }t          |          }t	          j        ||          }|                     ||          S )Nr)   rN   )rx   ry   r'   r   r   r,   )r-   ordinalsr(   rO   r*   r&   s         r0   from_ordinalszPeriodIndex.from_ordinals[  sP    :hbh777D!!&xu===t$///r2   npt.NDArray[np.object_]c                8    t          j        | t                    S )Nr)   )rx   ry   objectrB   s    r0   r/   zPeriodIndex.valuese  s    z$f----r2   int | npt.NDArray[np.int64]c                   t          |t          t          j        t          t          j        f          r7t          | j        t                    r| j                            |          }|S nit          |t                    r,|j
        | j        j
        k    r|j        S t          | |          t          |          rt          |t                    sJ |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)rj   r   rx   timedelta64r   ndarrayr(   r;    _check_timedeltalike_freq_compatr   basenr   r   int)rC   rG   deltas      r0   _maybe_convert_timedeltaz$PeriodIndex._maybe_convert_timedeltai  s    " eirzJKK 	$)T** 
CCEJJ z** 	zTY^++w'e444 	eS)))))L $D$///r2   r    c                    | j         |k    S )zF
        Can we compare values of the given dtype to our own?
        r)   )rC   r*   s     r0   _is_comparable_dtypez PeriodIndex._is_comparable_dtype  s     zU""r2   wheremasknpt.NDArray[np.bool_]
np.ndarrayc                    t          |t                    rt          |j        | j                  }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)rj   r   r9   _valuesr(   rp   super	asof_locs)rC   r   r   	__class__s      r0   r   zPeriodIndex.asof_locs  sl     e]++ 	VDI>>>EEE;// 	VTUUUww  ---r2   c                    t          |           dk    rdS | j        st          d          | j        }t	          |dd         |dd         z
  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   )rq   is_monotonic_increasingrw   asi8r`   all)rC   r/   s     r0   is_fullzPeriodIndex.is_full  sm     t99>>4+ 	75666fQRRj6#2#;.!388::;;;r2   c                    dS )Nperiodri   rB   s    r0   inferred_typezPeriodIndex.inferred_type  s	     xr2   c                    t                                          ||          }| j        |j        k    r|                     |          }|S r?   )r   _convert_tolerancer*   r   )rC   	tolerancetargetr   s      r0   r   zPeriodIndex._convert_tolerance  sF    
 GG..y&AA	:%%55i@@Ir2   c                L   |}|                      |           t          || j                  r	t          }n8t	          |t
                    r	 |                     |          \  }}n&# t          $ r}t          d| d          |d}~ww xY w| 	                    |          r9	 | 
                    ||          S # t          $ r}t          |          |d}~ww xY w|| j        k    r|                     |          }ntt          |          t	          |t                    r|                     |           n:t	          |t                    r|                     |          }nt          |          	 t!          j        | |          S # t          $ r}t          |          |d}~ww xY 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	   rj   rK   _parse_with_resorw   KeyError_can_partial_date_slice_partial_date_slicerF   _cast_partial_indexing_scalarr
   _disallow_mismatched_indexingr   r   get_loc)rC   r   orig_keyparsedresoerrs         r0   r   zPeriodIndex.get_loc  s   ( ""3''' dj11 	 CCS!! 	 O#44S99 O O ODCDDDEE3NO ++D11 1133D&AAA 1 1 1"3--S01 t+++ 88@@smm#V$$ 	 ..s3333X&& 	 44S99CC 3--	.=s+++ 	. 	. 	.8$$#-	.sH   A% %
B/BB!B7 7
CCC/F 
F#FF#r   r
   Nonec                D    |j         | j        k    rt          |          d S r?   )_dtyper*   r   )rC   r   s     r0   r   z)PeriodIndex._disallow_mismatched_indexing  s%    :##3-- $#r2   labelr   c                z    	 t          || j                  }n"# t          $ r}t          |          |d }~ww xY w|S )Nr   )r
   r(   rw   r   )rC   r   r   r   s       r0   r   z)PeriodIndex._cast_partial_indexing_scalar  sQ    	+E	222FF 	+ 	+ 	+5//s*	+ s    
838sidec                    t          |t                    r|                     |          }t                                          ||          S r?   )rj   r   r   r   _maybe_cast_slice_bound)rC   r   r   r   s      r0   r   z#PeriodIndex._maybe_cast_slice_bound  sB    eX&& 	>66u==Eww..ud;;;r2   r   r   c                    t          j        |j        |j                  }t          ||          }|                    | j        d          |                    | j        d          fS )Nr   rT   )rJ   end)r   getattr_abbrevr
   rP   r(   )rC   r   r   r(   ivs        r0   _parsed_string_to_boundsz$PeriodIndex._parsed_string_to_bounds  s[    '+D,<d>NOOF&&&		$)	11299TYE93R3RSSr2   r   periodsr   c                Z    |%t          dt          |           j         d          | |z   S )Nz%`freq` argument is not supported for z.shift)rp   rQ   __name__)rC   r   r(   s      r0   shiftzPeriodIndex.shift  s=    ST

8KSSS   g~r2   )r<   r=   )r<   r   )NrI   )rJ   rK   r<   r!   )NrT   )rJ   rK   r<   r   )r<   r   )NNNNFN)r*   r^   r_   r`   rO   ra   r<   r!   )r<   r!   )r<   r   )r<   r   )r*   r    r<   r`   )r   r   r   r   r<   r   )r<   r`   )r<   rK   )r   r
   r<   r   )r   r   r<   r
   )r   rK   )r   r   r   r   )r   N)r   r   r<   r!   )(r   
__module____qualname____doc___typ__annotations__r   	_data_cls!_supports_partial_string_indexingpropertyrD   r   rF   r   rP   _shared_doc_kwargsrV   rX   fgetrZ   r]   r~   classmethodrv   r   r/   r   r   r   r   r   r   r   r   r   r   r   r   r   __classcell__)r   s   @r0   r9   r9   P   s        Z Zx DI(,%% % % X% * * * ^* 	S)   	 ; ; ; ; ; 	S	!""> > > > #"> S		6 6 6   X6 S		 !!8 8 8 "! X8 S		 !!8 8 8 "! X8 " $U; U; U; U; U;n  $ $ $ $ $ [$2 37 0 0 0 0 0 [0 . . . X. 0  0  0  0D# # # #. . . . . . 
< 
< 
< X
<    X    <. <. <.|           	S		677< < < < < 87<T T T T
 	S		$%%    &%    r2   r9   r   
int | NonerO   ra   r<   c                F   t          j        | ||          dk    rt          d          |,t          | t                    st          |t                    sd}t          j        | |||          \  }}t          |          }t          ||          }t          ||          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)   rN   )	comcount_not_nonerw   rj   r
   r   _generate_ranger   r9   )rT   r   r   r(   rO   r&   r*   s          r0   period_ranger   #  s    p %g..!33,
 
 	
 |Zv66|z#v?V?V|,UC$GGJD$Et5)))Dt$''''r2   )NNNNN)r   r   rO   ra   r<   r9   )E
__future__r   r   r   typingr   rr   numpyrx   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   r1   
_field_opsr9   r   ri   r2   r0   <module>r      s   " " " " " "        !                * * * * * *              @ ? ? ? ? ?        5 4 4 4 4 4 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0 0 < < < < < <            !                 ( ( ( ( ( ( ( ( ( ( ( ( 7 7 7 7 7 7 B B B B B B        8 7 7 7 7 7 ((((((            D011    .*JK L L L] 	  	  	  ***[-CC	  
 --J J J J J' J J .- J\ 	 C( C( C( C( C( C( C(r2   