o
    5c                     @  sv  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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" d dl#m$Z$ d d	l%m&Z& d d
l'm(Z(m)Z) d dl*m+Z+m,Z,m-Z-m.Z.m/Z/ d dl0m1Z1m2Z2m3Z3m4Z4 d dl5m6Z6m7Z7 d dl8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@ d dlAmBZB d dlCmDZDmEZEmFZFmGZG d dlHmIZI d dlJmK  mLZ d dlMmNZO d dlPmK  mQZR erd dl0mSZSmTZT d dlMmUZUmVZV d dlWmXZX ededZYddiZZd>d?ddZ[G dd deOj\e!j]Z^dd  Z_		!d@dAd)d*Z`edBd+d,ZaedCd/d,ZadDd1d,Za	d>dEd3d4ZdFd6d7Zb								dGdHd9d:ZcdId<d=ZddS )J    )annotations)	timedeltaN)TYPE_CHECKINGAnyCallableLiteralSequenceTypeVaroverload)algoslib)NDArrayBacked)
BaseOffsetNaTNaTType	Timedeltaastype_overflowsafedt64arr_to_periodarrget_unit_from_dtypeiNaTparsingperiod	to_offset)	FreqGroup)isleapyear_arr)Tickdelta_to_tick)DIFFERENT_FREQIncompatibleFrequencyPeriodget_period_field_arrperiod_asfreq_arr)AnyArrayLikeDtypeNpDtypenpt)cache_readonlydoc)ensure_objectis_datetime64_any_dtypeis_datetime64_dtypeis_dtype_equalis_float_dtypeis_integer_dtypeis_period_dtypepandas_dtype)PeriodDtype)ABCIndexABCPeriodIndex	ABCSeriesABCTimedeltaArray)isna)datetimelike)NumpySorterNumpyValueArrayLike)DatetimeArrayTimedeltaArray)ExtensionArrayBaseOffsetT)boundklassPeriodArraynamestrc                   s     fdd} |_ ||_t|S )Nc                   s   | j j}t | j|}|S N)freq_period_dtype_coder    asi8)selfbaseresultr@    O/var/www/html/gps/gps/lib/python3.10/site-packages/pandas/core/arrays/period.pyfi   s   z_field_accessor.<locals>.f)__name____doc__property)r@   	docstringrL   rJ   rI   rK   _field_accessorh   s   rQ   c                      s  e Zd ZU dZdZdZeeZ	e
fZeZdZedd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< 	ddddZe		ddd#d$Zeddd%dd*d+Zeddd%dd,d-Zeddd.d/Zed0d1 Z	ddd6d7Zdd:d;Z ddd<d=Z!e"dd>d?Z#eddAdBZ$dddDdEZ%ddFdGZ&e'dHdIZ(e'dJdKZ)e'dLdMZ*e'dNdOZ+e'dPdQZ,e'dRdSZ-e'dTdUZ.e.Z/e'dVdWZ0e0Z1e1Z2e'dXdY Z3Z4e'dZd[Z5e'd\Z6e'd]d^Z7e7Z8edd_d`Z9dddddeZ:dddhdiZ;ddjdkZ<e=di e>dldldmdddodpZ?dddrdsZ@eAjBdtdduddwdxZCdd fdzd{ZD	|	ddddZEdd fddZFdddZGdddZHdddZI fddZJdddZKdd ZL  ZMS )r?   a)  
    Pandas ExtensionArray for storing Period data.

    Users should use :func:`~pandas.period_array` to create new instances.
    Alternatively, :func:`~pandas.array` can be used to create new instances
    from a sequence of Period scalars.

    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`.
    i  periodarray)r   returntype[Period]c                 C  s   t S rB   )r   rF   rJ   rJ   rK   _scalar_type      zPeriodArray._scalar_typez	list[str]
_other_opsis_leap_year	_bool_ops)
start_timeend_timerC   _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_methodsr0   _dtypeNFdtypeDtype | NonecopyboolNonec                 C  s   t ||}|d urt|}t|tr"|j}t|t| s!tdnt|tr*|j}t|t| rF|d ur?||j	kr?t
|||j|j	}}tj|d|d}|d u rVtdt| |t| d S )NzIncorrect dtypeint64rv   rx   z,freq is not specified and cannot be inferred)validate_dtype_freqr   _maybe_convert_freq
isinstancer3   _valuestype	TypeErrorr2   rC   raise_on_incompatible_ndarraynparray
ValueErrorr   __init__r0   )rF   valuesrv   rC   rx   rJ   rJ   rK   r      s$   




zPeriodArray.__init__r   
np.ndarrayrC   BaseOffset | Nonec                 C  s0   d}t |tjr|jdksJ || |||dS )Nz Should be numpy array of type i8i8)rC   rv   )r   r   ndarrayrv   )clsr   rC   rv   assertion_msgrJ   rJ   rK   _simple_new   s   zPeriodArray._simple_newr|   r   type[PeriodArray]scalars&Sequence[Period | None] | AnyArrayLikec                C  st   |rt |tr|j}nd }t || r t|j| |r| }|S tj|td}|p-t	
|}t	||}| ||dS )Nrv   rC   )r   r0   rC   r}   rv   rx   r   asarrayobject	libperiodextract_freqextract_ordinals)r   r   rv   rx   rC   periodsordinalsrJ   rJ   rK   _from_sequence   s   
zPeriodArray._from_sequencec                C  s   | j |||dS )Nr|   )r   )r   stringsrv   rx   rJ   rJ   rK   _from_sequence_of_strings  s   z%PeriodArray._from_sequence_of_stringsc                 C  s   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   )r   )r   datarC   tzrJ   rJ   rK   _from_datetime64  s   zPeriodArray._from_datetime64c                 C  s   t |}|d urt|}t|}|d us|d ur/|dkr"tdt||||\}}||fS |dkrBtdd|i|\}}||fS td)Nr   z=Can either instantiate from fields or endpoints, but not bothrC   z/Not enough parameters to construct Period rangerJ   )dtlvalidate_periodsr   r~   lenr   _get_ordinal_range_range_from_fields)r   startendr   rC   fieldsfield_countsubarrrJ   rJ   rK   _generate_range-  s   

zPeriodArray._generate_rangevaluePeriod | NaTTypesetitemnp.int64c                 C  sJ   |t u r
t|jS t|| jr| j||d t|jS td| d)N)r   z!'value' should be a Period. Got 'z
' instead.)	r   r   r{   r   r   rV   _check_compatible_withordinalr   )rF   r   r   rJ   rJ   rK   _unbox_scalarH  s   zPeriodArray._unbox_scalarrA   r   c                 C  s   t || jdS )Nr   )r   rC   )rF   r   rJ   rJ   rK   _scalar_from_stringV  s   zPeriodArray._scalar_from_stringc                 C  s   |t u rd S | | d S rB   )r   _require_matching_freq)rF   otherr   rJ   rJ   rK   r   Y  s   z"PeriodArray._check_compatible_withc                 C  s   | j S rB   )ru   rU   rJ   rJ   rK   rv   a  s   zPeriodArray.dtyper   c                 C  s   | j jS )zC
        Return the frequency object for this PeriodArray.
        rv   rC   rU   rJ   rJ   rK   rC   f  s   zPeriodArray.freqNpDtype | Nonec                 C  s0   |dkr| j S |tkr| j S tjt| tdS )Nr   r   )rE   ry   _isnanr   r   listr   )rF   rv   rJ   rJ   rK   	__array__m  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   r5   r   freqstrrC   r   r;   from_storage)rF   r   r   r   period_typestorage_arrayrJ   rJ   rK   __arrow_array__v  s*   


zPeriodArray.__arrow_array__r^   z)
        The year of the period.
        r_   z6
        The month as January=1, December=12.
        r`   z)
        The days of the period.
        ra   z)
        The hour of the period.
        rb   z+
        The minute of the period.
        rc   z+
        The second of the period.
        rf   z/
        The week ordinal of the year.
        rh   z>
        The day of the week with Monday=0, Sunday=6.
        rj   z.
        The ordinal day of the year.
        rk   z*
        The quarter of the date.
        rl   rm   z2
        The number of days in the month.
        c                 C  s   t t| jS )zH
        Logical indicating if the date belongs to a leap year.
        )r   r   r   r^   rU   rJ   rJ   rK   rY     s   zPeriodArray.is_leap_yearr   howr9   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 rH| j }|}nt	
