a
    DBìj”¢  ã                   @  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]dBdddœdd„Z^G d d„ deHj_e#j`ƒZad!d"œd#d$„ZbdCd&d'd(dd)œd*d+„Zceddd,œd-d.„ƒZded/d0d,œd1d.„ƒZdd2dd,œd3d.„ZddDd4d"œd5d6„ZdEd8d9œd:d;„ZedFd<d"œd=d>„Zfd?d"œd@dA„ZgdS )Gé    )Ú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Ústrz
str | None)ÚnameÚ	docstringc                   s    ‡ fdd„}ˆ |_ ||_t|ƒS )Nc                   s   | j j}tˆ | j|ƒ}|S ©N)ÚdtypeÚ_dtype_coder#   Úasi8)ÚselfÚbaseÚresult©rC   © úX/mnt/bigstor/www/usecases/.venv/lib/python3.9/site-packages/pandas/core/arrays/period.pyÚfm   s    z_field_accessor.<locals>.f)Ú__name__Ú__doc__Úproperty)rC   rD   rO   rM   rL   rN   Ú_field_accessorl   s    rS   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	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dœdd„Zed dd!d"œd#d$„ƒZeddd%œddd!dœd&d'„ƒZeddd%œddd!dœd(d)„ƒZed£d!dœd*d+„ƒZed,d-„ ƒZed.d!d/œd0d1„ƒZd2d3d4œd5d6„Zd7d8d4œd9d:„Z d;dd<œd=d>„Z!e"ddœd?d@„ƒZ#edAdœdBdC„ƒZ$ed7dœdDdE„ƒZ%d¤dFdGdHdœdIdJ„Z&d¥dKdL„Z'e(dMdNƒZ)e(dOdPƒZ*e(dQdRƒZ+e(dSdTƒZ,e(dUdVƒZ-e(dWdXƒZ.e(dYdZƒZ/e/Z0e(d[d\ƒZ1e1Z2e2Z3e(d]d^ƒ Z4Z5e(d_d`ƒZ6e(daƒZ7e(dbdcƒZ8e8Z9edddœdedf„ƒZ:d¦d7dhdiœdjdk„Z;d2dœdldm„Z<e=f i e>¤dndndoœ¤Žd§d7d!diœdqdr„ƒZ?d¨ddsœdtdu„Z@dvddwœdxdydzœd{d|„ZAd©dd~œ‡ fdd€„ZBdªd‚dƒd„d…d†œd‡dˆ„ZCddd}d‰œdŠd‹dŒdd!d�œdŽd�„ZDd«d‹dd!d�œ‡ fd‘d’„ZEd“d”d!d•œd–d—„ZFdAd˜œd™dš„ZG‡ fd›dœ„ZHd�d!d<œ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è  Zperiodarrayc                 C  s
   t | tƒS rE   )Ú
