
    `Vg                       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lJmKc mLZ d dlMmNZO d dlPmKc mQZR erd dl0mSZSmTZT d dlMmUZUmVZV d dlWmXZX  ede      ZYddiZZd%d&dZ[ G d deOj                  e!j                        Z^d Z_	 	 d'	 	 	 	 	 	 	 d(dZ`ed)d       Zaed*d       Za	 	 	 	 d+d Za	 d%	 d,d!Zd-d"Zb	 	 	 	 	 	 	 	 d.	 d/d#Zcd0d$Zdy)1    )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PeriodArrayc                @      fd} |_         ||_        t        |      S )Nc                b    | j                   j                  }t        | j                  |      }|S N)freq_period_dtype_coder!   asi8)selfbaseresultnames      Z/var/www/html/hubwallet-dev/venv/lib/python3.12/site-packages/pandas/core/arrays/period.pyfz_field_accessor.<locals>.fi   s)    yy++%dDIIt<    )__name____doc__property)rJ   	docstringrL   s   `  rK   _field_accessorrR   h   s"    
 AJAIA;rM   c                      e Zd ZU dZdZdZ ej                  e      Z	e
fZeZdZedNd       Zg Zded<   dgZded	<   g d
Zded<   g dZded<   eez   ez   Zded<   g dZded<   ded<   	 dO	 	 	 	 	 dPdZe	 	 dQ	 	 	 	 	 	 	 dRd       Zeddd	 	 	 	 	 	 	 	 	 dSd       Zeddd	 	 	 	 	 dTd       ZedUdVd       Zed        Z	 dW	 	 	 	 	 dXdZdYdZ dWdZdZ!e"d[d       Z#ed\d        Z$dUd]d!Z%dUd"Z& e'd#d$      Z( e'd%d&      Z) e'd'd(      Z* e'd)d*      Z+ e'd+d,      Z, e'd-d.      Z- e'd/d0      Z.e.Z/ e'd1d2      Z0e0Z1e1Z2 e'd3d4      xZ3Z4 e'd5d6      Z5 e'd7      Z6 e'd8d9      Z7e7Z8ed^d:       Z9d_d`d;Z:dUdad<Z;dbd=Z< e=dci e>d>d>d?ddded@       Z?dWdfdAZ@eAj                  dBddC	 dgdD       ZCdhdi fdEZD	 	 dj	 	 	 	 	 	 	 dkdFZEdldV fdGZF	 	 	 	 	 	 	 	 dmdHZG	 	 	 	 	 	 dndIZHdodJZI fdKZJ	 	 	 	 dpdLZKdM ZL xZMS )qr@   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   c                    t         S rC   )r    rG   s    rK   _scalar_typezPeriodArray._scalar_type   s    rM   z	list[str]
_other_opsis_leap_year	_bool_ops)
start_timeend_timerD   _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_methodsr1   _dtypeNFc                   t        ||      }|t        j                  |      }t        |t              r,|j
                  }t        |t        |             s't        d      t        |t              r|j
                  }t        |t        |             r5|||j                  k7  rt        ||      |j                  |j                  }}t        j                  |d|      }|t        d      t        j                   | |t#        |             y )NzIncorrect dtypeint64dtypecopyz,freq is not specified and cannot be inferred)validate_dtype_freqr    _maybe_convert_freq
