
    Pi                       d dl mZ d dlmZ d dlZd dlmZmZmZm	Z	m
Z
mZmZ d dlZd dlZd dlmZmZ d dlmZ d dlmZmZmZmZmZmZmZmZm Z m!Z!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- d dl.m/Z/m0Z0m1Z1m2Z2m3Z3 d dl4m5Z5m6Z6m7Z7 d dl8m9Z9m:Z: d dl;m<Z<m=Z= d dl>m?Z?m@Z@mAZAmBZB d dlCmDZD d dlEmFZG d dlHmIc mJZK er0d dlLmMZMmNZN d dlOmPZPmQZQmRZRmSZSmTZTmUZUmVZVmWZW d dl;mXZX d dlEmYZYmZZZ d dl[m\Z\  e
de          Z]ddiZ^d=d>dZ_ e7d            G d! deGj`        e$ja                              Zbd?d$Zc	 	 d@dAd,ZdedBd-            ZeedCd0            ZedDd2Ze	 d=dEd4ZdFdGd8Zf	 	 	 	 	 	 	 	 dHdId:ZgdJd<ZhdS )K    )annotations)	timedeltaN)TYPE_CHECKINGAnyLiteralSelfTypeVarcastoverload)algoslib)NDArrayBacked)
BaseOffsetDayNaTNaTType	Timedeltaadd_overflowsafeastype_overflowsafedt64arr_to_periodarrget_unit_from_dtypeiNaTparsingperiod	to_offset)	FreqGroupPeriodDtypeBase)isleapyear_arr)Tickdelta_to_tick)DIFFERENT_FREQIncompatibleFrequencyPeriodget_period_field_arrperiod_asfreq_arr)cache_readonlydoc
set_module)ensure_objectpandas_dtype)DatetimeTZDtypePeriodDtype)ABCIndexABCPeriodIndex	ABCSeriesABCTimedeltaArray)isna)datetimelike)CallableSequence)AnyArrayLikeDtypeDtypeObjFillnaOptionsNpDtypeNumpySorterNumpyValueArrayLikenpt)ExtensionDtype)DatetimeArrayTimedeltaArray)ExtensionArrayBaseOffsetT)boundklassPeriodArraynamestr	docstring
str | Nonec                H      fd} |_         ||_        t          |          S )Nc                L    | j         j        }t          | j        |          }|S N)dtype_dtype_coder$   asi8)selfbaseresultrE   s      m/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/pandas/core/arrays/period.pyfz_field_accessor.<locals>.fr   s%    z%%dDIt<<    )__name____doc__property)rE   rG   rS   s   `  rR   _field_accessorrX   q   s8        
 AJAIA;;rT   zpandas.arraysc                      e Zd ZU dZdZdZ ej        e          Z	e
fZd Zded<   dZedd
            Zg Zded<   dgZded<   g dZded<   g dZded<   eez   ez   Zded<   g dZded<   ded<   dddZedd#            Zeddd$dd%            Zedd&dd(            Zeddd)            Zed*             Zedd-            Zdd1Zdd4Z dd7Z!e"dd8            Z#edd:            Z$edd;            Z%	 ddd?Z&dd@Z' e(dAdB          Z) e(dCdD          Z* e(dEdF          Z+ e(dGdH          Z, e(dIdJ          Z- e(dKdL          Z. e(dMdN          Z/e/Z0 e(dOdP          Z1e1Z2e2Z3 e(dQdR          xZ4Z5 e(dSdT          Z6 e(dUdV          Z7 e(dWdX          Z8e8Z9eddZ            Z:ddd^Z;dd_Z< e=di e>d`d`dadddc            Z?dddfZ@dgddhddlZAdd fdnZB	 	 dddvZCdddmdwdd~ZDddZEddZF fdZGddZHd ZIdmddd fdZJ xZKS )rD   a^  
    Pandas ExtensionArray for storing Period data.

    Users should use :func:`~pandas.array` to create new instances.

    Parameters
    ----------
    values : Union[PeriodArray, Series[period], ndarray[int], PeriodIndex]
        The data to store. These should be arrays that can be directly
        converted to ordinals without inference or copy (PeriodArray,
        ndarray[int64]), or a box around such an array (Series[period],
        PeriodIndex).
    dtype : PeriodDtype, optional
        A PeriodDtype instance from which to extract a `freq`. If both
        `freq` and `dtype` are specified, then the frequencies must match.
    copy : bool, default False
        Whether to copy the ordinals before storing.

    Attributes
    ----------
    None

    Methods
    -------
    None

    See Also
    --------
    Period: Represents a period of time.
    PeriodIndex : Immutable Index for period data.
    period_range: Create a fixed-frequency PeriodArray.
    array: Construct a pandas array.

    Notes
    -----
    There are two components to a PeriodArray

    - ordinals : integer ndarray
    - freq : pd.tseries.offsets.Offset

    The values are physically stored as a 1-D ndarray of integers. These are
    called "ordinals" and represent some kind of offset from a base.

    The `freq` indicates the span covered by each element of the array.
    All elements in the PeriodArray have the same `freq`.

    Examples
    --------
    >>> pd.arrays.PeriodArray(pd.PeriodIndex(["2023-01-01", "2023-01-02"], freq="D"))
    <PeriodArray>
    ['2023-01-01', '2023-01-02']
    Length: 2, dtype: period[D]
    i  periodarrayc                ,    t          | t                    S rK   )