isinstancer+   )ÚxrM   rM   rN   Ú<lambda>»   s   ÿzPeriodArray.<lambda>)r   ztype[Period]©Úreturnc                 C  s   t S rE   )r"   ©rI   rM   rM   rN   Ú_scalar_typeÀ   s    zPeriodArray._scalar_typez	list[str]Ú
_other_opsÚis_leap_yearÚ	_bool_ops)Ú
start_timeZ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+   Ú_dtypeNFzDtype | NoneÚboolÚNone)rF   ÚcopyrX   c                 C  s  |d ur,t jdttƒ d� t||ƒ}t|ƒ}|d urVt|ƒ}t|tƒsVtd|› d�ƒ‚t|t	ƒr~|j
}t|t| ƒƒsŽtdƒ‚nt|tƒrŽ|j
}t|t| ƒƒrÈ|d urº||jkrºt||jƒ‚|j|j }}|sÜt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©rF   ©rF   r{   z-dtype is not specified and cannot be inferred)ÚwarningsÚwarnÚFutureWarningr'   Úvalidate_dtype_freqr+   r)   rT   Ú
ValueErrorr.   Ú_valuesÚtypeÚ	TypeErrorr-   rF   Úraise_on_incompatibler_   Ú_ndarrayÚnpÚasarrayÚarrayr	   r   Ú__init__)rI   ÚvaluesrF   r_   r{   rM   rM   rN   rŽ   ã   s:    ü





zPeriodArray.__init__znpt.NDArray[np.int64]r9   )r�   rF   rX   c                 C  s.   d}t |tjƒr|jdks"J |ƒ‚| ||d�S )Nz Should be numpy array of type i8Úi8r   )rT   r‹   ÚndarrayrF   )Úclsr�   rF   Zassertion_msgrM   rM   rN   Ú_simple_new  s    zPeriodArray._simple_newr€   c                C  sŒ   |d urt |ƒ}|r&t|tƒr&|j}nd }t|| ƒrPt|j|ƒ |rL| ¡ }|S tj|t	d�}|pjt
 |¡}t
 ||¡}t|ƒ}| ||d�S )Nr   )r)   rT   r+   r_   r„   rF   r{   r‹   rŒ   ÚobjectÚ	libperiodÚextract_freqZextract_ordinals)r’   ZscalarsrF   r{   r_   ÚperiodsÚordinalsrM   rM   rN   Ú_from_sequence  s    
zPeriodArray._from_sequencec                C  s   | j |||d�S )Nr€   )r™   )r’   ÚstringsrF   r{   rM   rM   rN   Ú_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   )rT   r   r   ÚnrC   r   r+   )r’   Údatar_   ÚtzrF   rM   rM   rN   Ú_from_datetime64:  s
    
zPeriodArray._from_datetime64c                 C  sP   t  |¡}|d urt |¡}|d us,|d ur@t||||ƒ\}}ntdƒ‚||fS )Nz/Not enough parameters to construct Period range)ÚdtlZvalidate_periodsr"   Ú_maybe_convert_freqÚ_get_ordinal_ranger…   )r’   ÚstartÚendr—   r_   ÚsubarrrM   rM   rN   Ú_generate_rangeO  s    

zPeriodArray._generate_rangeÚdict)ÚfieldsrX   c                C  s,   t f d|i|¤Ž\}}t|ƒ}| j||d�S )Nr_   r   )Ú_range_from_fieldsr+   r“   )r’   r¨   r_   r¥   rF   rM   rM   rN   Ú_from_fields]  s    zPeriodArray._from_fieldszPeriod | NaTTypeznp.int64)ÚvaluerX   c                 C  sJ   |t u rt |j¡S t|| jƒr6|  |¡ t |j¡S td|› d�ƒ‚d S )Nz!'value' should be a Period. Got 'z
' instead.)	r   r‹   r~   Ú_valuerT   rZ   Ú_check_compatible_withÚordinalr…   ©rI   r«   rM   rM   rN   Ú_unbox_scalari  s    
zPeriodArray._unbox_scalarrB   r"   c                 C  s   t || jd�S )N)r_   )r"   r_   r¯   rM   rM   rN   Ú_scalar_from_stringv  s    zPeriodArray._scalar_from_stringzPeriod | NaTType | PeriodArray)ÚotherrX   c                 C  s   |t u rd S |  |j¡ d S rE   )r   Ú_require_matching_freqr_   ©rI   r²   rM   rM   rN   r­   |  s    z"PeriodArray._check_compatible_withc                 C  s   | j S rE   )rx   rY   rM   rM   rN   rF   †  s    zPeriodArray.dtyper   c                 C  s   | j jS )zC
        Return the frequency object for this PeriodArray.
        ©rF   r_   rY   rM   rM   rN   r_   ‹  s    zPeriodArray.freqc                 C  s   t | jj| jjƒS rE   )r   r_   rœ   rC   rY   rM   rM   rN   Úfreqstr’  s    zPeriodArray.freqstrzNpDtype | Nonezbool | Nonez
