a
    DBìj"J  ã                   @  sÌ  d dl mZ d dlmZmZ d dlmZ d dlZd dlZd dl	m
Z d dlmZmZmZmZmZ d dlmZ d dlmZmZ d d	lmZ d d
lmZ d dlmZ d dlmZ d dlm Z  d dl!m"Z"m#Z#m$Z$m%Z% d dl&m'  m(Z) d dl*m'  m+  m,Z- d dl*m.Z. d dl/m0Z0 d dl1m2Z2m3Z3 d dl4m5Z5 e�rXd dl6m7Z7 d dl8m9Z9m:Z:m;Z;m<Z< e=e-j>ƒZ>e> ?ddi¡ ddiZ@dd„ ZAe5g d¢e"jB e"dd�e5dge"ƒG dd „ d e0ƒƒƒZCd&d!d"d d#œd$d%„ZDdS )'é    )Úannotations)ÚdatetimeÚ	timedelta)ÚTYPE_CHECKINGN)Úindex)Ú
BaseOffsetÚNaTÚPeriodÚ
ResolutionÚTick)ÚOFFSET_TO_PERIOD_FREQSTR)Úcache_readonlyÚdoc)Úfind_stack_level)Ú
is_integer)ÚPeriodDtype)Ú	ABCSeries)Úis_valid_na_for_dtype)ÚPeriodArrayÚperiod_arrayÚraise_on_incompatibleÚvalidate_dtype_freq)Úmaybe_extract_name)ÚDatetimeIndexOpsMixin)ÚDatetimeIndexÚIndex)Úinherit_names)ÚHashable)ÚDtypeÚDtypeObjÚSelfÚnptZtarget_klasszPeriodIndex or list of PeriodsÚklassr   c                 K  sZ   |  d¡}|jdkrF|  dd ¡}t|ƒ}t||d�}| j|fi |¤ŽS | |fi |¤ŽS d S )NÚdataÚint64Úfreq©Údtype)Úpopr'   r   r   Ú_simple_new)ÚclsÚdÚvaluesr%   r'   © r-   úY/mnt/bigstor/www/usecases/.venv/lib/python3.9/site-packages/pandas/core/indexes/period.pyÚ_new_PeriodIndexD   s    

r/   )ÚstrftimeÚ
start_timeZend_timeT)ÚwrapZis_leap_yearc                
      s8  e Zd ZU dZdZded< ded< ded< eZd	Ze	d