isinstancer,   )xs    rR   <lambda>zPeriodArray.<lambda>   s    	;B B rT   zCallable[[DtypeObj], bool]_is_recognized_dtype)r   returntype[Period]c                    t           S rK   )r#   rO   s    rR   _scalar_typezPeriodArray._scalar_type   s    rT   z	list[str]
_other_opsis_leap_year	_bool_ops)
start_timeend_timefreq_object_ops)yearmonthdayhourminutesecond
weekofyearweekdayweek	dayofweekday_of_week	dayofyearday_of_yearquarterqyeardays_in_monthdaysinmonth
_field_ops_datetimelike_ops)strftimeto_timestampasfreq_datetimelike_methodsr,   _dtypeNFrL   Dtype | NonecopyboolNonec                   |7t          |          }t          |t                    st          d| d          t          |t                    r4|j        }t          |t          |                     st          d          nt          |t                    r|j        }t          |t          |                     r0| ||j	        k    rt          ||j                  |j        |j	        }}|st          j        |d          }nt          j        |d|          }|t          d          t!          t          |          }t#          j        | ||           d S )NzInvalid dtype z for PeriodArrayzIncorrect dtypeint64rL   rL   r   z-dtype is not specified and cannot be inferred)r*   r\   r,   
ValueErrorr/   _valuestype	TypeErrorr.   rL   raise_on_incompatiblerj   _ndarraynpasarrayarrayr
   r   __init__)rO   valuesrL   r   s       rR   r   zPeriodArray.__init__   s^    ''Ee[11 K !I%!I!I!IJJJfi(( 	$^Ffd4jj11 3 12223 // 	$^Ffd4jj)) 	: Ufl%:%:+FEJ???"OV\EF 	@Zg666FFXfG$???F=LMMM[%((tVU33333rT   r   npt.NDArray[np.int64]r   c                ~    d}t          |t          j                  r|j        dk    s
J |             | ||          S )Nz Should be numpy array of type i8i8r   )r\   r   ndarrayrL   )clsr   rL   assertion_msgs       rR   _simple_newzPeriodArray._simple_new   sJ     ;&"*--U&,$2F2F2F2F2FFs6''''rT   r   c                  |t          |          }|rt          |t                    r|j        }nd }t          ||           r-t	          |j        |           |r|                                }|S t          j        |t                    }|pt          j        |          }t          j        ||          }t          |          } | ||          S )Nr   )r*   r\   r,   rj   validate_dtype_freqrL   r   r   r   object	libperiodextract_freqextract_ordinals)r   scalarsrL   r   rj   periodsordinalss          rR   _from_sequencezPeriodArray._from_sequence  s      ''E 	Z{33 	:DDDgs## 	t444 )!,,..N*WF3336y-g66-gt<<D!!s85))))rT   r   r=   c               2    |                      |||          S )Nr   )r   )r   stringsrL   r   s       rR   _from_sequence_of_stringsz%PeriodArray._from_sequence_of_strings'  s     !!'T!BBBrT   c                    t          |t                    rt          |          j        }t	          |||          \  }}t          |          } | ||          S )a  
        Construct a PeriodArray from a datetime64 array

        Parameters
        ----------
        data : ndarray[datetime64[ns], datetime64[ns, tz]]
        freq : str or Tick
        tz : tzinfo, optional

        Returns
        -------
        PeriodArray[freq]
        r   )r\   r   r,   _freqstrr   )r   datarj   tzrL   s        rR   _from_datetime64zPeriodArray._from_datetime64-  s]     dJ'' 	.t$$-D)$b99
dD!!s4u%%%%rT   c                    t          j        |          }|t          j        |          }||t	          ||||          \  }}nt          d          ||fS )Nz/Not enough parameters to construct Period range)dtlvalidate_periodsr#   _maybe_convert_freq_get_ordinal_ranger   )r   startendr   rj   subarrs         rR   _generate_rangezPeriodArray._generate_rangeB  sd    &w//-d33D-eS'4HHLFDDNOOOt|rT   fieldsdictc               p    t          dd|i|\  }}t          |          }|                     ||          S )Nrj   r    )_range_from_fieldsr,   r   )r   r   rj   r   rL   s        rR   _from_fieldszPeriodArray._from_fieldsP  sA    )>>t>v>>D!!vU333rT   valuePeriod | NaTTypenp.int64c                    |t           u rt          j        |j                  S t	          || j                  r.|                     |           t          j        |j                  S t          d| d          )Nz!'value' should be a Period. Got 'z
' instead.)	r   r   r   _valuer\   rd   _check_compatible_withordinalr   rO   r   s     rR   _unbox_scalarzPeriodArray._unbox_scalar\  su     C<<8EL)))t011 	T''...8EM***RRRRSSSrT   rF   r#   c                .    t          || j                  S )N)rj   )r#   rj   r   s     rR   _scalar_from_stringzPeriodArray._scalar_from_stringi  s    e$),,,,rT   otherPeriod | NaTType | PeriodArrayc                P    |t           u rd S |                     |j                   d S rK   )r   _require_matching_freqrj   rO   r   s     rR   r   z"PeriodArray._check_compatible_witho  s.    C<<F 	##EJ/////rT   c                    | j         S rK   )r   rc   s    rR   rL   zPeriodArray.dtypey  s
    {rT   r   c                    | j         j        S )zC
        Return the frequency object for this PeriodArray.
        rL   rj   rc   s    rR   rj   zPeriodArray.freq~  s    
 zrT   c                4    t          | j                  j        S rK   )r,   rj   r   rc   s    rR   freqstrzPeriodArray.freqstr  s    49%%..rT   NpDtype | Nonebool | None
np.ndarrayc                l   |dk    ra|sDt          j        | j        |          }| j        r |                                }d|j        _        |S t          j        | j        |          S |du rt          d          |t          k    r| j
         S t          j        t          |           t                    S )Nr   r   Fz:Unable to avoid copy while creating an array as requested.)r   r   rN   	_readonlyviewflags	writeabler   r   r   _isnanlistr   )rO   rL   r   rQ   s       rR   	__array__zPeriodArray.__array__  s     D==  8DIU;;;> 3#[[]]F-2FL*x	77775==L   D==K< xT