np.ndarrayc                 C  sh   |dkr,|st j| j|d�S t j| j|d�S |du rFtjdttƒ d� |tkrV| j	 S t jt
| ƒtd�S )Nr�   r   FaS  Starting with NumPy 2.0, the behavior of the 'copy' keyword has changed and passing 'copy=False' raises an error when returning a zero-copy NumPy array is not possible. pandas will follow this behavior starting with pandas 3.0.
This conversion to NumPy requires a copy, but 'copy=False' was passed. Consider using 'np.asarray(..)' instead.r|   )r‹   rŒ   rH   r�   r�   r‚   rƒ   r'   ry   Ú_isnanÚlistr”   )rI   rF   r{   rM   rM   rN   Ú	__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||ƒrp| j	|j
kr€t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~   )ÚpyarrowZ(pandas.core.arrays.arrow.extension_typesrº   ÚtypesÚ
is_integerr�   rŠ   r0   rT   r¶   r_   rˆ   r=   Zfrom_storage)rI   r‡   r½   rº   Zperiod_typeZstorage_arrayrM   rM   rN   Ú__arrow_array__³  s(    
ÿÿÿ
ÿ
zPeriodArray.__arrow_array__ra   z×
        The year of the period.

        Examples
        --------
        >>> idx = pd.PeriodIndex(["2023", "2024", "2025"], freq="Y")
        >>> idx.year
        Index([2023, 2024, 2025], dtype='int64')
        rb   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')
        rc   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')
        rd   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')
        re   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')
        rf   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')
        ri   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')
        rk   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')
        rm   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')
        rn   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')
        ro   rp   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')
        z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Œ   ra   rY   rM   rM   rN   r\   t  s    zPeriodArray.is_leap_yearr£   r;   )ÚhowrX   c                 C  sD  ddl m} t |¡}|dk}|rx|dks4| jdkrXtddƒtddƒ }| jdd	�| S tddƒ}| | j jdd	�| S |d
u r | j ¡ }t	|dƒ}|j
}|}nt |¡}|j}| j||d	�}	t |	j|¡}
| |
¡}| jjdk�r6t | j¡}t|ƒdk�r2|d }|| jjk�r| j|_n|dk�r2| jj|_|S | d¡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Á   NZinfer)Úpandas.core.arraysr;   r•   Úvalidate_end_aliasr_   r   ru   rx   Z_get_to_timestamp_baser   Ú_freqstrr"   r¡   Ú_period_dtype_coderv   Zperiodarr_to_dt64arrrH   r™   rC   ÚlibalgosZunique_deltasÚlenrF   Ú_nZ_freqrJ   Z
_with_freq)rI   r_   rÁ   r;   r¤   ÚadjustZ	freq_coderF   rJ   Znew_parrÚnew_dataÚdtaZdiffsÚdiffrM   rM   rN   ru   �  s:    








zPeriodArray.to_timestampc                 C  s   t j|| jd�S )N)r®   r_   )r"   Z_from_ordinalr_   )rI   rU   rM   rM   rN   Ú	_box_funcÅ  s    zPeriodArray._box_funcZPeriodIndex)r²   Z
other_namerÂ   c           
      C  sž   t  |¡}t|tƒr(t|dƒr(t|ƒj}t |¡}| j	j
}|j}| j}|dk}|rd|| jj d }n|}t||||ƒ}| jr†t|| 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È   rT   r   Úhasattrr+   rÉ   r"   r¡   rx   rG   rÊ   rH   rF   rÍ   r$   Z_hasnar   r·   r‡   )
rI   r_   rÁ   Zbase1Zbase2rH   r¤   r®   rÏ   rF   rM   rM   rN   rv   È  s     .