|}|j}| j||d	}t|j|}||}	| jjdkrt| 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
        r   )r9   EB   Dnsr   )r   Ninfer)pandas.core.arraysr9   r   validate_end_aliasrC   r   rr   ru   _get_to_timestamp_baser   r~   rD   rs   periodarr_to_dt64arrrE   r@   libalgosunique_deltasr   n_freqrG   
_with_freq)rF   rC   r   r9   r   adjustrG   new_parrnew_datadtadiffsdiffrJ   rJ   rK   rr     s8   





zPeriodArray.to_timestampr   intc                 C  s&   |durt dt| j d| | S )a  
        Shift each value by `periods`.

        Note this is different from ExtensionArray.shift, which
        shifts the *position* of each element, padding the end with
        missing values.

        Parameters
        ----------
        periods : int
            Number of periods to shift by.
        freq : pandas.DateOffset, pandas.Timedelta, or str
            Frequency increment to shift by.
        Nz%`freq` argument is not supported for z._time_shift)r   r   rM   )rF   r   rC   rJ   rJ   rK   _time_shift  s   zPeriodArray._time_shiftc                 C  s   t j|| jdS )N)r   rC   )r   _from_ordinalrC   )rF   xrJ   rJ   rK   	_box_func4  s   zPeriodArray._box_funcPeriodIndex)r   
