
    iK                    Z   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-jz                        Z=e=j}                  ddi       ddiZ?d Z@ e5dddge"j                  e"d       e5dge"       ed       G d  d!e0                           ZB ed      	 	 	 	 	 d#	 	 	 	 	 d$d"       ZCy)%    )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                    |j                  d      }|j                  dk(  r=|j                  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        W/app/cer_product_mecsu/.venv/lib/python3.12/site-packages/pandas/core/indexes/period.py_new_PeriodIndexr2   F   sg    UU6]F||wuuVT"D!V51sv+++6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	d&d
       Z
ed'd       Z eej                  fddded(d)d       Z eej                         d*d+d       Ze	 eej"                  j$                        d,d              Ze	 eej&                  j$                        d,d              Ze	 eej(                  j$                        d,d              Z	 	 	 	 	 d-	 	 	 	 	 	 	 d.dZeddddddddd	 d/d       Zeddd/d       Ze	d0d       Zd1dZd2dZd3 fdZe	d4d       Ze	d5d       Z fdZd  Z d6d!Z!d7d"Z" ee#jH                        d8 fd#       Z$d9d$Z% ee#jL                        d:d;d%       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+   Tc                "    t         j                  S N)libindexPeriodEngineselfs    r1   _engine_typezPeriodIndex._engine_type   s    $$$r3   c                .    | j                   j                  S r?   )r+   _resolution_objrB   s    r1   rF   zPeriodIndex._resolution_obj   s     zz)))r3   zarrays.PeriodArray)other
other_nameNc                    | j                   j                  ||      }t        |       j                  || j                        S Nname)r=   asfreqtyper-   rL   rC   r)   howarrs       r1   rM   zPeriodIndex.asfreq   s8     jjc*Dz%%c		%::r3   c                |    | j                   j                  ||      }t        j                  || j                        S rJ   )r=   to_timestampr   r-   rL   rO   s       r1   rS   zPeriodIndex.to_timestamp   s/    jj%%dC0((499==r3   c                Z    t        | j                  j                  | j                  d      S NFrL   copy)r   r=   hourrL   rB   s    r1   rX   zPeriodIndex.hour   s     TZZ__4995AAr3   c                Z    t        | j                  j                  | j                  d      S rU   )r   r=   minuterL   rB   s    r1   rZ   zPeriodIndex.minute   !     TZZ&&TYYUCCr3   c                Z    t        | j                  j                  | j                  d      S rU   )r   r=   secondrL   rB   s    r1   r]   zPeriodIndex.second   r[   r3   c                n   d }|s"t        |t        t        f      r|j                  }t	        |||       }t        ||      }| j                  |||      \  }}|r,t        ||       r |j                  |k7  r|j                  |      }t        ||      }|r|j                         }| j                  |||      S )N)r'   r)   )rL   refs)
isinstancer   r   _referencesr   r   _maybe_copy_array_inputr)   rM   r   rW   r-   )r.   r'   r)   r+   rW   rL   r_   s          r1   __new__zPeriodIndex.__new__   s     
4%);<##D!$c2"5$/ 00tUC
d
 JtS)dii4.? ;;t$D D199;Dt$T::r3   )yearquartermonthdayrX   rZ   r]   r)   c                   |||||||d}	|	j                         D 
ci c]  \  }
}|	|
| }	}
}t        j                  |	|      }| j                  |      S c c}}
w )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]')
        )rd   re   rf   rg   rX   rZ   r]   )fieldsr)   )itemsr   _from_fieldsr-   )r.   rd   re   rf   rg   rX   rZ   r]   r)   ri   keyvaluerQ   s                r1   from_fieldszPeriodIndex.from_fields  sp    f 
 06||~SeAR#u*SS&&f4@s## Ts
   