zPeriodArray.asfreq)Úboxedc                 C  s   |rt S djS )Nz'{}')rB   Úformat)rI   rÔ   rM   rM   rN   Ú
_formatter  s    zPeriodArray._formatterr   )Úna_repÚdate_formatzstr | floatznpt.NDArray[np.object_])r×   rX   c                K  s   t  | j| jj||¡S )z3
        actually format my specific types
        )r•   Zperiod_array_strftimerH   rF   rG   )rI   r×   rØ   ÚkwargsrM   rM   rN   Ú_format_native_types  s    ÿz PeriodArray._format_native_typesT©r{   c                   sˆ   t |ƒ}|| jkr"|s| S |  ¡ S t|tƒr8|  |j¡S t |d¡sNt|t	ƒrxt
|dd ƒ}t |¡}|  ¡  |¡ |¡S tƒ j||d�S )NÚMrž   rÛ   )r)   rx   r{   rT   r+   rv   r_   r   Úis_np_dtyper*   Úgetattrr    Zdtype_to_unitru   Ztz_localizeZas_unitÚsuperÚastype)rI   rF   r{   rž   Úunit©Ú	__class__rM   rN   rà   "  s    


zPeriodArray.astypeÚleftz$NumpyValueArrayLike | ExtensionArrayzLiteral['left', 'right']zNumpySorter | Noneznpt.NDArray[np.intp] | np.intp)r«   ÚsideÚsorterrX   c                 C  s,   |   |¡ d¡}| j d¡}|j|||d�S )NúM8[ns])rå   ræ   )Z_validate_setitem_valueÚviewrŠ   Úsearchsorted)rI   r«   rå   ræ   ZnpvalueZm8arrrM   rM   rN   ré   6  s    zPeriodArray.searchsorted)ÚlimitÚ
limit_arear{   r5   z
int | Nonez#Literal['inside', 'outside'] | None)Úmethodrê   rë   r{   rX   c                C  s:   |   d¡}|j||||d�}|r2td|  | j¡ƒS | S d S )Nrç   )rì   rê   rë   r{   r9   )rè   Ú_pad_or_backfillr	   rF   )rI   rì   rê   rë   r{   rÐ   rK   rM   rM   rN   rí   C  s    

ÿzPeriodArray._pad_or_backfill)rê   r{   rX   c                   sD   |d ur0|   d¡}|j||||d�}|  | j¡S tƒ j||||d�S )Nrç   )r«   rì   rê   r{   )rè   ÚfillnarF   rß   )rI   r«   rì   rê   r{   rÐ   rK   râ   rM   rN   rî   V  s
    
zPeriodArray.fillnaznp.ndarray | intzCallable[[Any, Any], Any])r²   ÚoprX   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   rH   r‹   rŒ   r‡   rF   )rI   r²   rï   Ú
res_valuesrM   rM   rN   Ú_addsub_int_array_or_scalarf  s
    
z'PeriodArray._addsub_int_array_or_scalar)r²   c                 C  s,   t |tƒrJ ‚| j|dd� |  |jtj¡S )NT)rJ   )rT   r   r³   rô   rœ   rð   rñ   r´   rM   rM   rN   Ú_add_offset{  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
        )rT   r_   r   r‰   r0   rß   Ú_add_timedeltalike_scalarr‹   rŒ   r   Úasm8Ú_add_timedelta_arraylike)rI   r²   Útdrâ   rM   rN   rö   ‚  s    

z%PeriodArray._add_timedeltalike_scalarz,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yx } ztdƒ|‚W Y d}~n
d}~0 0 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©rF   r{   Z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ó   rM   rM   rN   rø   —  s"    

ÿÿ
ÿýz$PeriodArray._add_timedelta_arraylikec              
   C  s¬   | j  ¡ sJ ‚t  d| j j› d�¡}t|ttjtfƒrHt t	|ƒj