&1111rT   c                   ddl }ddlm} ||j                            |          r/|                    | j        |                                 |          S t          ||          r1| j	        |j
        k    r t          d| j	         d|j
         d          nt          d| d	           || j	                  }|                    | j        |                                 d
          }|j                            ||          S )z6
        Convert myself into a pyarrow Array.
        r   N)ArrowPeriodType)maskr   zENot supported to convert PeriodArray to array with different 'freq' (z vs )z)Not supported to convert PeriodArray to 'z' typer   )pyarrow(pandas.core.arrays.arrow.extension_typesr   types
is_integerr   r   r1   r\   r   rj   r   r@   from_storage)rO   r   r   r   period_typestorage_arrays         rR   __arrow_array__zPeriodArray.__arrow_array__  s4    	LLLLLL}''-- }}T]4}PPPD/22 
<49,,#B#'<B B59YB B B   -  LLLL   &odl33dm$))++GTT%22;NNNrT   rl   aN  
        The year of the period.

        See Also
        --------
        PeriodIndex.day_of_year : The ordinal day of the year.
        PeriodIndex.dayofyear : The ordinal day of the year.
        PeriodIndex.is_leap_year : Logical indicating if the date belongs to a
            leap year.
        PeriodIndex.weekofyear : The week ordinal of the year.
        PeriodIndex.year : The year of the period.

        Examples
        --------
        >>> idx = pd.PeriodIndex(["2023", "2024", "2025"], freq="Y")
        >>> idx.year
        Index([2023, 2024, 2025], dtype='int64')
        rm   a  
        The month as January=1, December=12.

        See Also
        --------
        PeriodIndex.days_in_month : The number of days in the month.
        PeriodIndex.daysinmonth : The number of days in the month.

        Examples
        --------
        >>> idx = pd.PeriodIndex(["2023-01", "2023-02", "2023-03"], freq="M")
        >>> idx.month
        Index([1, 2, 3], dtype='int64')
        rn   a  
        The days of the period.

        See Also
        --------
        PeriodIndex.day_of_week : The day of the week with Monday=0, Sunday=6.
        PeriodIndex.day_of_year : The ordinal day of the year.
        PeriodIndex.dayofweek : The day of the week with Monday=0, Sunday=6.
        PeriodIndex.dayofyear : The ordinal day of the year.
        PeriodIndex.days_in_month : The number of days in the month.
        PeriodIndex.daysinmonth : The number of days in the month.
        PeriodIndex.weekday : The day of the week with Monday=0, Sunday=6.

        Examples
        --------
        >>> idx = pd.PeriodIndex(['2020-01-31', '2020-02-28'], freq='D')
        >>> idx.day
        Index([31, 28], dtype='int64')
        ro   a  
        The hour of the period.

        See Also
        --------
        PeriodIndex.minute : The minute of the period.
        PeriodIndex.second : The second of the period.
        PeriodIndex.to_timestamp : Cast to DatetimeArray/Index.

        Examples
        --------
        >>> idx = pd.PeriodIndex(["2023-01-01 10:00", "2023-01-01 11:00"], freq='h')
        >>> idx.hour
        Index([10, 11], dtype='int64')
        rp   a  
        The minute of the period.

        See Also
        --------
        PeriodIndex.hour : The hour of the period.
        PeriodIndex.second : The second of the period.
        PeriodIndex.to_timestamp : Cast to DatetimeArray/Index.

        Examples
        --------
        >>> idx = pd.PeriodIndex(["2023-01-01 10:30:00",
        ...                       "2023-01-01 11:50:00"], freq='min')
        >>> idx.minute
        Index([30, 50], dtype='int64')
        rq   a  
        The second of the period.

        See Also
        --------
        PeriodIndex.hour : The hour of the period.
        PeriodIndex.minute : The minute of the period.
        PeriodIndex.to_timestamp : Cast to DatetimeArray/Index.

        Examples
        --------
        >>> idx = pd.PeriodIndex(["2023-01-01 10:00:30",
        ...                       "2023-01-01 10:00:31"], freq='s')
        >>> idx.second
        Index([30, 31], dtype='int64')
        rt   av  
        The week ordinal of the year.

        See Also
        --------
        PeriodIndex.day_of_week : The day of the week with Monday=0, Sunday=6.
        PeriodIndex.dayofweek : The day of the week with Monday=0, Sunday=6.
        PeriodIndex.week : The week ordinal of the year.
        PeriodIndex.weekday : The day of the week with Monday=0, Sunday=6.
        PeriodIndex.year : The year of the period.

        Examples
        --------
        >>> idx = pd.PeriodIndex(["2023-01", "2023-02", "2023-03"], freq="M")
        >>> idx.week  # It can be written `weekofyear`
        Index([5, 9, 13], dtype='int64')
        rv   a(  
        The day of the week with Monday=0, Sunday=6.

        See Also
        --------
        PeriodIndex.day : The days of the period.
        PeriodIndex.day_of_week : The day of the week with Monday=0, Sunday=6.
        PeriodIndex.day_of_year : The ordinal day of the year.
        PeriodIndex.dayofweek : The day of the week with Monday=0, Sunday=6.
        PeriodIndex.dayofyear : The ordinal day of the year.
        PeriodIndex.week : The week ordinal of the year.
        PeriodIndex.weekday : The day of the week with Monday=0, Sunday=6.
        PeriodIndex.weekofyear : The week ordinal of the year.

        Examples
        --------
        >>> idx = pd.PeriodIndex(["2023-01-01", "2023-01-02", "2023-01-03"], freq="D")
        >>> idx.weekday
        Index([6, 0, 1], dtype='int64')
        rx   a  
        The ordinal day of the year.

        See Also
        --------
        PeriodIndex.day : The days of the period.
        PeriodIndex.day_of_week : The day of the week with Monday=0, Sunday=6.
        PeriodIndex.day_of_year : The ordinal day of the year.
        PeriodIndex.dayofweek : The day of the week with Monday=0, Sunday=6.
        PeriodIndex.dayofyear : The ordinal day of the year.
        PeriodIndex.weekday : The day of the week with Monday=0, Sunday=6.
        PeriodIndex.weekofyear : The week ordinal of the year.
        PeriodIndex.year : The year of the period.

        Examples
        --------
        >>> idx = pd.PeriodIndex(["2023-01-10", "2023-02-01", "2023-03-01"], freq="D")
        >>> idx.dayofyear
        Index([10, 32, 60], dtype='int64')

        >>> idx = pd.PeriodIndex(["2023", "2024", "2025"], freq="Y")
        >>> idx
        PeriodIndex(['2023', '2024', '2025'], dtype='period[Y-DEC]')
        >>> idx.dayofyear
        Index([365, 366, 365], dtype='int64')
        ry   ah  
        The quarter of the date.

        See Also
        --------
        PeriodIndex.qyear : Fiscal year the Period lies in according to its
            starting-quarter.

        Examples
        --------
        >>> idx = pd.PeriodIndex(["2023-01", "2023-02", "2023-03"], freq="M")
        >>> idx.quarter
        Index([1, 1, 1], dtype='int64')
        rz   a  
        Fiscal year the Period lies in according to its starting-quarter.

        The `year` and the `qyear` of the period will be the same if the fiscal
        and calendar years are the same. When they are not, the fiscal year
        can be different from the calendar year of the period.

        Returns
        -------
        int
            The fiscal year of the period.

        See Also
        --------
        PeriodIndex.quarter : The quarter of the date.
        PeriodIndex.year : The year of the period.

        Examples
        --------
        If the natural and fiscal year are the same, `qyear` and `year` will
        be the same.

        >>> per = pd.Period('2018Q1', freq='Q')
        >>> per.qyear
        2018
        >>> per.year
        2018

        If the fiscal year starts in April (`Q-MAR`), the first quarter of
        2018 will start in April 2017. `year` will then be 2017, but `qyear`
        will be the fiscal year, 2018.

        >>> per = pd.Period('2018Q1', freq='Q-MAR')
        >>> per.start_time
        Timestamp('2017-04-01 00:00:00')
        >>> per.qyear
        2018
        >>> per.year
        2017
        r{   a  
        The number of days in the month.

        See Also
        --------
        PeriodIndex.day : The days of the period.
        PeriodIndex.days_in_month : The number of days in the month.
        PeriodIndex.daysinmonth : The number of days in the month.
        PeriodIndex.month : The month as January=1, December=12.

        Examples
        --------
        For Series:

        >>> period = pd.period_range('2020-1-1 00:00', '2020-3-1 00:00', freq='M')
        >>> s = pd.Series(period)
        >>> s
        0   2020-01
        1   2020-02
        2   2020-03
        dtype: period[M]
        >>> s.dt.days_in_month
        0    31
        1    29
        2    31
        dtype: int64

        For PeriodIndex:

        >>> idx = pd.PeriodIndex(["2023-01", "2023-02", "2023-03"], freq="M")
        >>> idx.days_in_month   # It can be also entered as `daysinmonth`
        Index([31, 28, 31], dtype='int64')
        npt.NDArray[np.bool_]c                N    t          t          j        | j                            S )a  
        Logical indicating if the date belongs to a leap year.

        See Also
        --------
        PeriodIndex.qyear : Fiscal year the Period lies in according to its
            starting-quarter.
        PeriodIndex.year : The year of the period.

        Examples
        --------
        >>> idx = pd.PeriodIndex(["2023", "2024", "2025"], freq="Y")
        >>> idx.is_leap_year
        array([False,  True, False])
        )r   r   r   rl   rc   s    rR   rf   zPeriodArray.is_leap_year  s    " bj33444rT   r   howr>   c                   ddl m} t          j        |          }| j        j        dk    s|dk    rd}nd}|dk    }|r|dk    s| j        dk    r<t          dd	          t          d|	          z
  }|                     d
          |z   S t          d|	          }| | j        z                       d
          |z
  S |3| j        	                                }t          |d          }|j        }|}	nt          j        |          }|j        }	|                     ||          }