AArK   c                   t        j                  |t         j                        }t        |      }t	        j
                  ||      }| 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*   rK   )npasarrayr(   r   r   r-   )r.   ordinalsr)   rL   r+   r'   s         r1   from_ordinalszPeriodIndex.from_ordinalsA  sG    < ::hbhh7D!&&xu=t$//r3   c                8    t        j                  | t              S )Nr*   )rp   rq   objectrB   s    r1   r0   zPeriodIndex.valuesg  s    zz$f--r3   c                   t        |t        t        j                  t        t        j
                  f      r=t        | j                  t        t        f      r| j                  j                  |      }|S t        |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)r`   r   rp   timedelta64r   ndarrayr)   r
   r=    _check_timedeltalike_freq_compatr	   basenr   r   int)rC   rG   deltas      r1   _maybe_convert_timedeltaz$PeriodIndex._maybe_convert_timedeltak  s    " eirzzJK$))dC[1

CCEJz*zzTYY^^+ww'e44eS)))L $D$//r3   c                     | j                   |k(  S )zF
        Can we compare values of the given dtype to our own?
        r*   )rC   r+   s     r1   _is_comparable_dtypez PeriodIndex._is_comparable_dtype  s     zzU""r3   c                    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)   rW   z6asof_locs `where` must be DatetimeIndex or PeriodIndex)r`   r   r;   _valuesr)   	TypeErrorsuper	asof_locs)rC   wheremask	__class__s      r1   r   zPeriodIndex.asof_locs  sM     e]+DIIEJEE;/TUUw --r3   c                    t        |       dk(  ry| j                  st        d      | j                  }t	        |dd |dd z
  dk  j                               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boolall)rC   r0   s     r1   is_fullzPeriodIndex.is_full  sZ     t9>++566fQRj6#2;.!388:;;r3   c                     y)Nperiod rB   s    r1   inferred_typezPeriodIndex.inferred_type  s     r3   c                |    t         |   ||      }| j                  |j                  k(  r| j                  |      }|S r?   )r   _convert_tolerancer+   r~   )rC   	tolerancetargetr   s      r1   r   zPeriodIndex._convert_tolerance  s<    
 G.y&A	::%55i@Ir3   c                   |}| j                  |       t        || j                        rt        }nt	        |t
              re	 | j                  |      \  }}| j                  |      r	 | j                  ||      S || j                  k(  r| j                  |      }nZt        |      t	        |t              r| j                  |       n-t	        |t              r| j                  |      }nt        |      	 t!        j"                  | |      S # t        $ r}t        d| d      |d}~ww xY w# t        $ r}t        |      |d}~ww xY w# 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   r`   str_parse_with_resor   KeyError_can_partial_date_slice_partial_date_slicerF   _cast_partial_indexing_scalarr   _disallow_mismatched_indexingr   r   get_loc)rC   rl   orig_keyparsedresoerrs         r1   r   zPeriodIndex.get_loc  s\   ( ""3' djj1CS!O#44S9
 ++D1133D&AA t+++ 88@sm#V$..s3X&44S9C 3-	.==s++9  O!3C5DE3NO   1"3-S01,  	.8$#-	.sH   D (D- 6E
 	D*D%%D*-	E6EE
	E$EE$c                L    |j                   | j                  k7  rt        |      y r?   )_dtyper+   r   )rC   rl   s     r1   r   z)PeriodIndex._disallow_mismatched_indexing  s!    ::#3- $r3   c                p    	 t        || j                        }|S # t        $ r}t        |      |d }~ww xY w)Nr)   )r   r)   r   r   )rC   labelr   r   s       r1   r   z)PeriodIndex._cast_partial_indexing_scalar  s<    	+E		2F   	+5/s*	+s    	505c                f    t        |t              r| j                  |      }t        |   ||      S r?   )r`   r   r   r   _maybe_cast_slice_bound)rC   r   sider   s      r1   r   z#PeriodIndex._maybe_cast_slice_bound  s/    eX&66u=Ew.ud;;r3   c                    t        j                  |j                  |j                        }t        ||      }|j	                  | j
                  d      |j	                  | j
                  d      fS )Nr   start)rP   end)r   getattr_abbrevr   rM   r)   )rC   r   r   r)   ivs        r1   _parsed_string_to_boundsz$PeriodIndex._parsed_string_to_bounds  sY    '++D,<,<d>N>NOF&		$))	1299TYYE93RSSr3   c                T    |"t        dt        |       j                   d      | |z   S )Nz%`freq` argument is not supported for z.shift)r   rN   __name__)rC   periodsr)   s      r1   shiftzPeriodIndex.shift  s8    7T
8K8K7LFS  g~r3   )returnztype[libindex.PeriodEngine])r   r   )NE)rP   r   r   r   )Nr   )rP   r   r   r   )r   r   NNNNN)r+   zDtype | NonerW   zbool | NonerL   Hashable | Noner   r   )r   r   )r   znpt.NDArray[np.object_])r   zint | npt.NDArray[np.int64])r+   r"   r   r   )r   r   r   znpt.NDArray[np.bool_]r   z
np.ndarray)r   r   )r   r   )rl   r   r   None)r   r   r   r   )r   r   )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   rM   _shared_doc_kwargsrS   rX   fgetrZ   r]   rc   classmethodrn   rs   r0   r~   r   r   r   r   r   r   r   r   r   r   r   r   __classcell__)r   s   @r1   r;   r;   R   sn   L\ D
I(,%% % * * 	"  	;; 		!	!"> #> 				B   B 			 	 !D " D 			 	 !D " D "  $!; 	!;
 !; !; 
!;F  <$ 
<$ <$| 37  0  0J . . 0D#. 
< 
<  <.|  			6	67< 8<T
 			$	$% &r3   r;   c                   t        j                  | ||      dk7  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 specifiedDr*   FrV   )	comcount_not_noner   r`   r   r   _generate_ranger   r;   )r   r   r   r)   rL   r'   r+   s          r1   period_ranger   %  s    H %g.!3,
 	
 |Zv6z#v?V,,UC$GJD$Et5)Dt$U33r3   r   )r   z
int | NonerL   r   r   r;   )D
__future__r   r   r   typingr   r   numpyrp   pandas._libsr   r@   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indexesrz   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   r   r3   r1   <module>r      s_   "
  *  @  1 1 0 <  !   ( ( 7 B 8(  001    .*JK L] 	  zCK,B,BC	
 -HI' I  .IX H
	 N4 N4
 N4 N4 N4r3   