dœdd„ƒZ
eddœdd„ƒZeejfdddœe¤Žd]dddœdd„ƒZeejƒd^dddœdd„ƒZe	eejjƒddœdd „ƒƒZe	eejjƒddœd!d"„ƒƒZe	eejjƒddœd#d$„ƒƒZd_d&d'd(dd)œd*d+„Zeddddddddd,œddœd-d.„ƒZedd/œddœd0d1„ƒZe	d2dœd3d4„ƒZd5dœd6d7„Zd8d'd9œd:d;„Zdd<d=d>œ‡ fd?d@„Ze	d'dœdAdB„ƒZe	ddœdCdD„ƒZ‡ fdEdF„ZdGdH„ Z dIdJdKœdLdM„Z!dNdIdOœdPdQ„Z"ee#j$ƒddRœ‡ fdSdT„ƒZ$ddNdUœdVdW„Z%ee#j&ƒd`dYddZœd[d\„ƒZ&‡  Z'S )aÚPeriodIndexaí  
    Immutable ndarray holding ordinal values indicating regular periods in time.

    Index keys are boxed to Period objects which carries the metadata (eg,
    frequency information).

    Parameters
    ----------
    data : array-like (1d int np.ndarray or PeriodArray), optional
        Optional period-like data to construct index with.
    copy : bool
        Make a copy of input ndarray.
    freq : str or period object, optional
        One of pandas period strings or corresponding objects.
    year : int, array, or Series, default None

        .. deprecated:: 2.2.0
           Use PeriodIndex.from_fields instead.
    month : int, array, or Series, default None

        .. deprecated:: 2.2.0
           Use PeriodIndex.from_fields instead.
    quarter : int, array, or Series, default None

        .. deprecated:: 2.2.0
           Use PeriodIndex.from_fields instead.
    day : int, array, or Series, default None

        .. deprecated:: 2.2.0
           Use PeriodIndex.from_fields instead.
    hour : int, array, or Series, default None

        .. deprecated:: 2.2.0
           Use PeriodIndex.from_fields instead.
    minute : int, array, or Series, default None

        .. deprecated:: 2.2.0
           Use PeriodIndex.from_fields instead.
    second : int, array, or Series, default None

        .. deprecated:: 2.2.0
           Use PeriodIndex.from_fields instead.
    dtype : str or PeriodDtype, default None

    Attributes
    ----------
    day
    dayofweek
    day_of_week
    dayofyear
    day_of_year
    days_in_month
    daysinmonth
    end_time
    freq
    freqstr
    hour
    is_leap_year
    minute
    month
    quarter
    qyear
    second
    start_time
    week
    weekday
    weekofyear
    year

    Methods
    -------
    asfreq
    strftime
    to_timestamp
    from_fields
    from_ordinals

    See Also
    --------
    Index : The base pandas Index type.
    Period : Represents a period of time.
    DatetimeIndex : Index with datetime64 data.
    TimedeltaIndex : Index of timedelta64 data.
    period_range : Create a fixed-frequency PeriodIndex.

    Examples
    --------
    >>> idx = pd.PeriodIndex.from_fields(year=[2000, 2002], quarter=[1, 3])
    >>> idx
    PeriodIndex(['2000Q1', '2002Q3'], dtype='period[Q-DEC]')
    Zperiodindexr   Ú_datar   r%   r   r'   Tztype[libindex.PeriodEngine])Úreturnc                 C  s   t jS ©N)ÚlibindexZPeriodEngine©Úselfr-   r-   r.   Ú_engine_type¼   s    zPeriodIndex._engine_typer
   c                 C  s   | j jS r6   )r'   Ú_resolution_objr8   r-   r-   r.   r;   À   s    zPeriodIndex._resolution_objzpandas.arrays.PeriodArray)ÚotherZ
other_nameNÚEÚstrr    )Úhowr5   c                 C  s"   | j  ||¡}t| ƒj|| jd�S ©N©Úname)r4   ÚasfreqÚtyper)   rB   ©r9   r%   r?   Úarrr-   r-   r.   rC   É   s    zPeriodIndex.asfreqÚstartr   c                 C  s   | j  ||¡}tj|| jd�S r@   )r4   Úto_timestampr   r)   rB   rE   r-   r-   r.   rH   Ó   s    zPeriodIndex.to_timestampr   c                 C  s   t | jj| jd�S r@   )r   r4   ÚhourrB   r8   r-   r-   r.   rI   Ø   s    zPeriodIndex.hourc                 C  s   t | jj| jd�S r@   )r   r4   ÚminuterB   r8   r-   r-   r.   rJ   Ý   s    zPeriodIndex.minutec                 C  s   t | jj| jd�S r@   )r   r4   ÚsecondrB   r8   r-   r-   r.   rK   â   s    zPeriodIndex.secondFzDtype | NoneÚboolúHashable | None)r'   ÚcopyrB   r5   c                 K  s¦  h d£}d }	|s$t |ttfƒr$|j}	t|ƒ |¡sVttt|ƒ| ƒƒ}
td|
› �ƒ‚nt	|ƒrpt
jdttƒ d� |d urŠt
jdttƒ d� t||| ƒ}|d u rÔ|d u rÔ|s´|  d ¡ | jf i |¤d|i¤Žj}d}n´|rò|d urètdƒ‚td	ƒ‚n–t||ƒ}|�r$t || ƒ�r$|j|k�r$| |¡}|d u �r^|d u�r^tj|tjd
�}t|ƒ}t||d
�}n*|d u�r||d u�r|tdƒ‚nt||d�}|�r–| ¡ }| j|||	d�S )N>   rI   ÚquarterrJ   ÚyearÚdayÚmonthrK   z-__new__() got an unexpected keyword argument zXConstructing PeriodIndex from fields is deprecated. Use PeriodIndex.from_fields instead.)Ú
stacklevelz‚The 'ordinal' keyword in PeriodIndex is deprecated and will be removed in a future version. Use PeriodIndex.from_ordinals instead.r%   Fz Cannot pass both data and fieldsz#Cannot pass both ordinal and fieldsr&   z!Cannot pass both data and ordinal)r#   r%   )rB   Úrefs)Ú
isinstancer   r   Z_referencesÚsetÚissubsetÚnextÚiterÚ	TypeErrorÚlenÚwarningsÚwarnÚFutureWarningr   r   Z_raise_scalar_data_errorÚfrom_fieldsr4   Ú
ValueErrorr   r%   rC   ÚnpÚasarrayr$   r   r   r   rN   r)   )r*   r#   Zordinalr%   r'   rN   rB   ÚfieldsZvalid_field_setrT   Úargumentr-   r-   r.   Ú__new__ê   sT    