isinstancer4   _valuestype	TypeErrorr3   rD   raise_on_incompatible_ndarraynparray
ValueErrorr   __init__r1   )rG   valuesry   rD   rz   s        rK   r   zPeriodArray.__init__   s     #5$/--d3Dfi(^^Ffd4j1 122/^^Ffd4j)DFKK$7+FD99!??FKKDF&d;<KLLtV[->?rM   c                |    d}t        |t        j                        r|j                  dk(  sJ |        | |||      S )Nz Should be numpy array of type i8i8)rD   ry   )r}   r   ndarrayry   )clsr   rD   ry   assertion_msgs        rK   _simple_newzPeriodArray._simple_new   s<     ;&"**-&,,$2FUUF6E22rM   rx   c               X   |rt        |t              r|j                  }nd }t        ||       r*t        |j                  |       |r|j                         }|S t        j                  |t              }|xs t        j                  |      }t        j                  ||      } | ||      S )Nry   rD   )r}   r1   rD   r{   ry   rz   r   asarrayobject	libperiodextract_freqextract_ordinals)r   scalarsry   rz   rD   periodsordinalss          rK   _from_sequencezPeriodArray._from_sequence   s     Z{3::DDgs#t4!,,.N**WF36y--g6--gt<8$''rM   c               *    | j                  |||      S )Nrx   )r   )r   stringsry   rz   s       rK   _from_sequence_of_stringsz%PeriodArray._from_sequence_of_strings  s     !!'T!BBrM   c                6    t        |||      \  }} | ||      S )a  
        Construct a PeriodArray from a datetime64 array

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

        Returns
        -------
        PeriodArray[freq]
        r   )r   )r   datarD   tzs       rK   _from_datetime64zPeriodArray._from_datetime64  s#     *$b9
d4d##rM   c                
   t        j                  |      }|t        j                  |      }t	        |      }||%|dkD  rt        d      t        ||||      \  }}||fS |dkD  rt        dd|i|\  }}||fS t        d      )Nr   z=Can either instantiate from fields or endpoints, but not bothrD   z/Not enough parameters to construct Period range )dtlvalidate_periodsr    r|   lenr   _get_ordinal_range_range_from_fields)r   startendr   rD   fieldsfield_countsubarrs           rK   _generate_rangezPeriodArray._generate_range-  s    &&w/--d3D&kQ S  .eS'4HLFD t| 1_-B4B6BLFD t| NOOrM   c                    |t         u rt        j                  |j                        S t	        || j
                        r2| j                  ||       t        j                  |j                        S t        d| d      )N)setitemz!'value' should be a Period. Got 'z
' instead.)	r   r   rw   valuer}   rW   _check_compatible_withordinalr   )rG   r   r   s      rK   _unbox_scalarzPeriodArray._unbox_scalarH  si    
 C<88EKK((t001''w'?88EMM**@zRSSrM   c                0    t        || j                        S )Nr   )r    rD   )rG   r   s     rK   _scalar_from_stringzPeriodArray._scalar_from_stringV  s    e$)),,rM   c                8    |t         u ry | j                  |       y rC   )r   _require_matching_freq)rG   otherr   s      rK   r   z"PeriodArray._check_compatible_withY  s    C<##E*rM   c                    | j                   S rC   )ru   rV   s    rK   ry   zPeriodArray.dtypea  s    {{rM   c                .    | j                   j                  S )zC
        Return the frequency object for this PeriodArray.
        ry   rD   rV   s    rK   rD   zPeriodArray.freqf  s    
 zzrM   c                    |dk(  r| j                   S |t        k(  r| j                   S t        j                  t        |       t              S )Nr   r   )rF   bool_isnanr   r   listr   )rG   ry   s     rK   	__array__zPeriodArray.__array__m  s=    D=99d]KK< xxT