t          j        |
j        |	          } |j        ||j                  }|j        |k    sJ | j        j        dk    rjt-          j        | j                  }t1          |          dk    r<|d         }|| j        j        k    r| j        |_        n|dk    r| j        j        |_        |S |                    d          }|pt9          |          }t;          |j        t<                    rGt;          |t<                    s2t          |          t          |j        j                  k    r||_        |S )a  
        Cast to DatetimeArray/Index.

        If possible, gives microsecond-unit DatetimeArray/Index. Otherwise
        gives nanosecond unit.

        Parameters
        ----------
        freq : str or DateOffset, optional
            Target frequency. The default is 'D' for week or longer,
            's' otherwise.
        how : {'s', 'e', 'start', 'end'}
            Whether to use the start or end of the time period being converted.

        Returns
        -------
        DatetimeArray/Index
            Timestamp representation of given Period-like object.

        See Also
        --------
        PeriodIndex.day : The days of the period.
        PeriodIndex.from_fields : Construct a PeriodIndex from fields
            (year, month, day, etc.).
        PeriodIndex.from_ordinals : Construct a PeriodIndex from ordinals.
        PeriodIndex.hour : The hour of the period.
        PeriodIndex.minute : The minute of the period.
        PeriodIndex.month : The month as January=1, December=12.
        PeriodIndex.second : The second of the period.
        PeriodIndex.year : The year of the period.

        Examples
        --------
        >>> idx = pd.PeriodIndex(["2023-01", "2023-02", "2023-03"], freq="M")
        >>> idx.to_timestamp()
        DatetimeIndex(['2023-01-01', '2023-02-01', '2023-03-01'],
        dtype='datetime64[us]', freq='MS')

        The frequency will not be inferred if the index contains less than
        three elements, or if the values of index are not strictly monotonic:

        >>> idx = pd.PeriodIndex(["2023-01", "2023-02"], freq="M")
        >>> idx.to_timestamp()
        DatetimeIndex(['2023-01-01', '2023-02-01'], dtype='datetime64[us]', freq=None)

        >>> idx = pd.PeriodIndex(
        ...     ["2023-01", "2023-02", "2023-02", "2023-03"], freq="2M"
        ... )
        >>> idx.to_timestamp()
        DatetimeIndex(['2023-01-01', '2023-02-01', '2023-02-01', '2023-03-01'],
        dtype='datetime64[us]', freq=None)
        r   )r>   nsusEB   D)unitr   )r   Nr   inferdays) pandas.core.arraysr>   r   validate_end_aliasrj   rP   r   r   r   _get_to_timestamp_baser   r   r#   r   _period_dtype_coder   periodarr_to_dt64arrrN   r   rL   r   rE   libalgosunique_deltaslen_n_freq