üû




zPeriodIndex.__new__)rP   rO   rR   rQ   rI   rJ   rK   r%   c                C  s>   |||||||dœ}	dd„ |	  ¡ D ƒ}	tj|	|d�}
|  |
¡S )N)rP   rO   rR   rQ   rI   rJ   rK   c                 S  s   i | ]\}}|d ur||“qS r6   r-   )Ú.0ÚkeyÚvaluer-   r-   r.   Ú
<dictcomp>W  ó    z+PeriodIndex.from_fields.<locals>.<dictcomp>)rc   r%   )Úitemsr   Z_from_fieldsr)   )r*   rP   rO   rR   rQ   rI   rJ   rK   r%   rc   rF   r-   r-   r.   r_   A  s    ù	zPeriodIndex.from_fieldsrA   c                C  s4   t j|t jd�}t|ƒ}tj||d�}| j||d�S )Nr&   rA   )ra   rb   r$   r   r   r)   )r*   Zordinalsr%   rB   r'   r#   r-   r-   r.   Úfrom_ordinals[  s    zPeriodIndex.from_ordinalsznpt.NDArray[np.object_]c                 C  s   t j| td�S )Nr&   )ra   rb   Úobjectr8   r-   r-   r.   r,   e  s    zPeriodIndex.valueszint | npt.NDArray[np.int64]c                 C  s†   t |ttjttjfƒr4t | jtƒrx| j |¡}|S nDt |t	ƒr^|j
| jj
krR|jS t| |ƒ‚nt|ƒrxt |tƒstJ ‚|S t| dƒ‚dS )aÅ  
        Convert timedelta-like input to an integer multiple of self.freq

        Parameters
        ----------
        other : timedelta, np.timedelta64, DateOffset, int, np.ndarray

        Returns
        -------
        converted : int, np.ndarray[int64]

        Raises
        ------
        IncompatibleFrequency : if the input cannot be written as a multiple
            of self.freq.  Note IncompatibleFrequency subclasses ValueError.
        N)rU   r   ra   Ztimedelta64r   Zndarrayr%   r4   Z _check_timedeltalike_freq_compatr   ÚbaseÚnr   r   Úint)r9   r<   Údeltar-   r-   r.   Ú_maybe_convert_timedeltai  s    
z$PeriodIndex._maybe_convert_timedeltar   )r'   r5   c                 C  s
   | j |kS )zF
        Can we compare values of the given dtype to our own?
        r&   )r9   r'   r-   r-   r.   Ú_is_comparable_dtype‹  s    z PeriodIndex._is_comparable_dtypeznpt.NDArray[np.bool_]z
np.ndarray)ÚwhereÚmaskr5   c                   s<   t |tƒrt|j| jd�}nt |tƒs.tdƒ‚tƒ  ||¡S )z�
        where : array of timestamps
        mask : np.ndarray[bool]
            Array of booleans where data is not NA.
        ©r%   z6asof_locs `where` must be DatetimeIndex or PeriodIndex)rU   r   r3   Z_valuesr%   rZ   ÚsuperÚ	asof_locs)r9   rt   ru   ©Ú	__class__r-   r.   rx   ”  s
    

