
    Owg4                       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$ d dl%m&Z&m'Z'm(Z( d d	l)m*Z* d d
l+m,Z,m-Z- d dl.m/Z/m0Z0m1Z1m2Z2m3Z3 d dl4m5Z5m6Z6 d dl7m8Z8 d dl9m:Z:m;Z; d dl<m=Z=m>Z> d dl?m@Z@mAZAmBZBmCZC d dlDmEZE d dlFmGZH d dlImJc mKZL er(d dlMmNZN d dlOmPZPmQZQmRZRmSZSmTZTmUZUmVZVmWZW d dlFmXZXmYZY d dlZm[Z[  e
de      Z\ddiZ]d&d'dZ^ G d deHj                  e#j                        Zad(dZb	 	 d)	 	 	 	 	 	 	 d*dZced+d       Zded,d        Zd	 	 	 	 d-d!Zd	 d&	 d.d"Zd/d0d#Ze	 	 	 	 	 	 	 	 d1	 d2d$Zfd3d%Zgy)4    )annotations)	timedeltaN)TYPE_CHECKINGAnyCallableLiteralTypeVarcastoverload)algoslib)NDArrayBacked)
BaseOffsetNaTNaTType	Timedeltaadd_overflowsafeastype_overflowsafedt64arr_to_periodarrget_unit_from_dtypeiNaTparsingperiod	to_offset)	FreqGroupPeriodDtypeBasefreq_to_period_freqstr)isleapyear_arr)Tickdelta_to_tick)DIFFERENT_FREQIncompatibleFrequencyPeriodget_period_field_arrperiod_asfreq_arr)cache_readonlydoc)find_stack_level)ensure_objectpandas_dtype)DatetimeTZDtypePeriodDtype)ABCIndexABCPeriodIndex	ABCSeriesABCTimedeltaArray)isna)datetimelike)Sequence)AnyArrayLikeDtypeFillnaOptionsNpDtypeNumpySorterNumpyValueArrayLikeSelfnpt)DatetimeArrayTimedeltaArray)ExtensionArrayBaseOffsetT)boundklassPeriodArrayc                @      fd} |_         ||_        t        |      S )Nc                b    | j                   j                  }t        | j                  |      }|S N)dtype_dtype_coder$   asi8)selfbaseresultnames      P/var/www/horilla/myenv/lib/python3.12/site-packages/pandas/core/arrays/period.pyfz_field_accessor.<locals>.fm   s)    zz%%%dDIIt<    )__name____doc__property)rL   	docstringrN   s   `  rM   _field_accessorrT   l   s"    
 AJAIA;rO   c                      e Zd ZU dZdZdZ ej                  e      Z	e
fZd ZdZedRd       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<   	 dS	 	 	 	 	 dTdZe	 	 	 	 	 	 dUd       Zeddd	 	 	 	 	 dVd       Zeddd	 	 	 	 	 dVd       ZedWdXd       Zed        ZedYd       Z	 	 	 	 dZdZd[dZ d\d Z!e"d]d!       Z#ed^d"       Z$ed_d#       Z%	 d`	 	 	 	 	 dad$Z&dWd%Z' e(d&d'      Z) e(d(d)      Z* e(d*d+      Z+ e(d,d-      Z, e(d.d/      Z- e(d0d1      Z. e(d2d3      Z/e/Z0 e(d4d5      Z1e1Z2e2Z3 e(d6d7      xZ4Z5 e(d8d9      Z6 e(d:      Z7 e(d;d<      Z8e8Z9edbd=       Z:dcddd>Z;ded?Z< e=dfi e>d@d@dAdgdhdB       Z?didjdCZ@dDddE	 	 	 dkdFZAdldm fdHZB	 	 dn	 	 	 	 	 	 	 dodIZCdddGdJ	 	 	 	 	 	 	 	 	 dpdKZD	 dq	 	 	 	 	 dr fdLZE	 	 	 	 	 	 dsdMZFdtdNZG fdOZH	 	 	 	 dudPZIdQ ZJ xZKS )vrB   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.
    freq : str or DateOffset
        The `freq` to use for the array. Mostly applicable when `values`
        is an ndarray of integers, when `freq` is required. When `values`
        is a PeriodArray (or box around), it's checked that ``values.freq``
        matches `freq`.
    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 rE   )
isinstancer,   )xs    rM   <lambda>zPeriodArray.<lambda>   s    Z	;& rO   )r   c                    t         S rE   )r#   rI   s    rM   _scalar_typezPeriodArray._scalar_type   s    rO   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,   _dtypeNFc                   |;t        j                  dt        t                      t	        ||      }t        |      }|*t        |      }t        |t
              st        d| d      t        |t              r,|j                  }t        |t        |             s't        d      t        |t              r|j                  }t        |t        |             r?|%||j                  k7  rt        ||j                         |j"                  |j                  }}|st%        j&                  |d      }nt%        j(                  |d|      }|t        d	      t+        t
        |      }t-        j.                  | ||       y )
Nz}The 'freq' keyword in the PeriodArray constructor is deprecated and will be removed in a future version. Pass 'dtype' instead)
stacklevelzInvalid dtype z for PeriodArrayzIncorrect dtypeint64rF   rF   copyz-dtype is not specified and cannot be inferred)warningswarnFutureWarningr(   validate_dtype_freqr,   r*   rX   
ValueErrorr/   _valuestype	TypeErrorr.   rF   raise_on_incompatiblerc   _ndarraynpasarrayarrayr
   r   __init__)rI   valuesrF   rc   r   s        rM   r   zPeriodArray.__init__   sA    MMP+-	 'ud3D%E 'Ee[1 >%8H!IJJfi(^^Ffd4j1 122/^^Ffd4j) Ufll%:+FEJJ??"OOV\\EFZZg6FXXfG$?F=LMM[%(tVU3rO   c                z    d}t        |t        j                        r|j                  dk(  sJ |        | ||      S )Nz Should be numpy array of type i8i8r   )rX   r   ndarrayrF   )clsr   rF   assertion_msgs       rM   _simple_newzPeriodArray._simple_new  s:     ;&"**-&,,$2FUUF6''rO   r   c                  |t        |      }|rt        |t              r|j                  }nd }t        ||       r*t	        |j
                  |       |r|j                         }|S t        j                  |t              }|xs t        j                  |      }t        j                  ||      }t        |      } | ||      S )Nr   )r*   rX   r,   rc   r   rF   r   r   r   object	libperiodextract_freqextract_ordinals)r   scalarsrF   r   rc   periodsordinalss          rM   _from_sequencezPeriodArray._from_sequence  s      'EZ{3::DDgs#t4!,,.N**WF36y--g6--gt<D!85))rO   c               *    | j                  |||      S )Nr   )r   )r   stringsrF   r   s       rM   _from_sequence_of_stringsz%PeriodArray._from_sequence_of_strings4  s     !!'T!BBrO   c                    t        |t              r t        |j                  |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   )rX   r   r   nrL   r   r,   )r   datarc   tzrF   s        rM   _from_datetime64zPeriodArray._from_datetime64:  sK     dJ')$&&$))<D)$b9