_with_freqr   r\   r   n)rO   rj   r   r>   r   r   adjust	freq_coderL   rP   new_parrnew_datadtadiffsdiffs                  rR   r   zPeriodArray.to_timestamp  sl   j 	544444*3//9>T!!TT\\DDDSj 	Ms{{di3.."13///)AD2I2I2II((W(55>>"14000ty(6676CCfLL<::<<I#Iq11E>DDD-d33D*D;;t;--1(-FF*m*88>JJJx49>S   *4955E5zzQQx4:=(( $	CIIQYY $	CIJ..))C sx--%&tS11% "$9#(*+E+E+EEE $CIJrT   c                8    t          j        || j                  S )N)r   rj   )r#   _from_ordinalrj   )rO   r]   s     rR   	_box_funczPeriodArray._box_funcg  s    #ADI>>>>rT   PeriodIndex)r   
other_namer   c                   t          j        |          }t          |t                    r$t	          |d          rt          |          j        }t          j        |          }| j	        j
        }|j        }| j        }|dk    }|r|| j        j        z   dz
  }n|}t          ||||          }| j        rt"          || j        <   t          |          }	 t'          |           ||	          S )a  
        Convert the {klass} to the specified frequency `freq`.

        Equivalent to applying :meth:`pandas.Period.asfreq` with the given arguments
        to each :class:`~pandas.Period` in this {klass}.

        Parameters
        ----------
        freq : str
            A frequency.
        how : str {{'E', 'S'}}, default 'E'
            Whether the elements should be aligned to the end
            or start within pa period.

            * 'E', 'END', or 'FINISH' for end,
            * 'S', 'START', or 'BEGIN' for start.

            January 31st ('END') vs. January 1st ('START') for example.

        Returns
        -------
        {klass}
            The transformed {klass} with the new frequency.

        See Also
        --------
        {other}.asfreq: Convert each Period in a {other_name} to the given frequency.
        Period.asfreq : Convert a :class:`~pandas.Period` object to the given frequency.

        Examples
        --------
        >>> pidx = pd.period_range("2010-01-01", "2015-01-01", freq="Y")
        >>> pidx
        PeriodIndex(['2010', '2011', '2012', '2013', '2014', '2015'],
        dtype='period[Y-DEC]')

        >>> pidx.asfreq("M")
        PeriodIndex(['2010-12', '2011-12', '2012-12', '2013-12', '2014-12',
        '2015-12'], dtype='period[M]')

        >>> pidx.asfreq("M", how="S")
        PeriodIndex(['2010-01', '2011-01', '2012-01', '2013-01', '2014-01',
        '2015-01'], dtype='period[M]')
        r   r   r   r   )r   r   r\   r   hasattrr,   r   r#   r   r   rM   r   rN   rL   r  r%   _hasnar   r   r   )
rO   rj   r   base1base2rN   r   r   r	  rL   s
             rR   r   zPeriodArray.asfreqj  s    \ *3//dJ'' 	.GD:N,O,O 	.t$$-D)$//''ySj 	TZ]*Q.GGG$WeUC@@; 	)$(HT[!D!!tDzz(%0000rT   boxedCallable[[object], str]c                "    |rt           S dj        S )Nz'{}')rF   format)rO   r  s     rR   
_formatterzPeriodArray._formatter  s     	J}rT   r   )na_repdate_formatr  str | floatnpt.NDArray[np.object_]c               N    t          j        | j        | j        j        ||          S )z3
        actually format my specific types
        )r   period_array_strftimerN   rL   rM   )rO   r  r  kwargss       rR   _format_native_typesz PeriodArray._format_native_types  s)     .Itz-v{
 
 	
rT   Tc                   t          |          }|| j        k    r|s| S |                                 S t          |t                    r|                     |j                  S t          j        |d          st          |t                    r_t          |dd           }t          j        |          }|                                                     |                              |          S t!                                          ||          S )NMr   r   )r*   r   r   r\   r,   r   rj   r   is_np_dtyper+   getattrr   dtype_to_unitr   tz_localizeas_unitsuperastype)rO   rL   r   r   r   	__class__s        rR   r,  zPeriodArray.astype  s     U##DK #yy{{"e[)) 	+;;uz***?5#&& 	E*UO*L*L 	Ed++B$U++D $$&&22266>>tDDDww~~e$~///rT   left$NumpyValueArrayLike | ExtensionArraysideLiteral['left', 'right']sorterNumpySorter | Nonenpt.NDArray[np.intp] | np.intpc                    |                      |                              d          }| j                            d          }|                    |||          S )NM8[ns])r0  r2  )_validate_setitem_valuer   r   searchsorted)rO   r   r0  r2  npvaluem8arrs         rR   r8  zPeriodArray.searchsorted  sW     ..u55::8DD ""8,,!!'V!DDDrT   )limit
limit_arear   methodr8   r;  
int | Noner<  #Literal['inside', 'outside'] | Nonec                   |                      d          }|                    ||||          }|r(t          d|                     | j                            S | S )Nr6  )r=  r;  r<  r   r   )r   _pad_or_backfillr
   rL   )rO   r=  r;  r<  r   r
  rQ   s          rR   rA  zPeriodArray._pad_or_backfill  se     ii!!%%:D & 
 
  	DJ 7 7888KrT   np.ndarray | intopCallable[[Any, Any], Any]c                    |t           j        t           j        fv sJ |t           j        u r| }t          | j        t          j        |d                    } t          |           || j                  S )z
        Add or subtract array of integers.

        Parameters
        ----------
        other : np.ndarray[int64] or int
        op : {operator.add, operator.sub}

        Returns
        -------
        result : PeriodArray
        r   r   )	operatoraddsubr   rN   r   r   r   rL   )rO   r   rC  
