o
    �¨Êh4Ÿ  ã                   @  s€  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lImJ  mKZL erãd dlMmNZN d dlOmPZPmQZQmRZRmSZSmTZTmUZUmVZVmWZW d dlFmXZXmYZY d dlZm[Z[ e
ded�Z\ddiZ]dDdEdd „Z^G d!d„ deHj_e#j`ƒZadFd$d%„Zb		&dGdHd-d.„ZcedId/d0„ƒZdedJd3d0„ƒZddKd5d0„Zd	dDdLd7d8„ZdMdNd<d=„Ze								dOdPd?d@„ZfdQdBdC„ZgdS )Ré    )Ú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ÚPeriodArrayÚnameÚstrÚ	docstringú
str | Nonec                   s    ‡ fdd„}ˆ |_ ||_t|ƒS )Nc                   s   | j j}tˆ | j|ƒ}|S ©N)ÚdtypeÚ_dtype_coder#   Úasi8)ÚselfÚbaseÚresult©rB   © úK/var/www/html/env/lib/python3.10/site-packages/pandas/core/arrays/period.pyÚfm   s   z_field_accessor.<locals>.f)Ú__name__Ú__doc__Úproperty)rB   rD   rP   rN   rM   rO   Ú_field_accessorl   s   rT   c                      sè  e Zd ZU dZdZdZe e¡Z	e
fZdd„ ZdZed£d	d
„ƒ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 e Zded< g d¢Zded< ded< 	d¤d¥dd „Zed¦d$d%„ƒZeddd&œd§d'd(„ƒZeddd&œd§d)d*„ƒZed¨d©d+d,„ƒZed-d.„ ƒZedªd1d2„ƒZd«d6d7„Zd¬d:d;„Z d­d>d?„Z!e"d®d@dA„ƒZ#ed¯dCdD„ƒZ$ed°dEdF„ƒZ%	d±d²dJdK„Z&d¨dLdM„Z'e(dNdOƒZ)e(dPdQƒZ*e(dRdSƒZ+e(dTdUƒZ,e(dVdWƒZ-e(dXdYƒZ.e(dZd[ƒZ/e/Z0e(d\d]ƒZ1e1Z2e2Z3e(d^d_ƒ Z4Z5e(d`daƒZ6e(dbƒZ7e(dcddƒZ8e8Z9ed³dfdg„ƒZ:d´dµdkdl„Z;d¶dmdn„Z<e=d·i e>¤dododpœ¤Žd¸d¹drds„ƒZ?dºd»dudv„Z@dwddxœd¼d|d}„ZAd½d¾‡ fdd€„ZB	�	d¿dÀdˆd‰„ZCddd~dŠœdÁd‘d’„ZD	~dÂdÃ‡ fd“d”„ZEdÄd˜d™„ZFdÅdšd›„ZG‡ fdœd�„ZHdÆdŸd „ZId¡d¢„ ZJ‡  ZKS )ÇrA   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                 C  s
   t | tƒS rF   )Ú
isinstancer+   )ÚxrN   rN   rO   Ú<lambda>»   s    ÿzPeriodArray.<lambda>)r   Úreturnútype[Period]c                 C  s   t S rF   )r"   ©rJ   rN   rN   rO   Ú_scalar_typeÀ   ó   zPeriodArray._scalar_typez	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+   Ú_dtypeNFrG   úDtype | NoneÚcopyÚboolÚNonec                 C  s  |d urt jdttƒ d� t||ƒ}t|ƒ}|d ur+t|ƒ}t|tƒs+td|› d�ƒ‚t|t	ƒr?|j
}t|t| ƒƒs>tdƒ‚nt|tƒrG|j
}t|t| ƒƒrd|d ur]||jkr]t||jƒ‚|j|j}}|sntj|dd�}ntj|d|d�}|d u r~td	ƒ‚tt|ƒ}t | ||¡ d S )
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©rG   ©rG   r~   z-dtype is not specified and cannot be inferred)ÚwarningsÚwarnÚFutureWarningr'   Úvalidate_dtype_freqr+   r)   rV   Ú
ValueErrorr.   Ú_valuesÚtypeÚ	TypeErrorr-   rG   Úraise_on_incompatiblerc   Ú_ndarrayÚnpÚasarrayÚarrayr	   r   Ú__init__)rJ   ÚvaluesrG   rc   r~   rN   rN   rO   r’   ã   s<   ü


ÿ

zPeriodArray.__init__r“   únpt.NDArray[np.int64]r9   c                 C  s.   d}t |tjƒr|jdksJ |ƒ‚| ||d�S )Nz Should be numpy array of type i8Úi8rƒ   )rV   r�   ÚndarrayrG   )Úclsr“   rG   Úassertion_msgrN   rN   rO   Ú_simple_new  s   zPeriodArray._simple_newr„   c                C  sŒ   |d urt |ƒ}|rt|tƒr|j}nd }t|| ƒr(t|j|ƒ |r&| ¡ }|S tj|t	d�}|p5t
 |¡}t
 ||¡}t|ƒ}| ||d�S )Nrƒ   )r)   rV   r+   rc   rˆ   rG   r~   r�   r�   ÚobjectÚ	libperiodÚextract_freqÚextract_ordinals)r—   ÚscalarsrG   r~   rc   ÚperiodsÚordinalsrN   rN   rO   Ú_from_sequence  s   
zPeriodArray._from_sequencec                C  s   | j |||d�S )Nr„   )r¡   )r—   ÚstringsrG   r~   rN   rN   rO   Ú_from_sequence_of_strings4  s   z%PeriodArray._from_sequence_of_stringsc                 C  s<   t |tƒrt|j|jƒ}t|||ƒ\}}t|ƒ}| ||d�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ƒ   )rV   r   r   ÚnrB   r   r+   )r—   Údatarc   ÚtzrG   rN   rN   rO   Ú_from_datetime64:  s
   
zPeriodArray._from_datetime64c                 C  sN   t  |¡}|d urt |¡}|d us|d ur#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   ÚsubarrrN   rN   rO   Ú_generate_rangeO  s   

þzPeriodArray._generate_rangeÚfieldsÚdictc                C  s,   t dd|i|¤Ž\}}t|ƒ}| j||d�S )Nrc   rƒ   rN   )Ú_range_from_fieldsr+   r™   )r—   r°   rc   r®   rG   rN   rN   rO   Ú_from_fields]  s   zPeriodArray._from_fieldsÚvalueúPeriod | NaTTypeúnp.int64c                 C  sF   |t u r
t |j¡S t|| jƒr|  |¡ t |j¡S td|› d�ƒ‚)Nz!'value' should be a Period. Got 'z
' instead.)	r   r�   r‚   Ú_valuerV   r\   Ú_check_compatible_withÚordinalr‰   ©rJ   r´   rN   rN   rO   Ú_unbox_scalari  s   
zPeriodArray._unbox_scalarrC   r"   c                 C  s   t || jd�S )N)rc   )r"   rc   rº   rN   rN   rO   Ú_scalar_from_stringv  s   zPeriodArray._scalar_from_stringÚotherúPeriod | NaTType | PeriodArrayc                 C  s   |t u rd S |  |j¡ d S rF   )r   Ú_require_matching_freqrc   ©rJ   r½   rN   rN   rO   r¸   |  s   z"PeriodArray._check_compatible_withc                 C  s   | j S rF   )r|   r[   rN   rN   rO   rG   †  s   zPeriodArray.dtyper   c                 C  s   | j jS )zC
        Return the frequency object for this PeriodArray.
        ©rG   rc   r[   rN   rN   rO   rc   ‹  s   zPeriodArray.freqc                 C  s   t | jj| jjƒS rF   )r   rc   r¤   rB   r[   rN   rN   rO   Úfreqstr’  s   zPeriodArray.freqstrúNpDtype | Noneúbool | Noneú
np.ndarrayc                 C  s0   |dkr| j S |tkr| j S tjt| ƒtd�S )Nr•   rƒ   )rI   r   Ú_isnanr�   r‘   Úlistrš   )rJ   rG   r~   rN   rN   rO   Ú	__array__–  s
   zPeriodArray.__array__c                 C  s®   ddl }ddlm} |dur@|j |¡r|j| j|  ¡ |d�S t||ƒr8| j	|j
kr7td| j	› d|j
› d�ƒ‚ntd|› d	�ƒ‚|| j	ƒ}|j| j|  ¡ d
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Ž   r0   rV   rÂ   rc   rŒ   r=   Úfrom_storage)rJ   r‹   rÌ   rÉ   Úperiod_typeÚstorage_arrayrN   rN   rO   Ú__arrow_array__¡  s*   
ÿÿÿÿ
ÿ
zPeriodArray.__arrow_array__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')
        únpt.NDArray[np.bool_]c                 C  s   t t | 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[   rN   rN   rO   r_   b  s   zPeriodArray.is_leap_yearr¬   Úhowr;   c                 C  s:  ddl m} t |¡}|dk}|r<|dks| jdkr,tddƒtddƒ }| jdd	�| S tddƒ}| | j jdd	�| S |d
u rP| j ¡ }t	|dƒ}|j
}|}nt |¡}|j}| j||d	�}	t |	j|¡}
| |
¡}| jjdkr˜t | j¡}t|ƒdkr–|d }|| jjkr�| j|_|S |dkr–| jj|_|S | 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¬   )rÕ   NÚinfer)Úpandas.core.arraysr;   r›   Úvalidate_end_aliasrc   r   ry   r|   Ú_get_to_timestamp_baser   Ú_freqstrr"   rª   Ú_period_dtype_coderz   Úperiodarr_to_dt64arrrI   r¡   rB   ÚlibalgosÚunique_deltasÚlenrG   Ú_nÚ_freqrK   Ú
_with_freq)rJ   rc   rÕ   r;   r­   ÚadjustÚ	freq_coderG   rK   Únew_parrÚnew_dataÚdtaÚdiffsÚdiffrN   rN   rO   ry   o  s<   





ý

zPeriodArray.to_timestampc                 C  s   t j|| jd�S )N)r¹   rc   )r"   Ú_from_ordinalrc   )rJ   rW   rN   rN   rO   Ú	_box_func³  s   zPeriodArray._box_funcÚPeriodIndex)r½   Ú
other_namerÖ   c           
      C  sž   t  |¡}t|tƒrt|dƒrt|ƒj}t |¡}| j	j
}|j}| j}|dk}|r2|| jj d }n|}t||||ƒ}| jrCt|| j< t|ƒ}	t| ƒ||	d�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Ý   rV   r   Úhasattrr+   rß   r"   rª   r|   rH   rà   rI   rG   rå   r$   Ú_hasnar   rÆ   r‹   )
rJ   rc   rÕ   Úbase1Úbase2rI   r­   r¹   rë   rG   rN   rN   rO   rz   ¶  s    
.


zPeriodArray.asfreqÚboxedc                 C  s   |rt S djS )Nz'{}')rC   Úformat)rJ   r÷   rN   rN   rO   Ú
_formatterÿ  s   zPeriodArray._formatterr   )Úna_repÚdate_formatrú   ústr | floatúnpt.NDArray[np.object_]c                K  s   t  | j| jj||¡S )z3
        actually format my specific types
        )r›   Úperiod_array_strftimerI   rG   rH   )rJ   rú   rû   ÚkwargsrN   rN   rO   Ú_format_native_types  s   ÿz PeriodArray._format_native_typesTc                   sˆ   t |ƒ}|| jkr|s| S |  ¡ S t|tƒr|  |j¡S t |d¡s't|t	ƒr<t
|dd ƒ}t |¡}|  ¡  |¡ |¡S tƒ j||d�S )NÚMr¦   ©r~   )r)   r|   r~   rV   r+   rz   rc   r   Úis_np_dtyper*   Úgetattrr¨   Údtype_to_unitry   Útz_localizeÚas_unitÚsuperÚastype)rJ   rG   r~   r¦   Úunit©Ú	__class__rN   rO   r	    s   


zPeriodArray.astypeÚleftú$NumpyValueArrayLike | ExtensionArrayÚsideúLiteral['left', 'right']ÚsorterúNumpySorter | Noneúnpt.NDArray[np.intp] | np.intpc                 C  s,   |   |¡ d¡}| j d¡}|j|||d�S )NúM8[ns])r  r  )Ú_validate_setitem_valueÚviewrŽ   Úsearchsorted)rJ   r´   r  r  ÚnpvalueÚm8arrrN   rN   rO   r  $  s   zPeriodArray.searchsorted)ÚlimitÚ
limit_arear~   Úmethodr5   r  ú
int | Noner  ú#Literal['inside', 'outside'] | Nonec                C  s6   |   d¡}|j||||d�}|rtd|  | j¡ƒS | S )Nr  )r  r  r  r~   r9   )r  Ú_pad_or_backfillr	   rG   )rJ   r  r  r  r~   rì   rL   rN   rN   rO   r  1  s   

ÿzPeriodArray._pad_or_backfillc                   sD   |d ur|   d¡}|j||||d�}|  | j¡S tƒ j||||d�S )Nr  )r´   r  r  r~   )r  ÚfillnarG   r  )rJ   r´   r  r  r~   rì   rL   r  rN   rO   r   D  s
   
zPeriodArray.fillnaúnp.ndarray | intÚopúCallable[[Any, Any], Any]c                 C  sL   |t jt jfv s
J ‚|t ju r| }t| jtj|dd�ƒ}t| ƒ|| jd�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   rI   r�   r�   r‹   rG   )rJ   r½   r"  Ú
res_valuesrN   rN   rO   Ú_addsub_int_array_or_scalarT  s
   
z'PeriodArray._addsub_int_array_or_scalarc                 C  s,   t |tƒrJ ‚| j|dd� |  |jtj¡S )NT)rK   )rV   r   r¿   r(  r¤   r$  r%  rÀ   rN   rN   rO   Ú_add_offseti  s   zPeriodArray._add_offsetc                   sD   t | jtƒst| |ƒ‚t|ƒrtƒ  |¡S t t	|ƒj
¡}|  |¡S )z”
        Parameters
        ----------
        other : timedelta, Tick, np.timedelta64

        Returns
        -------
        PeriodArray
        )rV   rc   r   r�   r0   r  Ú_add_timedeltalike_scalarr�   r�   r   Úasm8Ú_add_timedelta_arraylike)rJ   r½   Útdr  rN   rO   r*  p  s   


z%PeriodArray._add_timedeltalike_scalarú,TimedeltaArray | npt.NDArray[np.timedelta64]c              
   C  s˜   | j  ¡ std| j › �ƒ‚t  d| j j› d�¡}ztt |¡|ddd�}W n ty6 } ztdƒ|‚d}~ww t	| j
t | d¡¡ƒ}t| ƒ|| j d	�S )
z›
        Parameters
        ----------
        other : TimedeltaArray or ndarray[timedelta64]

        Returns
        -------
        PeriodArray
        z2Cannot add or subtract timedelta64[ns] dtype from úm8[ú]F©rG   r~   Úround_okznCannot add/subtract timedelta-like from PeriodArray that is not an integer multiple of the PeriodArray's freq.Nr•   rƒ   )rG   Ú_is_tick_likerŒ   r�   Ú
_td64_unitr   r�   r‰   r!   r   rI   r  r‹   )rJ   r½   rG   ÚdeltaÚerrr'  rN   rN   rO   r,  …  s&   

ÿ
ÿÿý€ýz$PeriodArray._add_timedelta_arraylikec              
   C  s    | j  ¡ sJ ‚t  d| j j› d�¡}t|ttjtfƒr$t t	|ƒj
¡}nt |¡}z
t||ddd�}W n tyE } zt| |ƒ|‚d}~ww | d¡}t |¡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
        r/  r0  Fr1  Nr•   )rG   r3  r�   r4  rV   r   Útimedelta64r   r�   r   r+  r   r‰   r�   r  r   Úitem_from_zerodim)rJ   r½   rG   r-  r5  r6  rN   rN   rO   Ú _check_timedeltalike_freq_compatª  s   
€ÿ

z,PeriodArray._check_timedeltalike_freq_compat)rY   rZ   )NNF)rG   r}   r~   r   rY   r€   )r“   r”   rG   r+   rY   r9   )rG   r}   r~   r   rY   r9   rF   )rY   r9   )r°   r±   rY   r9   )r´   rµ   rY   r¶   )r´   rC   rY   r"   )r½   r¾   rY   r€   )rY   r+   )rY   r   )rY   rC   )NN)rG   rÃ   r~   rÄ   rY   rÅ   )rY   rÔ   )Nr¬   )rÕ   rC   rY   r;   )rY   rµ   rN   )NrÖ   )rÕ   rC   rY   r9   )F)r÷   r   )rú   rü   rY   rý   )T)r~   r   )r  N)r´   r  r  r  r  r  rY   r  )
r  r5   r  r  r  r  r~   r   rY   r9   )NNNT)r  r  r~   r   rY   r9   )r½   r!  r"  r#  rY   r9   )r½   r   )r½   r.  rY   r9   )LrQ   Ú
__module__Ú__qualname__rR   Ú__array_priority__Ú_typr�   r‚   r   Ú_internal_fill_valuer"   Ú_recognized_scalarsÚ_is_recognized_dtypeÚ_infer_matchesrS   r\   r^   Ú__annotations__r`   rd   rv   rw   r{   r’   Úclassmethodr™   r¡   r£   r§   r¯   r³   r»   r¼   r¸   r%   rG   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)  r*  r,  r9  Ú__classcell__rN   rN   r  rO   rA   y   sî   
 =
ÿ*
ûÿ




ÿ
þþþþþþþþþþþ
DHÿüúÿ


%rY   r!   c                 C  sŽ   t |tjtfƒs|du rd}n t |tƒrt|j|jƒ}nt |tt	t
fƒr(|j}ntt|ƒƒj}t| jj| jjƒ}tjt| ƒj||d�}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)rV   r�   r–   r/   r   r   r¤   rB   r-   rA   r"   rÂ   r   r   rc   r    rø   r‹   rQ   r!   )r  ÚrightrG  rF  ÚmsgrN   rN   rO   r�   Ð  s   
ÿr�   Fr¥   ú,Sequence[Period | str | None] | AnyArrayLikerc   ústr | Tick | BaseOffset | Noner~   r   c           	      C  s  t | ddƒ}t |d¡rt | |¡S t|tƒr-t| ƒ}|dur+||jkr&|S | |¡S |S t| t	j
tttfƒs;t| ƒ} t	 | ¡}|rGt|ƒ}nd}|jjdkrYt|ƒdkrYtdƒ‚|jjdv rs|jt	jdd	�}t ||¡}t||d
�S t|ƒ} |du r€t | ¡}t|ƒ}tj| |d
�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]
    rG   Nr  rP   r   z9PeriodIndex does not allow floating point in constructionÚiuFr  rƒ   )r  r   r  rA   r§   rV   r+   rc   rz   r�   r–   rÇ   Útupler.   r�   rG   Úkindrä   rŒ   r	  r‚   r›   Úfrom_ordinalsr(   rœ   r¡   )	r¥   rc   r~   Ú