zPeriodIndex.asof_locsc                 C  sH   t | ƒdkrdS | jstdƒ‚| j}t|dd… |dd…  dk  ¡ ƒS )z‰
        Returns True if this PeriodIndex is range-like in that all Periods
        between start and end are present, in order.
        r   TzIndex is not monotonicé   Néÿÿÿÿé   )r[   Zis_monotonic_increasingr`   Zasi8rL   Úall)r9   r,   r-   r-   r.   Úis_full¡  s    zPeriodIndex.is_fullc                 C  s   dS )NÚperiodr-   r8   r-   r-   r.   Úinferred_type®  s    zPeriodIndex.inferred_typec                   s(   t ƒ  ||¡}| j|jkr$|  |¡}|S r6   )rw   Ú_convert_tolerancer'   rr   )r9   Z	toleranceÚtargetry   r-   r.   r‚   ·  s    
zPeriodIndex._convert_tolerancec              
   C  sV  |}|   |¡ t|| jƒr t}nòt|tƒrÜz|  |¡\}}W n6 tyr } ztd|› d�ƒ|‚W Y d}~n
d}~0 0 |  	|¡r¼z|  
||¡W S  tyº } zt|ƒ|‚W Y d}~n
d}~0 0 || jkrÒ|  |¡}nt|ƒ‚n6t|tƒrò|  |¡ n t|tƒ�r
|  |¡}nt|ƒ‚zt | |¡W S  t�yP } zt|ƒ|‚W Y d}~n
d}~0 0 dS )a»  
        Get integer location for requested label.

        Parameters
        ----------
        key : Period, NaT, str, or datetime
            String or datetime key must be parsable as Period.

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

        Raises
        ------
        KeyError
            Key is not present in the index.
        TypeError
            If key is listlike or otherwise not hashable.
        zCannot interpret 'z' as periodN)Z_check_indexing_errorr   r'   r   rU   r>   Z_parse_with_resor`   ÚKeyErrorZ_can_partial_date_sliceZ_partial_date_slicer;   Ú_cast_partial_indexing_scalarr	   Ú_disallow_mismatched_indexingr   r   Úget_loc)r9   rg   Úorig_keyÚparsedÚresoÚerrr-   r-   r.   r‡   Ä  s4    

(
 


zPeriodIndex.get_locr	   ÚNone)rg   r5   c                 C  s   |j | jkrt|ƒ‚d S r6   )Z_dtyper'   r„   )r9   rg   r-   r-   r.   r†     s    z)PeriodIndex._disallow_mismatched_indexingr   )Úlabelr5   c              
   C  sF   zt || jd�}W n. ty@ } zt|ƒ|‚W Y d }~n