res_valuess       rR   _addsub_int_array_or_scalarz'PeriodArray._addsub_int_array_or_scalar  so     hlHL11111FE%diE1N1N1NOO
tDzz*DJ7777rT   c                   t          |t                    rJ t          |t                    r| t          j        |j        d          z   S |                     |d           |                     |j        t          j	                  S )Nr   T)rP   )
r\   r   r   r   timedelta64r  r   rJ  rF  rG  r   s     rR   _add_offsetzPeriodArray._add_offset  sv    eT*****eS!! 	7".#6666##E#555//FFFrT   c                   t          | j        t          t          f          st	          | |          t          |          r!t                                          |          S t          |t                    r-t          j	        t          |j                  j                  }n&t          j	        t          |          j                  }|                     |          S )z
        Parameters
        ----------
        other : timedelta, Tick, np.timedelta64

        Returns
        -------
        PeriodArray
        r   )r\   rj   r   r   r   r1   r+  _add_timedeltalike_scalarr   r   r   r  asm8_add_timedelta_arraylike)rO   r   tdr-  s      rR   rO  z%PeriodArray._add_timedeltalike_scalar  s     $)dC[11 	5'e444;; 	<7744U;;;eS!! 	3I57333899BBIe,,122B,,R000rT   ,TimedeltaArray | npt.NDArray[np.timedelta64]c                   | j                                         st          d| j                    t          j         d| j         j         d          }	 t          t          j        |          |dd          }n"# t          $ r}t          d          |d}~ww xY wt          | j
        t          j        |                    d                              } t          |           || j         	          S )
z
        Parameters
        ----------
        other : TimedeltaArray or ndarray[timedelta64]

        Returns
        -------
        PeriodArray
        z2Cannot add or subtract timedelta64[ns] dtype from m8[]FrL   r   round_okznCannot add/subtract timedelta-like from PeriodArray that is not an integer multiple of the PeriodArray's freq.Nr   r   )rL   _is_tick_liker   r   
_td64_unitr   r   r   r"   r   rN   r   r   )rO   r   rL   deltaerrrI  s         rR   rQ  z$PeriodArray._add_timedelta_arraylike4  s    z'')) 	QTZQQ   7tz477788
	'
5!!UU  EE  	 	 	 (E  	 &diEJJt<L<L1M1MNN
tDzz*DJ7777s   %A: :
BBBc                   | j                                         sJ t          j         d| j         j         d          }t	          |t
          t          j        t          f          r't          j        t          |          j
                  }nt          j        |          }	 t          ||dd          }n## t          $ r}t          | |          |d}~ww xY w|                    d          }t          j        |          S )a<  
        Arithmetic operations with timedelta-like scalars or array `other`
        are only valid if `other` is an integer multiple of `self.freq`.
        If the operation is valid, find that integer multiple.  Otherwise,
        raise because the operation is invalid.

        Parameters
        ----------
        other : timedelta, np.timedelta64, Tick,
                ndarray[timedelta64], TimedeltaArray, TimedeltaIndex

        Returns
        -------
        multiple : int or ndarray[int64]

        Raises
        ------
        IncompatibleFrequency
        rU  rV  FrW  Nr   )rL   rY  r   rZ  r\   r   rL  r   r   r   rP  r   r   r   r   r   item_from_zerodim)rO   r   rL   rR  r[  r\  s         rR    _check_timedeltalike_freq_compatz,PeriodArray._check_timedeltalike_freq_compatY  s    ( z'')))))7tz477788ei>?? 	#Ie,,122BBE""B	>'%eeTTTEE 	> 	> 	>'e44#=	> 

4  $U+++s   !B5 5
C?CCskipnakeepdimsrE   ra  rb  c                    t                      j        |f||d|}|r6t          |t          j                  r|                     || j                  S |S )Nr`  r   )r+  _reducer\   r   r   r   rL   )rO   rE   ra  rb  r"  rQ   r-  s         rR   rd  zPeriodArray._reduce  sf     !RfxRR6RR 	A
62:66 	A&&vTZ&@@@rT   )r`   ra   NF)rL   r   r   r   r`   r   )r   r   rL   r,   r`   r   )rL   r   r   r   r`   r   )rL   r=   r   r   r`   r   rK   )r`   r   )r   r   r`   r   )r   r   r`   r   )r   rF   r`   r#   )r   r   r`   r   )r`   r,   )r`   r   )r`   rF   )NN)rL   r   r   r   r`   r   )r`   r   )Nr   )r   rF   r`   r>   )r`   r   r   )Nr   )r   rF   r`   r   )F)r  r   r`   r  )r  r  r`   r  )T)r   r   )r.  N)r   r/  r0  r1  r2  r3  r`   r4  )
r=  r8   r;  r>  r<  r?  r   r   r`   r   )r   rB  rC  rD  r`   r   )r   r   )r   rS  r`   r   )rE   rF   ra  r   rb  r   )LrU   
__module____qualname__rV   __array_priority___typr   r   r   _internal_fill_valuer#   _recognized_scalarsr_   __annotations___infer_matchesrW   rd   re   rg   rk   r}   r~   r   r   classmethodr   r   r   r   r   r   r   r   r   r&   rL   rj   r   r   r   rX   rl   rm   rn   ro   rp   rq   rr   rt   rv   ru   rs   rw   rx   ry   rz   r{   r|   rf   r   r  r'   _shared_doc_kwargsr   r  r#  r,  r8  rA  rJ  rM  rO  rQ  r_  rd  __classcell__)r-  s   @rR   rD   rD   |   sZ        4 4n D#28D>>!)8 8     !N   X J*+I++++???K????  J    & $.#;i#GGGGG'M'M'MMMMM
4 4 4 4 4: ( ( ( [( 
 #* * * * * [*6 =BC C C C C [C
 & & & & [&(   [ 4 4 4 [4T T T T- - - -0 0 0 0    ^    X / / / X/ AE2 2 2 2 24O O O O< ?	 D* O	 E" /	 C, ?	 D$ _	 F& _	 F& !	 J( D!/	 K. IG-o	  I: o	 G" O'	* *EX $O 	# #MH  K5 5 5 X5$m m m m mb? ? ? ? 	SMMM]}MMMMC1 C1 C1 C1 NMC1P     (-$
 
 
 
 
 
0 0 0 0 0 0 02 *0%)	E E E E E" !:>     ,8 8 8 8*G G G G1 1 1 1 10#8 #8 #8 #8J#, #, #,R ,0%           rT   r`   r"   c                h   t          |t          j        t          f          s|d}nt          |t                    r\t          j                    5  t          j        ddt                     t          |          j
        }ddd           n# 1 swxY w Y   nKt          |t          t          t          f          r|j        }n!t          t!          |                    j        }t          | j                  j
        }t%          j        t)          |           j        ||          }t-          |          S )a>  
    Helper function to render a consistent error message when raising
    IncompatibleFrequency.

    Parameters
    ----------
    left : PeriodArray
    right : None, DateOffset, Period, ndarray, or timedelta-like

    Returns
    -------
    IncompatibleFrequency
        Exception to be raised by the caller.
    NignorezPeriodDtype\[B\] is deprecated)category)r   own_freq
