
    PiK                       d dl mZ d dlmZmZ d dlmZmZ d dlZd dl	m
Z d dlmZmZmZmZ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 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;  e<e-j=                  Z=e=>                    ddi           ddiZ?d Z@ e5dddge"jA        e"d           e5dge"           ed           G d  d!e0                                              ZB ed          	 	 	 	 	 d(d)d'            ZCdS )*    )annotations)datetime	timedelta)TYPE_CHECKINGSelfN)index)
BaseOffsetDayNaTPeriod
ResolutionTick)OFFSET_TO_PERIOD_FREQSTR)cache_readonlydoc
set_module)
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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        n/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/pandas/core/indexes/period.py_new_PeriodIndexr2   F   s    UU6]]F|wuuVT""D!!V5111sv+++++s6Q    strftime
start_timeend_timeT)wrapis_leap_yearpandasc            
      $    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 )^PeriodIndexa9  
    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.
    freq : str or period object, optional
        One of pandas period strings or corresponding objects.
    dtype : str or PeriodDtype, default None
        A dtype from which to extract a freq.
    copy : bool, default None
        Whether to copy input data, only relevant for array, Series, and Index
        inputs (for other input, e.g. a list, a new array is created anyway).
        Defaults to True for array input and False for Index/Series.
        Set to False to avoid copying array input at your own risk (if you
        know the input data won't be modified elsewhere).
        Set to True to force copying Series/Index input up front.
    name : str, default None
        Name of the resulting PeriodIndex.

    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

    Raises
    ------
    ValueError
        Passing the parameter data as a list without specifying either freq or
        dtype will raise a ValueError: "freq not specified and cannot be inferred"

    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(data=["2000Q1", "2002Q3"], freq="Q")
    >>> 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    r1   _engine_typezPeriodIndex._engine_type   s    $$r3   r   c                    | j         j        S rA   )r+   _resolution_objrD   s    r1   rH   zPeriodIndex._resolution_obj   s     z))r3   zarrays.PeriodArray)other