data_dtypeÚoutÚarrdatarG   Úarrr    rN   rN   rO   Úperiod_arrayô  s6   :





rT  c                 C  ó   d S rF   rN   rÁ   rN   rN   rO   rˆ   W  r]   rˆ   útimedelta | str | Noner   c                 C  rU  rF   rN   rÁ   rN   rN   rO   rˆ   \  r]   ú1BaseOffsetT | BaseOffset | timedelta | str | Nonec                 C  s^   |dur
t |dd�}| dur-t| ƒ} t| tƒstdƒ‚|du r$| j}|S || 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)   rV   r+   r‰   rc   r!   rÁ   rN   rN   rO   rˆ   a  s   

üú(tuple[npt.NDArray[np.int64], BaseOffset]c                 C  s°   t | jtjƒr| jjdkrtd| j› �ƒ‚|du r4t | tƒr&| j| j} }nt | tƒr3| j| j	j} }n
t | ttfƒr>| j} t
| jƒ}t |¡}|j}t|  d¡|||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: Nr•   )Úreso)rV   rG   r�   rN  r‰   r,   rŠ   rc   r.   Údtr   r"   rª   rà   Úc_dt64arr_to_periodarrr  )r¥   rc   r¦   r[  rK   rN   rN   rO   r   †  s   