other_freq)r\   r   r   r0   r   warningscatch_warningsfilterwarningsFutureWarningr,   r   r.   rD   r#   r   r    r   rj   r!   r  r   rU   r"   )r.  rightru  rt  msgs        rR   r   r     sY     %"*&7899 =U]

	E:	&	& 	=$&& 	5 	5#;m    %U++4J		5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5
 
ENK@	A	A =]

"9U#3#344<
49%%.H

JJ(z  C !%%%s   1BBBFr   ,Sequence[Period | str | None] | AnyArrayLikerj   str | Tick | BaseOffset | Noner   r   c                   t          | dd          }t          j        |d          rt                              | |          S t          |t                    r5t          |           }|"||j        k    r|S |                    |          S |S t          | t          j
        t          t          t          f          st          |           } t          j        |           }|rt          |          }nd}|j        j        dk    r"t#          |          dk    rt%          d          |j        j        dv rG|                    t          j        d	          }t+          j        ||          }t          ||
          S t/          |          } |t+          j        |           }t          |          }t                              | |
          S )a  
    Construct a new PeriodArray from a sequence of Period scalars.

    Parameters
    ----------
    data : Sequence of Period objects
        A sequence of Period objects. These are required to all have
        the same ``freq.`` Missing values can be indicated by ``None``
        or ``pandas.NaT``.
    freq : str, Tick, or Offset
        The frequency of every element of the array. This can be specified
        to avoid inferring the `freq` from `data`.
    copy : bool, default False
        Whether to ensure a copy of the data is made.

    Returns
    -------
    PeriodArray

    See Also
    --------
    PeriodArray
    pandas.PeriodIndex

    Examples
    --------
    >>> period_array([pd.Period("2017", freq="Y"), pd.Period("2018", freq="Y")])
    <PeriodArray>
    ['2017', '2018']
    Length: 2, dtype: period[Y-DEC]

    >>> period_array([pd.Period("2017", freq="Y"), pd.Period("2018", freq="Y"), pd.NaT])
    <PeriodArray>
    ['2017', '2018', 'NaT']
    Length: 3, dtype: period[Y-DEC]

    Integers that look like years are handled

    >>> period_array([2000, 2001, 2002], freq="D")
    <PeriodArray>
    ['2000-01-01', '2001-01-01', '2002-01-01']
    Length: 3, dtype: period[D]

    Datetime-like strings may also be passed

    >>> period_array(["2000-Q1", "2000-Q2", "2000-Q3", "2000-Q4"], freq="Q")
    <PeriodArray>
    ['2000Q1', '2000Q2', '2000Q3', '2000Q4']
    Length: 4, dtype: period[Q-DEC]
    rL   Nr%  rS   r   z9PeriodIndex does not allow floating point in constructioniuFr   r   )r'  r   r&  rD   r   r\   r,   rj   r   r   r   r   tupler/   r   rL   kindr  r   r,  r   r   from_ordinalsr)   r   r   )	r   rj   r   
data_dtypeoutarrdatarL   arrr   s	            rR   period_arrayr    s   n w--J
z3'' 8++D$777*k** $z&&
::d###
 dRZui@AA DzzjG  D!!}S  S\\A%5%5STTT}T!!nnRXEn22 *355851111!!D|%d++E%%d%%888rT   c                    d S rK   r   r   s     rR   r   r     s    BE#rT   timedelta | str | Noner   c                    d S rK   r   r   s     rR   r   r     s    LOCrT   1BaseOffsetT | BaseOffset | timedelta | str | Nonec                    |t          |d          }| Wt          |           } t          | t                    st	          d          || j        }n|| j        k    rt          d          |S )at  
    If both a dtype and a freq are available, ensure they match.  If only
    dtype is available, extract the implied freq.

    Parameters
    ----------
    dtype : dtype
    freq : DateOffset or None

    Returns
    -------
    freq : DateOffset

    Raises
    ------
    ValueError : non-period dtype
    IncompatibleFrequency : mismatch between dtype and freq
    NT	is_periodzdtype must be PeriodDtypez&specified freq and dtype are different)r   r*   r\   r,   r   rj   r"   r   s     rR   r   r     s    * ...U##%-- 	:8999<:DDUZ'(PQQQ KrT   (tuple[npt.NDArray[np.int64], BaseOffset]c                    t          | j        t          j                  r| j        j        dk    rt	          d| j                   |Mt          | t
                    r| j        | j        }} nLt          | t                    r| j        | j	        j        }} n#t          | t
          t          f          r| j        } t          | j                  }t          j        |          }|j        }t          |                     d          |||          |fS )a  
    Convert a datetime-like array to values Period ordinals.

    Parameters
    ----------
    data : Union[Series[datetime64[ns]], DatetimeIndex, ndarray[datetime64ns]]
    freq : Optional[Union[str, Tick]]
        Must match the `freq` on the `data` if `data` is a DatetimeIndex
        or Series.
    tz : Optional[tzinfo]

    Returns
    -------
    ordinals : ndarray[int64]
    freq : Tick
        The frequency extracted from the Series or DatetimeIndex if that's
        used.

    r%  zWrong dtype: Nr   )reso)r\   rL   r   r  r   r-   r   rj   r/   dtr   r#   r   r   c_dt64arr_to_periodarrr   )r   rj   r   r  rP   s        rR   r   r   ?  s    , dj"(++ 7tz#/E/E555666|dH%% 	4ty$DDi(( 	4tw|$D	D8Y/	0	0 |tz**D%d++D"D!$))D//4$GGGMMrT   r   multintc                H   t          j        | ||          dk    rt          d          |t          |d          }|j        }| t          | |          } |t          ||          }t          | t
                    }t          |t
                    }|r!|r| j        |j        k    rt          d          | t          u s	|t          u rt          d          |*|r| j        }n|r|j        }nt          d          |j        }|m||z  }| 6t          j
        |j        |z
  |z   |j        dz   |t          j        	          }n_t          j
        | j        | j        |z   |t          j        	          }n/t          j
        | j        |j        dz   |t          j        	          }||fS )