dD!4u%%rO   c                    t        j                  |      }|t        j                  |      }||t	        ||||      \  }}||fS t        d      )Nz/Not enough parameters to construct Period range)dtlvalidate_periodsr#   _maybe_convert_freq_get_ordinal_ranger   )r   startendr   rc   subarrs         rM   _generate_rangezPeriodArray._generate_rangeO  s`    &&w/--d3D-eS'4HLFD t| NOOrO   c               ^    t        dd|i|\  }}t        |      }| j                  ||      S )Nrc   r    )_range_from_fieldsr,   r   )r   fieldsrc   r   rF   s        rM   _from_fieldszPeriodArray._from_fields]  s5    )>t>v>D!vU33rO   c                    |t         u rt        j                  |j                        S t	        || j
                        r0| j                  |       t        j                  |j                        S t        d| d      )Nz!'value' should be a Period. Got 'z
' instead.)	r   r   r   _valuerX   r]   _check_compatible_withordinalr   rI   values     rM   _unbox_scalarzPeriodArray._unbox_scalari  sd     C<88ELL))t001''.88EMM**@zRSSrO   c                0    t        || j                        S )N)rc   )r#   rc   r   s     rM   _scalar_from_stringzPeriodArray._scalar_from_stringv  s    e$)),,rO   c                L    |t         u ry | j                  |j                         y rE   )r   _require_matching_freqrc   rI   others     rM   r   z"PeriodArray._check_compatible_with|  s     C< 	##EJJ/rO   c                    | j                   S rE   )r|   r\   s    rM   rF   zPeriodArray.dtype  s    {{rO   c                .    | j                   j                  S )zC
        Return the frequency object for this PeriodArray.
        rF   rc   r\   s    rM   rc   zPeriodArray.freq  s    
 zzrO   c                j    t        | j                  j                  | j                  j                        S rE   )r   rc   r   rL   r\   s    rM   freqstrzPeriodArray.freqstr  s    %diikk499>>BBrO   c                    |dk(  r| j                   S |t        k(  r| j                   S t        j                  t        |       t              S )Nr   r   )rH   bool_isnanr   r   listr   )rI   rF   r   s      rM   	__array__zPeriodArray.__array__  s?     D=99d]KK< xxT