€

r   rØ   ÚmultÚintc                 C  sZ  t  | ||¡dkrtdƒ‚|d urt|dd�}|j}| d ur#t| |ƒ} |d ur,t||ƒ}t| tƒ}t|tƒ}|rD|rD| j|jkrDtdƒ‚| tu sL|tu rPtdƒ‚|d u rg|rZ| j}n
|r`|j}ntdƒ‚|j}|d ur›|| }| d u r‰t	j
|j| | |jd |t	jd	�}||fS t	j
| j| j| |t	jd	�}||fS t	j
| j|jd |t	jd	�}||fS )
Né   zOOf the three parameters: start, end, and periods, exactly two must be specifiedTrX  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"   rV   rc   r   r�   Úaranger¹   r‚   )r¬   r­   rŸ   rc   r^  Úis_start_perÚ
is_end_perr¥   rN   rN   rO   r«   ®  sJ   ÿ



ÿ
úÿþr«   útuple[np.ndarray, BaseOffset]c                 C  sZ  |d u rd}|d u rd}|d u rd}|d u rd}g }|d urr|d u r-t ddd�}tjj}	nt |dd�}t |¡}	|	tjjkrBtdƒ‚|j}
t| |ƒ\} }t	| |ƒD ]\}}t
 |||
¡\}}t ||dddddd|	¡	}| |¡ qQn1t |dd�}t |¡}	t| |||||ƒ}t	|Ž D ]\}}}}}}| t ||||||dd|	¡	¡ qŠtj|tjd�|fS )Nr   rØ   ÚQTrX  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    rK   rÂ   ÚyÚqÚcalendar_yearÚcalendar_monthÚvalÚarraysÚmthÚdÚhÚmnÚsrN   rN   rO   r²   ß  s@   


ÿû
"r²   úlist[np.ndarray]c                    s^   d ‰ | D ]!}t |ttjtfƒr%ˆ d urt|ƒˆ krtdƒ‚ˆ d u r%t|ƒ‰ q‡ fdd„| D ƒS )NzMismatched Period array lengthsc                   s4   g | ]}t |tjttfƒrt |¡nt |ˆ ¡‘qS rN   )rV   r�   r–   rÇ   r.   r�   Úrepeat)Ú.0rW   ©ÚlengthrN   rO   Ú
<listcomp>  s    þÿ
ýz&_make_field_arrays.<locals>.<listcomp>)rV   rÇ   r�   r–   r.   rä   r‰   )r°   rW   rN   r~  rO   rk    s   €
ürk  rF   )rB   rC   rD   rE   )rY   r!   )NF)r¥   rJ  rc   rK  r~   r   rY   rA   )rc   r>   rY   r>   )rc   rV  rY   r   )rc   rW  rY   r>   )rY   rZ  )rØ   )r^  r_  )NNNNNNNN)rY   rf  )rY   r{  )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   r]  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.   r/   Úpandas.core.dtypes.missingr0   rÜ   r1   r¨   Úpandas.core.commonÚcoreÚcommonra  Úcollections.abcr2   Úpandas._typingr3   r4   r5   r6   r7   r8   r9   r:   r;   r<   Úpandas.core.arrays.baser=   r>   rD  rT   ÚDatelikeOpsÚPeriodMixinrA   r�   rT  rˆ   r«   r²   rk  rN   rN   rN   rO   Ú<module>   sv    $	8(ÿ      
]&ýc
&ÿ(2ø1