other_namer   c           	      C  sx   t |}t|}| jj}|j}| j}|dk}|r#|| jj	 d }n|}t
||||}| jr4t|| j< 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='A')
        >>> pidx
        PeriodIndex(['2010', '2011', '2012', '2013', '2014', '2015'],
        dtype='period[A-DEC]')

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

        >>> pidx.asfreq('M', how='S')
        PeriodIndex(['2010-01', '2011-01', '2012-01', '2013-01', '2014-01',
        '2015-01'], dtype='period[M]')
        r   r   r   )r   r   r   r~   ru   _dtype_coderD   rE   rC   r   r!   _hasnar   r   r   )	rF   rC   r   base1base2rE   r   r   r   rJ   rJ   rK   rs   7  s   
.

zPeriodArray.asfreqboxedc                 C  s   |rt S djS )Nz'{}')rA   format)rF   r   rJ   rJ   rK   
_formatter~  s   zPeriodArray._formatterr   )na_repdate_formatnpt.NDArray[np.object_]c                  s~   |  t} r fddndd | jr1| j}|||< | }tfdd|| D ||< |S tfdd|D }|S )z3
        actually format my specific types
        c                   s
   |   S rB   )rq   per)r   rJ   rK   <lambda>  s   
 z2PeriodArray._format_native_types.<locals>.<lambda>c                 S  s   t | S rB   )rA   r   rJ   rJ   rK   r     s    c                      g | ]} |qS rJ   rJ   .0r   	formatterrJ   rK   
<listcomp>      z4PeriodArray._format_native_types.<locals>.<listcomp>c                   r   rJ   rJ   r   r   rJ   rK   r     r   )astyper   r   r   r   r   )rF   r   r   kwargsr   r   imaskrJ   )r   r   rK   _format_native_types  s   
 z PeriodArray._format_native_typesTc                   sj   t |}t|| jr|s| S |  S t|r| |jS t|r-t|dd }| 	 
|S t j||dS )Nr   rx   )r/   r+   ru   rx   r.   rs   rC   r)   getattrrr   tz_localizesuperr   )rF   rv   rx   r   	__class__rJ   rK   r     s   zPeriodArray.astypeleft$NumpyValueArrayLike | ExtensionArraysideLiteral['left', 'right']sorterr7   npt.NDArray[np.intp] | np.intpc                 C  s,   |  |d}| jd}|j|||dS )NM8[ns])r  r  )_validate_searchsorted_valueviewr   searchsorted)rF   r   r  r  npvaluem8arrrJ   rJ   rK   r    s   zPeriodArray.searchsortedc                   s@   |d ur|  d}|j|||d}| | jS t j|||dS )Nr
  )r   methodlimit)r  fillnarv   r  )rF   r   r  r  r   rH   r  rJ   rK   r    s
   
zPeriodArray.fillnarF   qsnpt.NDArray[np.float64]interpolationc                 C  s   |  d||}| | jS )Nr
  )r  	_quantilerv   )rF   r  r  dtresrJ   rJ   rK   r    s   zPeriodArray._quantiler   np.ndarray | intopCallable[[Any, Any], Any]c                 C  sJ   |t jt jfv s