&11rM   c                   ddl }ddlm} ||j                  j	                  |      r,|j                  | j                  | j                         |      S t        ||      r?| j                  |j                  k7  r5t        d| j                   d|j                   d      t        d| d	       || j                        }|j                  | j                  | j                         d
      }|j                  j                  ||      S )z6
        Convert myself into a pyarrow Array.
        r   N)ArrowPeriodType)maskr   zENot supported to convert PeriodArray to array with different 'freq' (z vs )z)Not supported to convert PeriodArray to 'z' typerw   )pyarrow(pandas.core.arrays.arrow.extension_typesr   types
is_integerr   r   r6   r}   freqstrrD   r   r<   from_storage)rG   r   r   r   period_typestorage_arrays         rK   __arrow_array__zPeriodArray.__arrow_array__v  s     	L}}''-}}T]]4}PPD/2<<499,###'<<.TYYKqB 
  ?vVL  &dll3dmm$))+GT%%22;NNrM   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                R    t        t        j                  | j                              S )zH
        Logical indicating if the date belongs to a leap year.
        )r   r   r   r^   rV   s    rK   rY   zPeriodArray.is_leap_year  s    
 bjj344rM   c                p   ddl m} t        j                  |      }|dk(  }|rp|dk(  s| j                  dk(  r.t        dd      t        dd      z
  }| j                  d	      |z   S t        dd      }| | j                  z   j                  d	      |z
  S || j                  j                         }|}n!t        j                  |      }|j                  }| j                  ||	      }t        j                  |j                  |      } ||      }	| j                  j                  dk(  rt!        j"                  | j                        }
t%        |
      dk(  rQ|
d   }|| j                  j&                  k(  r| j                  |	_        |	S |dk(  r| j                  j*                  |	_        |	S |	j-                  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   )r:   EB   Dnsr   )howinfer)pandas.core.arraysr:   r   validate_end_aliasrD   r   rr   ru   _get_to_timestamp_baser    r|   rE   rs   periodarr_to_dt64arrrF   rJ   libalgosunique_deltasr   n_freqrH   
_with_freq)rG   rD   r   r:   r   adjustrH   new_parrnew_datadtadiffsdiffs               rK   rr   zPeriodArray.to_timestamp  s     	5**3/Sjs{dii3."1c*Yq$-??((W(5>>"1d+tyy(6676CfLL<;;557DD--d3D**D;;t;-11(--FH%99>>S  **4995E5zQQx499;;& $		CI J QY $		CIJ>>'**rM   c                T    |"t        dt        |       j                   d      | |z   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.
        z%`freq` argument is not supported for z._time_shift)r   r   rN   )rG   r   rD   s      rK   _time_shiftzPeriodArray._time_shift  s=     7:&&'|5  g~rM   c                D    t        j                  || j                        S )N)r   rD   )r    _from_ordinalrD   )rG   xs     rK   	_box_funczPeriodArray._box_func4  s    ##ADII>>rM   PeriodIndex)r   
other_namec                ~   t        j                  |      }t        j                  |      }| j                  j
                  }|j                  }| j                  }|dk(  }|r|| j                  j                  z   dz
  }n|}t        ||||      }| j                  rt        || j                  <    t        |       ||      S )a  
        Convert the {klass} to the specified frequency `freq`.

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

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

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

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

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

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

        Examples
        --------
        >>> pidx = pd.period_range('2010-01-01', '2015-01-01', freq='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_coderE   rF   rD   r   r"   _hasnar   r   r   )	rG   rD   r   base1base2rF   r   r   r   s	            rK   rs   zPeriodArray.asfreq7  s    \ **3/))$/''''yySjTYY[[(1,GG$WeUC@;;$(HT[[!tDz(..rM   c                *    |rt         S dj                  S )Nz'{}')strformat)rG   boxeds     rK   
_formatterzPeriodArray._formatter~  s    J}}rM   r   )na_repdate_formatc               P   | j                  t              }rfd}nd }| j                  rE| j                  }|||<   | }t	        j
                  ||   D cg c]
  } ||       c}      ||<   |S t	        j
                  |D cg c]
  } ||       c}      }|S c c}w c c}w )z3
        actually format my specific types
        c                &    | j                        S rC   )rq   )perr   s    rK   <lambda>z2PeriodArray._format_native_types.<locals>.<lambda>  s    CLL$= rM   c                    t        |       S rC   )r   )r   s    rK   r   z2PeriodArray._format_native_types.<locals>.<lambda>  s
    CH rM   )astyper   r   r   r   r   )	rG   r   r   kwargsr   	formatterr   imaskr   s	     `      rK   _format_native_typesz PeriodArray._format_native_types  s     V$ =I -I ;;;;D!F4LEEHHu%Nin%NOF5M  XX@#y~@AF &O@s   BB#c                J   t        |      }t        || j                        r|s| S | j                         S t	        |      r| j                  |j                        S t        |      r,t        |dd       }| j                         j                  |      S t        | 1  ||      S )Nr   rz   )r0   r,   ru   rz   r/   rs   rD   r*   getattrrr   tz_localizesuperr   )rG   ry   rz   r   	__class__s       rK   r   zPeriodArray.astype  s     U#%-yy{"5!;;uzz**"5)d+B$$&22266w~e$~//rM   c                    | j                  |      j                  d      }| j                  j                  d      }|j                  |||      S )NM8[ns])sidesorter)_validate_searchsorted_valueviewr   searchsorted)rG   r   r  r  npvaluem8arrs         rK   r  zPeriodArray.searchsorted  sM     33E:??I ""8,!!'V!DDrM   c                    |@| j                  d      }|j                  |||      }|j                  | j                        S t        |   |||      S )Nr  )r   methodlimit)r  fillnary   r  )rG   r   r  r  r   rI   r	  s         rK   r  zPeriodArray.fillna  sU    ))H%CZZeF%ZHF ;;tzz**w~E&~FFrM   c                z    | j                  d      j                  ||      }|j                  | j                        S )Nr  )r  	_quantilery   )rG   qsinterpolationdtress       rK   r  zPeriodArray._quantile  s4     		(#--b-@ zz$**%%rM   c                   |t         j                  t         j                  fv sJ |t         j                  u r| }t        j                  | j
                  || j                        } t        |       || j                        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_arrrF   r   r   rD   )rG   r   op
res_valuess       rK   _addsub_int_array_or_scalarz'PeriodArray._addsub_int_array_or_scalar  se      hllHLL1111FE//		54;;W
tDz*49955rM   c                    t        |t              rJ | j                  |d       | j                  |j                  t
        j                        S )NT)rH   )r}   r   r   r$  r   r  r  )rG   r   s     rK   _add_offsetzPeriodArray._add_offset  s@    eT***##E#5//FFrM   c                    t        | j                  t              st        | |      t	        |      rt
        |   |      S t        j                  t        |      j                        }| j                  |      S )z
        Parameters
        ----------
        other : timedelta, Tick, np.timedelta64

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

        Returns
        -------
        PeriodArray
        z2Cannot add or subtract timedelta64[ns] dtype from m8[]Fry   rz   round_okznCannot add/subtract timedelta-like from PeriodArray that is not an integer multiple of the PeriodArray's freq.Nr   )r  b_maskr   )rD   r}   r   r   ry   r   
_td64_unitr   r   r   r   isnatr   r!  rF   r  r   putmaskr   r   )rG   r   rD   ry   deltaerrr1  r#  s           rK   r*  z$PeriodArray._add_timedelta_arraylike  s    yy$%DTZZLQ  3t/q12
	'

5!UUE %//IIuzz$'$++f

 	

:t{{V3T:tDz*49955  	 (E 	s   "D 	D+D&&D+c                   t        | j                  t              sJ t        j                  d| j                  j
                   d      }t        |t        t        j                  t        f      r)t        j                  t        |      j                        }nt        j                  |      }	 t        ||dd      }|j                  d      }t        j                   |      S # t        $ r}t        | |      |d}~ww xY w)a<  
        Arithmetic operations with timedelta-like scalars or array `other`
        are only valid if `other` is an integer multiple of `self.freq`.
        If the operation is valid, find that integer multiple.  Otherwise,
        raise because the operation is invalid.

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

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

        Raises
        ------
        IncompatibleFrequency
        r-  r.  Fr/  Nr   )r}   rD   r   r   ry   r2  r   timedelta64r   r   r)  r   r   r   r  r   item_from_zerodim)rG   r   ry   r+  r5  r6  s         rK    _check_timedeltalike_freq_compatz,PeriodArray._check_timedeltalike_freq_compat1  s    ( $))T***3tyy334A67ei>?Ie,112BE"B	>'%eeTE 

4 $$U++	  	>'e4#=	>s   .C# #	C>,C99C>)returnztype[Period])NNF)ry   Dtype | Nonerz   r   r;  None)NN)r   
np.ndarrayrD   zBaseOffset | Nonery   r<  r;  r@   )
r   ztype[PeriodArray]r   z&Sequence[Period | None] | AnyArrayLikery   r<  rz   r   r;  r@   )ry   r<  rz   r   r;  r@   rC   )r;  r@   )F)r   Period | NaTTyper   r   r;  znp.int64)r   r   r;  r    )r   r   )r;  r1   )r;  r   )ry   zNpDtype | Noner;  r>  )r;  r>  )Nr   )r   r   r;  r:   )r   intr;  r@   )r;  r?  r   )Nr   )r   r   r;  r@   )r   r   )r;  znpt.NDArray[np.object_])T)rz   r   )leftN)r   z$NumpyValueArrayLike | ExtensionArrayr  zLiteral['left', 'right']r  r8   r;  znpt.NDArray[np.intp] | np.intp)NNN)rG   r@   r  znpt.NDArray[np.float64]r  r   r;  r@   )r   znp.ndarray | intr"  zCallable[[Any, Any], Any]r;  r@   )r   r   )r   z,TimedeltaArray | npt.NDArray[np.timedelta64]r;  r@   )NrN   
__module____qualname__rO   __array_priority___typr   rw   r   _internal_fill_valuer    _recognized_scalarsr/   _is_recognized_dtype_infer_matchesrP   rW   rX   __annotations__rZ   r]   ro   rp   rt   r   classmethodr   r   r   r   r   r   r   r   r'   ry   rD   r   r   rR   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*  r:  __classcell__)r	  s   @rK   r@   r@   s   sE   4n D#288D>!)* N  J	*+Iy+?K?J	 & $.#;i#GyG'M9M KP@)@CG@	@6  #'"		3	3  	3 		3
 
	3 	3 
 #((7( 	(
 ( 
( (0 /3%C ,C;?C	C C
 $ $"  : TT T 
	T-+    2O< 	D 	E 	C 	D 	F 	F !	J D!	K IG-	 I 	G G$E#	M  K5 57+v,? 	MM]}MA/ NA/L
 	4	  60, *0"	
E3
E '
E 	
E
 
(
EG	&	&#	& 	& 
		&6%6+D6	6,G1*'6A'6	'6R#,rM   c                b   t        |t        j                  t        f      s|d}nKt        |t        t
        t        t        f      r|j                  }nt        t        |            j                  }t        j                  t        |       j                  | j                  |      }t        |      S )a>  
    Helper function to render a consistent error message when raising
    IncompatibleFrequency.

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

    Returns
    -------
    IncompatibleFrequency
        Exception to be raised by the caller.
    N)r   own_freq
other_freq)r}   r   r   r5   r3   r@   r    r   r   r   r   r   r   r   rN   r   )rA  rightrQ  msgs       rK   r   r   W  s      %"**&789U]
	ENKL	M]]
"9U#34<<



J$,,:C !%%rM   c                   t        | dd      }t        |      rt        j                  | |      S t	        |      rt        | |      S t        | t        j                  t        t        t        f      st        |       } t        j                  |       }|rt        |      }nd}t        |      rt        |      dkD  rt        d      t!        |j"                        rD|j%                  t        j&                  d      }t)        j*                  ||      }t        ||      S t-        |      } t        j/                  | |      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]
    ry   Nr   r   z9PeriodIndex does not allow floating point in constructionFr  r   )r  r+   r@   r   r/   r}   r   r   r   tupler4   r   r1   r-   r   r   r.   ry   r   rw   r   from_ordinalsr)   r   )r   rD   rz   
data_dtypearrdatary   arrr   s           rK   period_arrayrZ  x  s	   t w-J:&++D$77z"4d++ dRZZui@ADzjjG D!g3w<!#3STT&nnRXXEn2 **358511!D%%d%%88rM   c                     y rC   r   r   s     rK   r{   r{         rM   c                     y rC   r   r   s     rK   r{   r{     r\  rM   c                    |t        |      }| Kt        |       } t        |       st        d      || j                  }|S || j                  k7  rt        d      |S )at  
    If both a dtype and a freq are available, ensure they match.  If only
    dtype is available, extract the implied freq.

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

    Returns
    -------
    freq : DateOffset

    Raises
    ------
    ValueError : non-period dtype
    IncompatibleFrequency : mismatch between dtype and freq
    zdtype must be PeriodDtypez&specified freq and dtype are different)r   r0   r/   r   rD   r   r   s     rK   r{   r{     so    *  U#u%899<::D
 K	 UZZ'(PQQ KrM   c                X   t        | j                  t        j                        r| j                  j                  dk7  rt	        d| j                         |\t        | t
              r| j                  | j                  }} nUt        | t              rE| j                  | j                  j                  }} n"t        | t
        t        f      r| j                  } t        | j                        }t        j                  |      }|j                  }t        | j                  d      |||      |fS )a  
    Convert an datetime-like array to values Period ordinals.

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

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

    MzWrong dtype: r   )reso)r}   ry   r   kindr   r2   r~   rD   r4   dtr   r    r|   rE   c_dt64arr_to_periodarrr  )r   rD   r   ra  rH   s        rK   r   r     s    , djj"((+tzz#/E=566|dH%tyy$Di(tww||$D	D8Y/	0||tzz*D%%d+D""D!$))D/4$GMMrM   c                |   t        j                  | ||      dk7  rt        d      |t        |      }|j                  }| t        | |      } |t        ||      }t        | t
              }t        |t
              }|r&|r$| j                  |j                  k7  rt        d      | t        u s|t        u rt        d      |)|r| j                  }n|r|j                  }nt        d      |||z  }| Ht        j                  |j                  |z
  |z   |j                  dz   |t        j                        }||fS t        j                  | j                  | j                  |z   |t        j                        }||fS t        j                  | j                  |j                  dz   |t        j                        }||fS )N   zOOf the three parameters: start, end, and periods, exactly two must be 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}   rD   r   r   aranger   rw   )r   r   r   rD   multis_start_per
is_end_perr   s           rK   r   r   .  s   
%g.!3,
 	

 vvud#
S$eV,LC(J
uzzSXX'=<==|scz899|::D88DBCCD.=99g%,ckkAot288D : 99u}}w6BHHD : yyaRXXN:rM   c                (   |d}|d}|d}|d}g }||&t        d      }t        j                  j                  }	nHt        |      }t	        j
                  |      }	|	t        j                  j                  k7  rt        d      |j                  }
t        | |      \  } }t        | |      D ]M  \  }}t        j                  |||
      \  }}t	        j                  ||dddddd|		      }|j                  |       O npt        |      }t	        j
                  |      }	t        | |||||      }t        | D ]5  \  }}}}}}|j                  t	        j                  ||||||dd|		             7 t        j                  |t        j                         |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   rw   )r^   r_   rk   r`   ra   rb   rc   rD   r   rH   r   yqmvalarraysmthdhmnss                        rK   r   r   ^  s    |~~
{H<S>D##))DT?D//5Dy''---$%=>>,,*49gg& 	!DAq++Aq':DAq**1aAq!Q4HCOOC 	!
 ++D1#D%dFFK#&< 	WAsAq"aOOI44QQ2q!QPTUV	W 88HBHH-t33rM   c            	     x   d }| D ]Q  }t        |t        t        j                  t        f      s)|t        |      |k7  rt        d      |Gt        |      }S | D cg c]R  }t        |t        j                  t        t        f      rt        j                  |      nt        j                  ||      T c}S c c}w )NzMismatched Period array lengths)	r}   r   r   r   r4   r   r   r   repeat)r   lengthr   s      rK   rr  rr    s    F  a$

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

1YYq&!	"  s   AB7rC   )rJ   r   )NF)r   z,Sequence[Period | str | None] | AnyArrayLikerD   zstr | Tick | Nonerz   r   r;  r@   )rD   r=   r;  r=   )rD   ztimedelta | str | Noner;  r   )rD   z$BaseOffsetT | timedelta | str | Noner;  r=   )r;  z(tuple[npt.NDArray[np.int64], BaseOffset])r   )NNNNNNNN)r;  ztuple[np.ndarray, BaseOffset])r;  zlist[np.ndarray])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   rd  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/   r0   pandas.core.dtypes.dtypesr1   pandas.core.dtypes.genericr2   r3   r4   r5   pandas.core.dtypes.missingr6   pandas.core.algorithmscore
algorithmsr   r7   r   pandas.core.commoncommonrg  r8   r9   r:   r;   pandas.core.arrays.baser<   r=   rL  rR   DatelikeOpsPeriodMixinr@   r   rZ  r{   r   r   rr  r   rM   rK   <module>r     s   "      .    1 5  
	 	 	 2  , & & 2    
 7 m:6 ] 
a,#//9#8#8 a,H&F #Y9
6Y9
Y9 Y9 	Y9x 
 
 
 
%5%%R %N-%NP-b 

		,4 #,4^rM   