other_nameNEhowstrr   c                    | j                             ||          }t          |                               || j                  S Nname)r=   asfreqtyper-   rQ   rE   r)   rL   arrs       r1   rR   zPeriodIndex.asfreq   s<     jc**Dzz%%c	%:::r3   startr   c                n    | j                             ||          }t          j        || j                  S rO   )r=   to_timestampr   r-   rQ   rT   s       r1   rX   zPeriodIndex.to_timestamp   s1    j%%dC00(49====r3   r   c                D    t          | j        j        | j        d          S NFrQ   copy)r   r=   hourrQ   rD   s    r1   r]   zPeriodIndex.hour   s     TZ_495AAAAr3   c                D    t          | j        j        | j        d          S rZ   )r   r=   minuterQ   rD   s    r1   r_   zPeriodIndex.minute         TZ&TYUCCCCr3   c                D    t          | j        j        | j        d          S rZ   )r   r=   secondrQ   rD   s    r1   rb   zPeriodIndex.second   r`   r3   Dtype | Noner\   bool | NonerQ   Hashable | Nonec                   d }|s#t          |t          t          f          r|j        }t	          |||           }t          ||          }|                     |||          \  }}|r0t          ||           r |j        |k    r|                    |          }t          ||          }|r|
                                }|                     |||          S )N)r'   r)   )rQ   refs)
isinstancer   r   _referencesr   r   _maybe_copy_array_inputr)   rR   r   r\   r-   )r.   r'   r)   r+   r\   rQ   rg   s          r1   __new__zPeriodIndex.__new__   s      	$
4%);<< 	$#D!$c22"5$// 00tUCC
d
  	%JtS)) 	%di4.?.? ;;t$$D D111 	99;;Dt$T:::r3   )yearquartermonthdayr]   r_   rb   r)   c                   |||||||d}	d |	                                 D             }	t          j        |	|          }
|                     |
          S )a  
        Construct a PeriodIndex from fields (year, month, day, etc.).

        Parameters
        ----------
        year : int, array, or Series, default None
            Year for the PeriodIndex.
        quarter : int, array, or Series, default None
            Quarter for the PeriodIndex.
        month : int, array, or Series, default None
            Month for the PeriodIndex.
        day : int, array, or Series, default None
            Day for the PeriodIndex.
        hour : int, array, or Series, default None
            Hour for the PeriodIndex.
        minute : int, array, or Series, default None
            Minute for the PeriodIndex.
        second : int, array, or Series, default None
            Second for the PeriodIndex.
        freq : str or period object, optional
            One of pandas period strings or corresponding objects.

        Returns
        -------
        PeriodIndex

        See Also
        --------
        PeriodIndex.from_ordinals : Construct a PeriodIndex from ordinals.
        PeriodIndex.to_timestamp : Cast to DatetimeArray/Index.

        Examples
        --------
        >>> idx = pd.PeriodIndex.from_fields(year=[2000, 2002], quarter=[1, 3])
        >>> idx
        PeriodIndex(['2000Q1', '2002Q3'], dtype='period[Q-DEC]')
        )rl   rm   rn   ro   r]   r_   rb   c                    i | ]
\  }}|||S rA    ).0keyvalues      r1   
<dictcomp>z+PeriodIndex.from_fields.<locals>.<dictcomp>=  s#    SSSeAR#uARARARr3   )fieldsr)   )itemsr   _from_fieldsr-   )r.   rl   rm   rn   ro   r]   r_   rb   r)   rw   rU   s              r1   from_fieldszPeriodIndex.from_fields  sk    f 
 
 TSv||~~SSS&f4@@@s###r3   rP   c                   t          j        |t           j                  }t          |          }t	          j        ||          }|                     ||          S )aE  
        Construct a PeriodIndex from ordinals.

        Parameters
        ----------
        ordinals : array-like of int
            The period offsets from the proleptic Gregorian epoch.
        freq : str or period object
            One of pandas period strings or corresponding objects.
        name : str, default None
            Name of the resulting PeriodIndex.

        Returns
        -------
        PeriodIndex

        See Also
        --------
        PeriodIndex.from_fields : Construct a PeriodIndex from fields
            (year, month, day, etc.).
        PeriodIndex.to_timestamp : Cast to DatetimeArray/Index.

        Examples
        --------
        >>> idx = pd.PeriodIndex.from_ordinals([-1, 0, 1], freq="Q")
        >>> idx
        PeriodIndex(['1969Q4', '1970Q1', '1970Q2'], dtype='period[Q-DEC]')
        r*   rP   )npasarrayr(   r   r   r-   )r.   ordinalsr)   rQ   r+   r'   s         r1   from_ordinalszPeriodIndex.from_ordinalsA  sR    < :hbh777D!!&xu===t$///r3   npt.NDArray[np.object_]c                8    t          j        | t                    S )Nr*   )r|   r}   objectrD   s    r1   r0   zPeriodIndex.valuesg  s    z$f----r3   int | npt.NDArray[np.int64]c                   t          |t          t          j        t          t          j        f          r>t          | j        t          t          f          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)rh   r   r|   timedelta64r   ndarrayr)   r
   r=    _check_timedeltalike_freq_compatr	   basenr   r   int)rE   rI   deltas      r1   _maybe_convert_timedeltaz$PeriodIndex._maybe_convert_timedeltak  s    " eirzJKK 	$)dC[11 
CCEJJ z** 	zTY^++w'e444 	eS)))))L $D$///r3   r"   boolc                    | j         |k    S )zF
        Can we compare values of the given dtype to our own?
        r*   )rE   r+   s     r1   _is_comparable_dtypez PeriodIndex._is_comparable_dtype  s     zU""r3   wheremasknpt.NDArray[np.bool_]
np.ndarrayc                    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.
        F)r)   r\   z6asof_locs `where` must be DatetimeIndex or PeriodIndex)rh   r   r;   _valuesr)   	TypeErrorsuper	asof_locs)rE   r   r   	__class__s      r1   r   zPeriodIndex.asof_locs  sn     e]++ 	VDIEJJJEEE;// 	VTUUUww  ---r3   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   )lenis_monotonic_increasing
ValueErrorasi8r   all)rE   r0   s     r1   is_fullzPeriodIndex.is_full  sm     t99>>4+ 	75666fQRRj6#2#;.!388::;;;r3   c                    dS )Nperiodrr   rD   s    r1   inferred_typezPeriodIndex.inferred_type  s	     xr3   c                    t                                          ||          }| j        |j        k    r|                     |          }|S rA   )r   _convert_tolerancer+   r   )rE   	tolerancetargetr   s      r1   r   zPeriodIndex._convert_tolerance  sF    
 GG..y&AA	:%%55i@@Ir3   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   rh   rM   _parse_with_resor   KeyError_can_partial_date_slice_partial_date_slicerH   _cast_partial_indexing_scalarr   _disallow_mismatched_indexingr   r   get_loc)rE   rt   orig_keyparsedresoerrs         r1   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#rt   r   Nonec                D    |j         | j        k    rt          |          d S rA   )_dtyper+   r   )rE   rt   s     r1   r   z)PeriodIndex._disallow_mismatched_indexing  s%    :##3-- $#r3   labelr   c                z    	 t          || j                  }n"# t          $ r}t          |          |d }~ww xY w|S )Nr)   )r   r)   r   r   )rE   r   r   r   s       r1   r   z)PeriodIndex._cast_partial_indexing_scalar  sQ    	+E	222FF 	+ 	+ 	+5//s*	+ s    
838sidec                    t          |t                    r|                     |          }t                                          ||          S rA   )rh   r   r   r   _maybe_cast_slice_bound)rE   r   r   r   s      r1   r   z#PeriodIndex._maybe_cast_slice_bound  sB    eX&& 	>66u==Eww..ud;;;r3   r   r   c                    t          j        |j        |j                  }t          ||          }|                    | j        d          |                    | j        d          fS )Nr   rV   )rL   end)r   getattr_abbrevr   rR   r)   )rE   r   r   r)   ivs        r1   _parsed_string_to_boundsz$PeriodIndex._parsed_string_to_bounds  s[    '+D,<d>NOOF&&&		$)	11299TYE93R3RSSr3   r   periodsr   c                Z    |%t          dt          |           j         d          | |z   S )Nz%`freq` argument is not supported for z.shift)r   rS   __name__)rE   r   r)   s      r1   shiftzPeriodIndex.shift  s=    ST

8KSSS   g~r3   )r>   r?   )r>   r   )NrK   )rL   rM   r>   r   )NrV   )rL   rM   r>   r   )r>   r   NNNNN)r+   rc   r\   rd   rQ   re   r>   r   )r>   r   )r>   r   )r>   r   )r+   r"   r>   r   )r   r   r   r   r>   r   )r>   r   )r>   rM   )rt   r   r>   r   )r   r   r>   r   )r   rM   )r   r   r   r   )r   N)r   r   r>   r   )(r   
__module____qualname____doc___typ__annotations__r   	_data_cls!_supports_partial_string_indexingpropertyrF   r   rH   r   rR   _shared_doc_kwargsrX   r]   fgetr_   rb   rk   classmethodrz   r   r0   r   r   r   r   r   r   r   r   r   r   r   r   r   __classcell__)r   s   @r1   r;   r;   R   s        L L\ DI(,%% % % X% * * * ^* 	S"   	 ; ; ; ; ; 	S	!""> > > > #"> S		B B B   XB S		 !!D D D "! XD S		 !!D D D "! XD "  $!; !; !; !; !;F  <$ <$ <$ <$ <$ [<$| 37  0  0  0  0  0 [ 0J . . . X. 0  0  0  0D# # # #. . . . . . 
< 
< 
< X
<    X    <. <. <.|           	S		677< < < < < 87<T T T T
 	S		$%%    &%    r3   r;   r   
int | NonerQ   re   r>   c                H   t          j        | ||          dk    rt          d          |,t          | t                    st          |t                    sd}t          j        | |||          \  }}t          |          }t          ||          }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
        A PeriodIndex of fixed frequency periods.

    See Also
    --------
    date_range : Returns a fixed frequency DatetimeIndex.
    Period : Represents a period of time.
    PeriodIndex : Immutable ndarray holding ordinal values indicating regular periods
        in time.

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

    To learn more about the frequency strings, please see
    :ref:`this link<timeseries.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*   Fr[   )	comcount_not_noner   rh   r   r   _generate_ranger   r;   )rV   r   r   r)   rQ   r'   r+   s          r1   period_ranger   %  s    H %g..!33,
 
 	
 |Zv66|z#v?V?V|,UC$GGJD$Et5)))Dt$U3333r3   r   )r   r   rQ   re   r>   r;   )D
__future__r   r   r   typingr   r   numpyr|   pandas._libsr   rB   pandas._libs.tslibsr	   r
   r   r   r   r   pandas._libs.tslibs.dtypesr   pandas.util._decoratorsr   r   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indexesr   ibaser    pandas.core.indexes.datetimeliker   pandas.core.indexes.datetimesr   r   pandas.core.indexes.extensionr   collections.abcr    pandas._typingr!   r"   r#   dict_index_doc_kwargsupdater   r2   
_field_opsr;   r   rr   r3   r1   <module>r      s   " " " " " "              
     * * * * * *                @ ? ? ? ? ?          1 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] 	  	  	  zCK,BC	  
 --HI I I I I' I I  .- IX H
	 N4 N4 N4 N4 N4 N4 N4r3   