J |t ju r| }tj| j|| jd}t| || jdS )a$  
        Add or subtract array of integers; equivalent to applying
        `_time_shift` pointwise.

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

        Returns
        -------
        result : PeriodArray
        )arr_maskr   )	operatoraddsubr   checked_add_with_arrrE   r   r   rC   )rF   r   r  
res_valuesrJ   rJ   rK   _addsub_int_array_or_scalar  s
   
z'PeriodArray._addsub_int_array_or_scalarc                 C  s,   t |trJ | j|dd | |jtjS )NT)rG   )r   r   r   r!  r   r  r  )rF   r   rJ   rJ   rK   _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
        )r   rC   r   r   r5   r  _add_timedeltalike_scalarr   r   r   asm8_add_timedelta_arraylike)rF   r   tdr  rJ   rK   r#    s   


z%PeriodArray._add_timedeltalike_scalar,TimedeltaArray | npt.NDArray[np.timedelta64]c              
   C  s   | j }t|tstd| j td|j d}ztt||ddd}W n t	y8 } zt
d|d}~ww t|}tj| j|d| j|d	}t|| j|B t t| || j d
S )z
        Parameters
        ----------
        other : TimedeltaArray or ndarray[timedelta64]

        Returns
        -------
        PeriodArray
        z2Cannot add or subtract timedelta64[ns] dtype from m8[]Frv   rx   round_okznCannot add/subtract timedelta-like from PeriodArray that is not an integer multiple of the PeriodArray's freq.Nr   )r  b_maskr   )rC   r   r   r   rv   r   
_td64_unitr   r   r   r   isnatr   r  rE   r  r   putmaskr   r   )rF   r   rC   rv   deltaerrr,  r   rJ   rJ   rK   r%    s0   



z$PeriodArray._add_timedelta_arraylikec              
   C  s   t | jt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yF } 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(  r)  Fr*  Nr   )r   rC   r   r   rv   r-  r   timedelta64r   r   r$  r   r   r   r  r   item_from_zerodim)rF   r   rv   r&  r0  r1  rJ   rJ   rK    _check_timedeltalike_freq_compat1  s   