&11rO   c                   ddl }ddlm} ||j                  j	                  |      r,|j                  | j                  | j                         |      S t        ||      r?| j                  |j                  k7  r5t        d| j                   d|j                   d      t        d| d	       || j                        }|j                  | j                  | j                         d
      }|j                  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   rX   r   rc   r   r>   from_storage)rI   r   r   r   period_typestorage_arrays         rM   __arrow_array__zPeriodArray.__arrow_array__  s     	L}}''-}}T]]4}PPD/2<<499,###'<<.TYYKqB 
  ?vVL  &dll3dmm$))+GT%%22;NNrO   re   z
        The year of the period.

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

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

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

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

        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')
        rj   a	  
        The second of the period.

        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')
        rm   a   
        The week ordinal of the year.

        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')
        ro   z
        The day of the week with Monday=0, Sunday=6.

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

        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')
        rr   z
        The quarter of the date.

        Examples
        --------
        >>> idx = pd.PeriodIndex(["2023-01", "2023-02", "2023-03"], freq="M")
        >>> idx.quarter
        Index([1, 1, 1], dtype='int64')
        rs   rt   a  
        The number of days in the month.

        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')
        c                R    t        t        j                  | j                              S )z
        Logical indicating if the date belongs to a leap year.

        Examples
        --------
        >>> idx = pd.PeriodIndex(["2023", "2024", "2025"], freq="Y")
        >>> idx.is_leap_year
        array([False,  True, False])
        )r   r   r   re   r\   s    rM   r_   zPeriodArray.is_leap_yearb  s     bjj344rO   c                   ddl m} t        j                  |      }|dk(  }|rp|dk(  s| j                  dk(  r.t        dd      t        dd      z
  }| j                  d	      |z   S t        dd      }| | j                  z   j                  d	      |z
  S |5| j                  j                         }t        |d      }|j                  }|}n!t        j                  |      }|j                  }| j                  ||	      }	t        j                  |	j                   |      }
 |j"                  |
      }| j                  j$                  dk(  rt'        j(                  | j                         }t+        |      dk(  rQ|d   }|| j,                  j.                  k(  r| j                  |_        |S |dk(  r| j                  j2                  |_        |S |j5                  d
      S )a  
        Cast to DatetimeArray/Index.

        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

        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[ns]', freq='MS')
        r   )r<   EB   Dnsr   )howinfer)pandas.core.arraysr<   r   validate_end_aliasrc   r   ry   r|   _get_to_timestamp_baser   _freqstrr#   r   _period_dtype_coderz   periodarr_to_dt64arrrH   r   rL   libalgosunique_deltaslenrF   _n_freqrJ   