¡}n
t |¡}zt||ddd�}W n0 ty– } zt| |ƒ|‚W Y d}~n
d}~0 0 | 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ú   rû   Frü   Nr�   )rF   rý   r‹   rþ   rT   r   Ztimedelta64r   rŒ   r   r÷   r   r…   r‰   rè   r   Zitem_from_zerodim)rI   r²   rF   rù   rÿ   r   rM   rM   rN   Ú _check_timedeltalike_freq_compat¼  s    
"
z,PeriodArray._check_timedeltalike_freq_compat)NNF)N)NN)N)Nr£   )NrÂ   )F)T)rä   N)NNNT)LrP   Ú
__module__Ú__qualname__rQ   Z__array_priority__Z_typr‹   r~   r   Z_internal_fill_valuer"   Z_recognized_scalarsZ_is_recognized_dtypeZ_infer_matchesrR   rZ   r[   Ú__annotations__r]   r`   rr   rs   rw   rŽ   Úclassmethodr“   r™   r›   rŸ   r¦   rª   r°   r±   r­   r%   rF   r_   r¶   r¹   rÀ   rS   ra   rb   rc   rd   re   rf   rg   ri   rk   rj   rh   rl   rm   rn   ro   rp   rq   r\   ru   rÒ   r&   Ú_shared_doc_kwargsrv   rÖ   rÚ   rà   ré   rí   rî   rô   rõ   rö   rø   r  Ú__classcell__rM   rM   râ   rN   rA   y   sì   
=
 ÿ*
ûÿ

 ÿ
þþþþþþþþþþþDHÿ  üú ÿ%r!   rW   c                 C  sŽ   t |tjtfƒs|du rd}n@t |tƒr8t|j|jƒ}n&t |tt	t
fƒrP|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)rT   r‹   r‘   r/   r   r   rœ   rC   r-   rA   r"   r¶   r   r   r_   r    rÕ   r‡   rP   r!   )rä   Úrightr	  r  ÚmsgrM   rM   rN   r‰   â  s    
ÿr‰   Fz,Sequence[Period | str | None] | AnyArrayLikezstr | Tick | BaseOffset | Nonery   )r�   r_   r{   rX   c           	      C  s  t | ddƒ}t |d¡r$t | |¡S t|tƒrZt| ƒ}|durV||jkrL|S | |¡S |S t| t	j
tttfƒsvt| ƒ} t	 | ¡}|rŽt|ƒ}nd}|jjdkr²t|ƒdkr²tdƒ‚|jjdv ræ|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]
    rF   NrÜ   rO   r   z9PeriodIndex does not allow floating point in constructionÚiuFrÛ   r   )rÞ   r   rÝ   rA   rŸ   rT   r+   r_   rv   r‹   r‘   r¸   Útupler.   rŒ   rF   ÚkindrÌ   rˆ   rà   r~   r•   Zfrom_ordinalsr(   r–   r™   )	r�   r_   r{   Z
data_dtypeÚoutZarrdatarF   Zarrr˜   rM   rM   rN   Úperiod_array  s6    :






r  )r_   rX   c                 C  s   d S rE   rM   rµ   rM   rM   rN   r„   i  s    r„   ztimedelta | str | Noner   c                 C  s   d S rE   rM   rµ   rM   rM   rN   r„   n  s    z1BaseOffsetT | BaseOffset | timedelta | str | Nonec                 C  s\   |durt |dd�}| durXt| ƒ} t| tƒs6tdƒ‚|du rF| j}n|| jkrXt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©Z	is_periodzdtype must be PeriodDtypez&specified freq and dtype are different)r   r)   rT   r+   r…   r_   r!   rµ   rM   rM   rN   r„   s  s    

z(tuple[npt.NDArray[np.int64], BaseOffset]c                 C  s°   t | jtjƒr| jjdkr*td| j› �ƒ‚|du rht | tƒrL| j| j } }q|t | tƒr|| 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)rT   rF   r‹   r  r…   r,   r†   r_   r.   Údtr   r"   r¡   rÊ   Úc_dt64arr_to_periodarrrè   )r�   r_   rž   r  rJ   rM   rM   rN   r   ˜  s    