z,PeriodArray._check_timedeltalike_freq_compat)rS   rT   )NNF)rv   rw   rx   ry   rS   rz   )NN)r   r   rC   r   rv   rw   rS   r?   )
r   r   r   r   rv   rw   rx   ry   rS   r?   )rv   rw   rx   ry   rS   r?   rB   )rS   r?   )F)r   r   r   ry   rS   r   )r   rA   rS   r   )r   ry   )rS   r0   )rS   r   )rv   r   rS   r   )rS   r   )Nr   )r   rA   rS   r9   )r   r   rS   r?   )rS   r   rJ   )Nr   )r   rA   rS   r?   )r   ry   )rS   r   )T)rx   ry   )r  N)r   r  r  r  r  r7   rS   r	  )NNN)rF   r?   r  r  r  rA   rS   r?   )r   r  r  r  rS   r?   )r   r   )r   r'  rS   r?   )NrM   
__module____qualname__rN   __array_priority___typr   r{   r   _internal_fill_valuer   _recognized_scalarsr.   _is_recognized_dtype_infer_matchesrO   rV   rX   __annotations__rZ   r]   ro   rp   rt   r   classmethodr   r   r   r   r   r   r   r   r&   rv   rC   r   r   rQ   r^   r_   r`   ra   rb   rc   rd   rf   rh   rg   re   ri   rj   rk   rl   rm   rn   rY   rr   r   r   r'   _shared_doc_kwargsrs   r   r   ravel_compatr   r   r  r  r  r!  r"  r#  r%  r4  __classcell__rJ   rJ   r  rK   r?   s   s   
 7



	;
F




)c                 C  sf   t |tjtfs|du rd}nt |ttttfr|j}nt	t
|j}tjt| j| 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)r   r   r   r4   r2   r?   r   r   r   r   r   r   r   r   rM   r   )r  rightrC  msgrJ   rJ   rK   r   W  s   r   Fr   ,Sequence[Period | str | None] | AnyArrayLikerC   str | Tick | Nonerx   ry   rS   c                 C  s   t | dd}t|rt| |S t|rt| |dS t| tjtt	t
fs(t| } t| }|r4t|}nd}t|rDt|dkrDtdt|jr]|jtjdd}t||}t||dS 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='A'),
    ...               pd.Period('2018', freq='A')])
    <PeriodArray>
    ['2017', '2018']
    Length: 2, dtype: period[A-DEC]

    >>> period_array([pd.Period('2017', freq='A'),
    ...               pd.Period('2018', freq='A'),
    ...               pd.NaT])
    <PeriodArray>
    ['2017', '2018', 'NaT']
    Length: 3, dtype: period[A-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]
    rv   Nr   r   z9PeriodIndex does not allow floating point in constructionFr   r   )r   r*   r?   r   r.   r   r   r   r   tupler3   r   r0   r,   r   r   r-   rv   r   r{   r   from_ordinalsr(   r   )r   rC   rx   
data_dtypearrdatarv   arrr   rJ   rJ   rK   period_arrayx  s&   :


rM  c                 C     d S rB   rJ   r   rJ   rJ   rK   r}     rW   r}   timedelta | str | Noner   c                 C  rN  rB   rJ   r   rJ   rJ   rK   r}     rW   $BaseOffsetT | timedelta | str | Nonec                 C  sX   |durt |}| dur*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
    Nzdtype must be PeriodDtypez&specified freq and dtype are different)r   r/   r.   r   rC   r   r   rJ   rJ   rK   r}     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.

    MzWrong dtype: Nr   )reso)r   rv   r   kindr   r1   r   rC   r3   dtr   r   r~   rD   c_dt64arr_to_periodarrr  )r   rC   r   rS  rG   rJ   rJ   rK   r     s   



r   r   c                 C  sP  t | ||dkrtd|d urt|}|j}| d ur!t| |} |d ur*t||}t| t}t|t}|rB|rB| j|jkrBtd| tu sJ|tu rNtd|d u rb|rX| j}n
|r^|j}ntd|d ur|| }| d u rt	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 specifiedz!start and end must have same freqzstart and end must not be NaTz#Could not infer freq from start/endr   r   )comcount_not_noner   r   r   r   r   rC   r   r   aranger   r{   )r   r   r   rC   multis_start_per
is_end_perr   rJ   rJ   rK   r   .  sH   




r   tuple[np.ndarray, BaseOffset]c                 C  sN  |d u rd}|d u rd}|d u rd}|d u rd}g }|d urn|d u r+t d}tjj}	nt |}t|}	|	tjjkr>td|j}
t| |\} }t	| |D ]\}}t
|||
\}}t||dddddd|		}|| qMn/t |}t|}	t| |||||}t	| D ]\}}}}}}|t||||||dd|		 qtj|tjd|fS )Nr   r   Qz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{   )r^   r_   rk   r`   ra   rb   rc   rC   r   rG   r   yqmvalarraysmthdhmnsrJ   rJ   rK   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 rJ   )r   r   r   r   r3   r   repeat)r   r   lengthrJ   rK   r     s    
z&_make_field_arrays.<locals>.<listcomp>)r   r   r   r   r3   r   r   )r   r   rJ   rt  rK   rc    s   
rc  rB   )r@   rA   )NF)r   rF  rC   rG  rx   ry   rS   r?   )rC   r<   rS   r<   )rC   rO  rS   r   )rC   rP  rS   r<   )rS   rQ  )r   )NNNNNNNN)rS   r^  )rS   rr  )e
__future__r   datetimer   r  typingr   r   r   r   r   r	   r
   numpyr   pandas._libsr   r   r   pandas._libs.arraysr   pandas._libs.tslibsr   r   r   r   r   r   rV  r   r   r   r   r   r   pandas._libs.tslibs.dtypesr   pandas._libs.tslibs.fieldsr   pandas._libs.tslibs.offsetsr   r   pandas._libs.tslibs.periodr   r   r   r    r!   pandas._typingr"   r#   r$   r%   pandas.util._decoratorsr&   r'   pandas.core.dtypes.commonr(   r)   r*   r+   r,   r-   r.   r/   pandas.core.dtypes.dtypesr0   pandas.core.dtypes.genericr1   r2   r3   r4   pandas.core.dtypes.missingr5   pandas.core.algorithmscore
algorithmsr   r6   r   pandas.core.commoncommonrX  r7   r8   r9   r:   pandas.core.arrays.baser;   r<   r?  rQ   DatelikeOpsPeriodMixinr?   r   rM  r}   r   r   rc  rJ   rJ   rJ   rK   <module>   sr    $
4(
     i#\
)
(1/