_with_freq)rI   rc   r   r<   r   adjust	freq_coderF   rJ   new_parrnew_datadtadiffsdiffs                 rM   ry   zPeriodArray.to_timestampo  s   . 	5**3/Sjs{dii3."1c*Yq$-??((W(5>>"1d+tyy(6676CfLL<::<I#Iq1E>>DD--d3D**D;;t;-11(--F*m**8499>>S  **4995E5zQQx4::==( $		CI J QY $		CIJ>>'**rO   c                D    t        j                  || j                        S )N)r   rc   )r#   _from_ordinalrc   )rI   rY   s     rM   	_box_funczPeriodArray._box_func  s    ##ADII>>rO   PeriodIndex)r   
other_namec                   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   rX   r   hasattrr,   r   r#   r   r|   rG   r   rH   rF   r   r%   _hasnar   r   r   )
rI   rc   r   base1base2rH   r   r   r   rF   s
             rM   rz   zPeriodArray.asfreq  s    \ **3/dJ'GD:N,Ot$--D))$/''''yySjTZZ]]*Q.GG$WeUC@;;$(HT[[!D!tDz(%00rO   c                *    |rt         S dj                  S )Nz'{}')strformat)rI   boxeds     rM   
_formatterzPeriodArray._formatter  s    J}}rO   r   )na_repdate_formatc               n    t        j                  | j                  | j                  j                  ||      S )z3
        actually format my specific types
        )r   period_array_strftimerH   rF   rG   )rI   r  r  kwargss       rM   _format_native_typesz PeriodArray._format_native_types  s.     ..IItzz--v{
 	
rO   Tc                   t        |      }|| j                  k(  r|s| S | j                         S t        |t              r| j                  |j                        S t        j                  |d      st        |t              rPt        |dd       }t        j                  |      }| j                         j                  |      j                  |      S t         | E  ||      S )NMr   r   )r*   r|   r   rX   r,   rz   rc   r   is_np_dtyper+   getattrr   dtype_to_unitry   tz_localizeas_unitsuperastype)rI   rF   r   r   unit	__class__s        rM   r  zPeriodArray.astype  s     U#DKKyy{"e[);;uzz**??5#&*UO*Ld+B$$U+D$$&2226>>tDDw~e$~//rO   c                    | j                  |      j                  d      }| j                  j                  d      }|j                  |||      S )NM8[ns])sidesorter)_validate_setitem_valueviewr   searchsorted)rI   r   r  r  npvaluem8arrs         rM   r  zPeriodArray.searchsorted$  sM     ..u5::8D ""8,!!'V!DDrO   )limit
limit_arear   c                   | j                  d      }|j                  ||||      }|r%t        d|j                  | j                              S | S )Nr  )methodr   r!  r   r:   )r  _pad_or_backfillr
   rF   )rI   r#  r   r!  r   r   rK   s          rM   r$  zPeriodArray._pad_or_backfill1  sT     ii!%%:D & 
 DJJ 788KrO   c                    |A| j                  d      }|j                  ||||      }|j                  | j                        S t        |   ||||      S )Nr  )r   r#  r   r   )r  fillnarF   r  )rI   r   r#  r   r   r   rK   r  s          rM   r&  zPeriodArray.fillnaD  s]      ))H%CZZeF%dZSF ;;tzz**w~E&D~QQrO   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   rH   r   r   r   rF   )rI   r   op
res_valuess       rM   _addsub_int_array_or_scalarz'PeriodArray._addsub_int_array_or_scalarT  sd     hllHLL1111FE%diiE1NO
tDz*DJJ77rO   c                    t        |t              rJ | j                  |d       | j                  |j                  t
        j                        S )NT)rJ   )rX   r   r   r-  r   r(  r)  r   s     rM   _add_offsetzPeriodArray._add_offseti  s@    eT***##E#5//FFrO   c                    t        | j                  t              st        | |      t	        |      rt
        |   |      S t        j                  t        |      j                        }| j                  |      S )z
        Parameters
        ----------
        other : timedelta, Tick, np.timedelta64

        Returns
        -------
        PeriodArray
        )rX   rc   r   r   r1   r  _add_timedeltalike_scalarr   r   r   asm8_add_timedelta_arraylike)rI   r   tdr  s      rM   r1  z%PeriodArray._add_timedeltalike_scalarp  sa     $))T*'e44;74U;;ZZ	%(--.,,R00rO   c                   | j                   j                         st        d| j                          t        j                   d| j                   j                   d      }	 t        t        j                  |      |dd      }t        | j                  t        j                  |j                  d                  } t        |       || j                   	      S # t        $ r}t        d      |d}~ww xY w)
z
        Parameters
        ----------
        other : TimedeltaArray or ndarray[timedelta64]

        Returns
        -------
        PeriodArray
        z2Cannot add or subtract timedelta64[ns] dtype from m8[]FrF   r   round_okznCannot add/subtract timedelta-like from PeriodArray that is not an integer multiple of the PeriodArray's freq.Nr   r   )rF   _is_tick_liker   r   
_td64_unitr   r   r   r"   r   rH   r  r   )rI   r   rF   deltaerrr,  s         rM   r3  z$PeriodArray._add_timedelta_arraylike  s     zz'')DTZZLQ  3tzz445Q78
	'

5!UUE &diiEJJt<L1MN
tDz*DJJ77  	 (E 	s   !"C 	C2!C--C2c                   | j                   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      }|j                  d      }t        j                   |      S # t        $ r}t        | |      |d}~ww xY w)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
        r6  r7  Fr8  Nr   )rF   r:  r   r;  rX   r   timedelta64r   r   r   r2  r   r   r   r  r   item_from_zerodim)rI   r   rF   r4  r<  r=  s         rM    _check_timedeltalike_freq_compatz,PeriodArray._check_timedeltalike_freq_compat  s    ( zz'')))3tzz445Q78ei>?Ie,112BE"B	>'%eeTE 

4 $$U++	  	>'e4#=	>s   .C# #	C>,C99C>)returnztype[Period])NNF)rF   Dtype | Noner   r   rB  None)r   znpt.NDArray[np.int64]rF   r,   rB  r:   )rF   rC  r   r   rB  r:   rE   )rB  r:   )r   dictrB  r:   )r   Period | NaTTyperB  znp.int64)r   r  rB  r#   )r   zPeriod | NaTType | PeriodArrayrB  rD  )rB  r,   )rB  r   )rB  r  )NN)rF   zNpDtype | Noner   zbool | NonerB  z
np.ndarray)rB  znpt.NDArray[np.bool_])Nr   )r   r  rB  r<   )rB  rF  r   )Nr   )r   r  rB  r:   )F)r  r   )r  zstr | floatrB  znpt.NDArray[np.object_])T)r   r   )leftN)r   z$NumpyValueArrayLike | ExtensionArrayr  zLiteral['left', 'right']r  zNumpySorter | NonerB  znpt.NDArray[np.intp] | np.intp)
r#  r6   r   
int | Noner!  z#Literal['inside', 'outside'] | Noner   r   rB  r:   )NNNT)r   rH  r   r   rB  r:   )r   znp.ndarray | intr+  zCallable[[Any, Any], Any]rB  r:   )r   r   )r   z,TimedeltaArray | npt.NDArray[np.timedelta64]rB  r:   )LrP   
__module____qualname__rQ   __array_priority___typr   r   r   _internal_fill_valuer#   _recognized_scalars_is_recognized_dtype_infer_matchesrR   r]   r^   __annotations__r`   rd   rv   rw   r{   r   classmethodr   r   r   r   r   r   r   r   r   r&   rF   rc   r   r   r   rT   re   rf   rg   rh   ri   rj   rk   rm   ro   rn   rl   rp   rq   rr   rs   rt   ru   r_   ry   r   r'   _shared_doc_kwargsrz   r  r
  r  r  r$  r&  r-  r/  r1  r3  rA  __classcell__)r  s   @rM   rB   rB   y   s   :z D#288D>!) !N  J	*+Iy+?K?J	 & $.#;i#GyG'M9M KP'4)'4CG'4	'4T (%( ( 
	( ( 
 #* 	*
 * 
* *6 /3%C ,C;?C	C C
 & &(   4 4TT 
T-0     C C AE	2#	22=	2		2O< 	D 	E 	C 	D 		F 		F !	J D!	K IG-	 I$ 	G G$E#	M:  K
5 
5@+H? 	MM]}MC1 NC1P (-$
$
	 
0. *0%)	E3E 'E #	E
 
(E" !:>  	
 8  
( OSR.8RGKR	R 8%8+D8	8*G1*#8A#8	#8J#,rO   c                   t        |t        j                  t        f      s|d}nwt        |t              r!t        |j                  |j                        }nFt        |t        t        t        f      r|j                  }nt        t        |            j                  }t        | j                  j                  | 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)r   own_freq
other_freq)rX   r   r   r0   r   r   r   rL   r.   rB   r#   r   r    r   rc   r!   r  r   rP   r"   )rG  rightrW  rV  msgs        rM   r   r     s      %"**&789U]
	E:	&+EGGUZZ@
	ENK@	A]]
"9U#34<<
%diikk499>>BH


J(zC !%%rO   c                N   t        | dd      }t        j                  |d      rt        j	                  | |      S t        |t              r1t        |       }|"||j                  k(  r|S |j                  |      S |S t        | t        j                  t        t        t        f      st        |       } t        j                  |       }|rt        |      }nd}|j                  j                   dk(  rt#        |      dkD  rt%        d      |j                  j                   dv rD|j'                  t        j(                  d	      }t+        j,                  ||      }t        ||
      S t/        |      } |t+        j0                  |       }t        |      }t        j3                  | |
      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]
    rF   Nr  rN   r   z9PeriodIndex does not allow floating point in constructioniuFr  r   )r  r   r  rB   r   rX   r,   rc   rz   r   r   r   tupler/   r   rF   kindr   r   r  r   r   from_ordinalsr)   r   r   )	r   rc   r   
data_dtypeoutarrdatarF   arrr   s	            rM   period_arrayrc    sh   t w-J
z3'++D$77*k*$z&
::d##
 dRZZui@ADzjjG D!}}S S\A%5STT}}T!nnRXXEn2 **358511!D|%%d+E%%d%%88rO   c                     y rE   r   r   s     rM   r   r   W      rO   c                     y rE   r   r   s     rM   r   r   \  re  rO   c                    |t        |d      }| Pt        |       } t        | t              st	        d      || j
                  }|S || j
                  k7  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
    T	is_periodzdtype must be PeriodDtypez&specified freq and dtype are different)r   r*   rX   r,   r   rc   r"   r   s     rM   r   r   a  sr    * .U#%-899<::D
 K	 UZZ'(PQQ KrO   c                X   t        | j                  t        j                        r| j                  j                  dk7  rt	        d| j                         |\t        | t
              r| j                  | j                  }} nUt        | t              rE| j                  | j                  j                  }} n"t        | t
        t        f      r| j                  } t        | j                        }t        j                  |      }|j                  }t        | j                  d      |||      |fS )a  
    Convert an 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: r   )reso)rX   rF   r   r]  r   r-   r   rc   r/   dtr   r#   r   r   c_dt64arr_to_periodarrr  )r   rc   r   rk  rJ   s        rM   r   r     s    , djj"((+tzz#/E=566|dH%tyy$Di(tww||$D	D8Y/	0||tzz*D%%d+D""D!$))D/4$GMMrO   c                   t        j                  | ||      dk7  rt        d      |t        |d      }|j                  }| t        | |      } |t        ||      }t        | t
              }t        |t
              }|r&|r$| j                  |j                  k7  rt        d      | t        u s|t        u rt        d      |5|r| j                  }n|r|j                  }nt        d      |j                  }|||z  }| Ht        j                  |j                  |z
  |z   |j                  dz   |t        j                  	      }||fS t        j                  | j                  | j                  |z   |t        j                  	      }||fS t        j                  | j                  |j                  dz   |t        j                  	      }||fS )
N   zOOf the three parameters: start, end, and periods, exactly two must be specifiedTrh  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#   rX   rc   r   r   aranger   r   )r   r   r   rc   multis_start_per
is_end_perr   s           rM   r   r     s   
%g.!3,
 	

 .vvud#
S$eV,LC(J
uzzSXX'=<==|scz899|::D88DBCCvvD.=99g%,ckkAot288D : 99u}}w6BHHD : yyaRXXN:rO   c                4   |d}|d}|d}|d}g }||(t        dd      }t        j                  j                  }	nJt        |d      }t	        j
                  |      }	|	t        j                  j                  k7  rt        d      |j                  }
t        | |      \  } }t        | |      D ]M  \  }}t        j                  |||
      \  }}t	        j                  ||dddddd|		      }|j                  |       O nrt        |d      }t	        j
                  |      }	t        | |||||      }t        | D ]5  \  }}}}}}|j                  t	        j                  ||||||dd|		             7 t        j                  |t        j                         |fS )Nr   r   QTrh  zbase must equal FR_QTRr   )r   r   FR_QTRr   r   freq_to_dtype_codeAssertionErrorr   _make_field_arrayszipr   quarter_to_myearperiod_ordinalappendr   r   r   )re   rf   rr   rg   rh   ri   rj   rc   r   rJ   r   yqcalendar_yearcalendar_monthvalarraysmthdhmnss                         rM   r   r     s    |~~
{H<SD1D##))DTT2D//5Dy''---$%=>>,,*49gg& 	!DAq,3,D,DQ7,S)M>**~q!Q1aC OOC 	! .++D1#D%dFFK#&< 	WAsAq"aOOI44QQ2q!QPTUV	W 88HBHH-t33rO   c            	     x   d }| D ]Q  }t        |t        t        j                  t        f      s)|t        |      |k7  rt        d      |Gt        |      }S | D cg c]R  }t        |t        j                  t        t        f      rt        j                  |      nt        j                  ||      T c}S c c}w )NzMismatched Period array lengths)	rX   r   r   r   r/   r   r   r   repeat)r   lengthrY   s      rM   r{  r{    s    F  a$

I67!c!f&6 !BCC~Q  	  a"**dI67 	

1YYq&!	"  s   AB7rE   )rL   r  rS   z
str | None)rB  r"   )NF)r   z,Sequence[Period | str | None] | AnyArrayLikerc   zstr | Tick | BaseOffset | Noner   r   rB  rB   )rc   r?   rB  r?   )rc   ztimedelta | str | NonerB  r   )rc   z1BaseOffsetT | BaseOffset | timedelta | str | NonerB  r?   )rB  z(tuple[npt.NDArray[np.int64], BaseOffset])r   )rs  int)NNNNNNNN)rB  ztuple[np.ndarray, BaseOffset])rB  zlist[np.ndarray])h
__future__r   datetimer   r(  typingr   r   r   r   r	   r
   r   r   numpyr   pandas._libsr   r   r   pandas._libs.arraysr   pandas._libs.tslibsr   r   r   r   r   r   r   rm  r   r   r   r   r   r   pandas._libs.tslibs.dtypesr   r   r   pandas._libs.tslibs.fieldsr   pandas._libs.tslibs.offsetsr   r    pandas._libs.tslibs.periodr!   r"   r#   r$   r%   pandas.util._decoratorsr&   r'   pandas.util._exceptionsr(   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commonrp  collections.abcr3   pandas._typingr4   r5   r6   r7   r8   r9   r:   r;   r<   r=   pandas.core.arrays.baser>   r?   rS  rT   DatelikeOpsPeriodMixinrB   r   rc  r   r   r   r{  r   rO   rM   <module>r     s   "       .    
 6  5  , 2    (	 	 	 7 m:6 ] 
T,#//9#8#8 T,n&L ,0`9
6`9
(`9 `9 	`9F 
 
 
 
"B""L %N-%NP.d 

		.4 #.4brO   