N   zOOf the three parameters: start, end, and periods, exactly two must be specifiedTr  z!start and end must have same freqzstart and end must not be NaTz#Could not infer freq from start/endr   r   )comcount_not_noner   r   r  r#   r\   rj   r   r   aranger   r   )r   r   r   rj   r  is_start_per
is_end_perr   s           rR   r   r   g  s   
%g..!33,
 
 	

 ...vud##
S$eV,,LC((J >
 >uzSX'='=<===||sczz8999| 	D:DD 	D8DDBCCCvD.=9g%,ckAot28  DD 9u}w6BH  DD yaRXNNN:rT   tuple[np.ndarray, BaseOffset]c                   |d}|d}|d}|d}g }||6t          dd          }t          t          t          j        j                  }	n\t          |d          }t          j        |          }	|	t          t          t          j        j                  k    rt          d          |j	        }
t          | |          \  } }t          | |d          D ]O\  }}t          j        |||
          \  }}t          j        ||dddddd|		  	        }|                    |           Pn~t          |d          }t          j        |          }	t          | |||||          }t          |ddiD ]8\  }}}}}}|                    t          j        ||||||dd|		  	                   9t!          j        |t           j        	          |fS )
Nr   r   QTr  zbase must equal FR_QTR)strictr  r   )r   r
   r  r   FR_QTRr   r   freq_to_dtype_codeAssertionErrorr   _make_field_arrayszipr   quarter_to_myearperiod_ordinalappendr   r   r   )rl   rm   ry   rn   ro   rp   rq   rj   r   rP   r   yqcalendar_yearcalendar_monthvalarraysmthdhmnss                         rR   r   r     s    |~~
{H<SD111DY-344DDTT222D/55DtC!1!78888$%=>>>,*499ggd333 	! 	!DAq,3,DQ7,S,S)M>*~q!Q1a C OOC    	! ...+D11#D%dFFKK#&#<t#<#< 	W 	WAsAq"aOOI4QQ2q!QPTUUVVVV8HBH---t33rT   list[np.ndarray]c                     d | D ]^}t          |t          t          j        t          f          r5"t          |          k    rt          d          t          |          _fd| D             S )NzMismatched Period array lengthsc                    g | ]R}t          |t          j        t          t          f          rt          j        |          nt          j        |          SS r   )r\   r   r   r   r/   r   repeat).0r]   lengths     rR   
<listcomp>z&_make_field_arrays.<locals>.<listcomp>  s^         !bj$	:;;&BJqMMM1f%%	  rT   )r\   r   r   r   r/   r  r   )r   r]   r  s     @rR   r  r    s    F    a$
I677 	 !c!ff&6&6 !BCCC~Q
       rT   rK   )rE   rF   rG   rH   )r`   r"   re  )r   r|  rj   r}  r   r   r`   rD   )rj   rA   r`   rA   )rj   r  r`   r   )rj   r  r`   rA   )r`   r  )r   )r  r  )NNNNNNNN)r`   r  )r`   r  )i
__future__r   datetimer   rF  typingr   r   r   r   r	   r
   r   rv  numpyr   pandas._libsr   r   r   pandas._libs.arraysr   pandas._libs.tslibsr   r   r   r   r   r   r   r   r  r   r   r   r   r   r   pandas._libs.tslibs.dtypesr   r   pandas._libs.tslibs.fieldsr   pandas._libs.tslibs.offsetsr   r    pandas._libs.tslibs.periodr!   r"   r#   r$   r%   pandas.util._decoratorsr&   r'   r(   pandas.core.dtypes.commonr)   r*   pandas.core.dtypes.dtypesr+   r,   pandas.core.dtypes.genericr-   r.   r/   r0   pandas.core.dtypes.missingr1   r   r2   r   pandas.core.commoncorecommonr  collections.abcr3   r4   pandas._typingr5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   pandas.core.arrays.baser@   rA   ro  rX   DatelikeOpsPeriodMixinrD   r   r  r   r   r   r  r   rT   rR   <module>r     s   " " " " " "                                     . - - - - -                                     6 5 5 5 5 5                                                       , + + + + + 2 2 2 2 2 2                   7       
	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 988888        766666 gm:666 ] 
     OH H H H H#/9#8 H H HV !& !& !& !&T ,0]9 ]9 ]9 ]9 ]9@ 
 E E E 
 E 
 O O O 
 O" " " "L %N %N %N %N %NP. . . . .d 

		.4 .4 .4 .4 .4b     rT   