r   rÄ   Úint)Úmultc                 C  sR  t  | ||¡dkrtdƒ‚|d ur4t|dd�}|j}| d urFt| |ƒ} |d urXt||ƒ}t| tƒ}t|tƒ}|rˆ|rˆ| j|jkrˆtdƒ‚| tu s˜|tu r tdƒ‚|d u rÎ|r´| j}n|rÀ|j}ntdƒ‚|j}|d u�r.|| }| d u �rt	j
|j| | |jd |t	jd	�}nt	j
| j| j| |t	jd	�}nt	j
| j|jd |t	jd	�}||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   )ÚcomZcount_not_noner…   r   rœ   r"   rT   r_   r   r‹   Zaranger®   r~   )r£   r¤   r—   r_   r  Zis_start_perZ
is_end_perr�   rM   rM   rN   r¢   À  sF    ÿ





ÿÿr¢   ztuple[np.ndarray, BaseOffset]c                 C  s\  |d u rd}|d u rd}|d u r$d}|d u r0d}g }|d urä|d u rZt ddd�}tjj}	n*t |dd�}t |¡}	|	tjjkr„tdƒ‚|j}
t| |ƒ\} }t	| |ƒD ]>\}}t
 |||
¡\}}t ||dddddd|	¡	}| |¡ q¢ndt |dd�}t |¡}	t| |||||ƒ}t	|Ž D ]2\}}}}}}| t ||||||dd|	¡	¡ �qtj|tjd�|fS )Nr   rÄ   ÚQTr  zbase must equal FR_QTRr   )r   r   ZFR_QTRr«   r•   Zfreq_to_dtype_codeÚAssertionErrorr¶   Ú_make_field_arraysÚzipr   Zquarter_to_myearZperiod_ordinalÚappendr‹   r�   r~   )ra   rb   rn   rc   rd   re   rf   r_   r˜   rJ   r¶   ÚyÚqZcalendar_yearZcalendar_monthÚvalZarraysZmthÚdÚhZmnÚsrM   rM   rN   r©   ñ  s>    


ÿ
$r©   zlist[np.ndarray]c                    s^   d ‰ | D ]B}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 rM   )rT   r‹   r‘   r¸   r.   rŒ   Úrepeat)Ú.0rU   ©ÚlengthrM   rN   Ú
<listcomp>.  s   þÿz&_make_field_arrays.<locals>.<listcomp>)rT   r¸   r‹   r‘   r.   rÌ   r…   )r¨   rU   rM   r&  rN   r  "  s    

ür  )N)NF)N)rÄ   )NNNNNNNN)hÚ
__future__r   Údatetimer   rð   Útypingr   r   r   r   r   r	   r
   r�   Únumpyr‹   Zpandas._libsr   rË   r   Zpandas._libs.arraysr   Zpandas._libs.tslibsr   r   r   r   r   r   r   r  r   r   r   r   r•   r   Zpandas._libs.tslibs.dtypesr   r   r   Zpandas._libs.tslibs.fieldsr   Zpandas._libs.tslibs.offsetsr   r   Zpandas._libs.tslibs.periodr    r!   r"   r#   r$   Zpandas.util._decoratorsr%   r&   Zpandas.util._exceptionsr'   Zpandas.core.dtypes.commonr(   r)   Zpandas.core.dtypes.dtypesr*   r+   Zpandas.core.dtypes.genericr,   r-   r.   r/   Zpandas.core.dtypes.missingr0   rÇ   r1   r    Zpandas.core.commonÚcoreÚcommonr  Úcollections.abcr2   Zpandas._typingr3   r4   r5   r6   r7   r8   r9   r:   r;   r<   Zpandas.core.arrays.baser=   r>   r  rS   ZDatelikeOpsZPeriodMixinrA   r‰   r  r„   r¢   r©   r  rM   rM   rM   rN   Ú<module>   st   $	8(ÿ      o&  ýc& ÿ(2        ø1