d }~0 0 |S )Nrv   )r	   r%   r`   r„   )r9   r�   r€   r‹   r-   r-   r.   r…     s
     z)PeriodIndex._cast_partial_indexing_scalar)Úsidec                   s"   t |tƒr|  |¡}tƒ  ||¡S r6   )rU   r   r…   rw   Ú_maybe_cast_slice_bound)r9   r�   rŽ   ry   r-   r.   r�     s    

z#PeriodIndex._maybe_cast_slice_bound)rŠ   r‰   c                 C  s<   t  |j|j¡}t||d�}|j| jdd�|j| jdd�fS )Nrv   rG   )r?   Úend)r   ÚgetZattr_abbrevr	   rC   r%   )r9   rŠ   r‰   r%   Zivr-   r-   r.   Ú_parsed_string_to_bounds  s    z$PeriodIndex._parsed_string_to_boundsr{   rp   )Úperiodsr5   c                 C  s&   |d urt dt| ƒj› d�ƒ‚| | S )Nz%`freq` argument is not supported for z.shift)rZ   rD   Ú__name__)r9   r“   r%   r-   r-   r.   Úshift  s
    ÿzPeriodIndex.shift)Nr=   )NrG   )NNNNFN)r{   N)(r”   Ú
__module__Ú__qualname__Ú__doc__Z_typÚ__annotations__r   Z	_data_clsZ!_supports_partial_string_indexingÚpropertyr:   r   r;   r   rC   Ú_shared_doc_kwargsrH   rI   ÚfgetrJ   rK   re   Úclassmethodr_   rl   r,   rr   rs   rx   r   r�   r‚   r‡   r†   r…   r   r�   r’   r•   Ú__classcell__r-   r-   ry   r.   r3   P   sˆ   
\ÿýü


      ùWö	"	>r3   z
int | NonerM   )r“   rB   r5   c                 C  sn   t  | ||¡dkrtdƒ‚|du r:t| tƒs:t|tƒs:d}t | |||¡\}}t|ƒ}t||d�}t||d�S )a  
    Return a fixed frequency PeriodIndex.

    The day (calendar) is the default frequency.

    Parameters
    ----------
    start : str, datetime, date, pandas.Timestamp, or period-like, default None
        Left bound for generating periods.
    end : str, datetime, date, pandas.Timestamp, or period-like, default None
        Right bound for generating periods.
    periods : int, default None
        Number of periods to generate.
    freq : str or DateOffset, optional
        Frequency alias. By default the freq is taken from `start` or `end`
        if those are Period objects. Otherwise, the default is ``"D"`` for
        daily frequency.
    name : str, default None
        Name of the resulting PeriodIndex.

    Returns
    -------
    PeriodIndex

    Notes
    -----
    Of the three parameters: ``start``, ``end``, and ``periods``, exactly two
    must be specified.

    To learn more about the frequency strings, please see `this link
    <https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#offset-aliases>`__.

    Examples
    --------
    >>> pd.period_range(start='2017-01-01', end='2018-01-01', freq='M')
    PeriodIndex(['2017-01', '2017-02', '2017-03', '2017-04', '2017-05', '2017-06',
             '2017-07', '2017-08', '2017-09', '2017-10', '2017-11', '2017-12',
             '2018-01'],
            dtype='period[M]')

    If ``start`` or ``end`` are ``Period`` objects, they will be used as anchor
    endpoints for a ``PeriodIndex`` with frequency matching that of the
    ``period_range`` constructor.

    >>> pd.period_range(start=pd.Period('2017Q1', freq='Q'),
    ...                 end=pd.Period('2017Q2', freq='Q'), freq='M')
    PeriodIndex(['2017-03', '2017-04', '2017-05', '2017-06'],
                dtype='period[M]')
    r}   zOOf the three parameters: start, end, and periods, exactly two must be specifiedNÚDr&   rA   )	ÚcomZcount_not_noner`   rU   r	   r   Z_generate_ranger   r3   )rG   r�   r“   r%   rB   r#   r'   r-   r-   r.   Úperiod_range#  s    8ÿr¡   )NNNNN)EÚ
__future__r   r   r   Útypingr   r\   Únumpyra   Zpandas._libsr   r7   Zpandas._libs.tslibsr   r   r	   r
   r   Zpandas._libs.tslibs.dtypesr   Zpandas.util._decoratorsr   r   Zpandas.util._exceptionsr   Zpandas.core.dtypes.commonr   Zpandas.core.dtypes.dtypesr   Zpandas.core.dtypes.genericr   Zpandas.core.dtypes.missingr   Zpandas.core.arrays.periodr   r   r   r   Zpandas.core.commonÚcoreÚcommonr    Zpandas.core.indexes.baseZindexesrn   Zibaser   Z pandas.core.indexes.datetimeliker   Zpandas.core.indexes.datetimesr   r   Zpandas.core.indexes.extensionr   Úcollections.abcr   Zpandas._typingr   r   r    r!   ÚdictZ_index_doc_kwargsÚupdater›   r/   Z
_field_opsr3   r¡   r-   r-   r-   r.   Ú<module>   sX   
ÿý
   Q     û