o
    $ja                    @  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mZ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 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&m'Z'm(Z(m)Z)m*Z*m+Z+ d d
l,m-Z-m.Z. d dl/m0Z0 d dl1m2Z2 d dl3m4Z4 d dl5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZE d dlFmGZH d dlImJZJmKZKmLZL d dlMmNZNmOZOmPZP d dlQmRZR d dlSmTZT d dlUmVZVmWZWmXZXmYZYmZZZm[Z[ d dl\m]Z]m^Z^m_Z_m`Z`maZa d dlbmcZcmdZd d dlemfZfmgZg d dlhmiZimjZjmkZkmlZl d dlmmnZnmoZompZp d dlqmrZr d dlsmtZt d dlumvZvmwZw d dlxmyZy d dlzm{Z{ d dl|m}Z} d dl~m  mZ d d lmZmZmZ d d!lmZmZ d d"lmZ d d#lmZmZ d d$lmZ erd d%lmZmZ d d&lmZ d d'lmZmZmZ ee8ef ZdTd*d+ZdUd/d0ZG d1d2 d2etevZG d3d4 d4eZd5Zd6Zd7Zd8ZG d9d: d:eZdVd?d@ZedWdCdDZedXdGdDZdYdJdDZdZdNdOZd[dRdSZdS )\    )annotations)datetime	timedelta)wrapsN)TYPE_CHECKINGAnyCallableLiteralUnioncastfinaloverload)using_string_dtype)algoslib)NDArrayBacked)
BaseOffsetIncompatibleFrequencyNaTNaTTypePeriod
ResolutionTick	Timedelta	Timestampadd_overflowsafeastype_overflowsafeget_unit_from_dtypeiNaTints_to_pydatetimeints_to_pytimedeltaperiods_per_day	to_offset)RoundToround_nsint64)compare_mismatched_resolutions)get_unit_for_round)integer_op_not_supported)	ArrayLikeAxisIntDatetimeLikeScalarDtypeDtypeObjFInterpolateOptionsNpDtypePositionalIndexer2DPositionalIndexerTupleScalarIndexerSelfSequenceIndexerTimeAmbiguousTimeNonexistentnpt)function)AbstractMethodErrorInvalidComparisonPerformanceWarning)AppenderSubstitutioncache_readonly)find_stack_level)'construct_1d_object_array_from_listlike)is_all_stringsis_integer_dtypeis_list_likeis_object_dtypeis_string_dtypepandas_dtype)
ArrowDtypeCategoricalDtypeDatetimeTZDtypeExtensionDtypePeriodDtype)ABCCategoricalABCMultiIndex)is_valid_na_for_dtypeisna)
algorithmsmissingnanopsops)isin	map_arrayunique1d)datetimelike_accumulations)OpsMixin)NDArrayBackedExtensionArrayravel_compat)ArrowExtensionArray)ExtensionArray)IntegerArray)arrayensure_wrapped_if_datetimelikeextract_array)check_array_indexercheck_setitem_lengths)unpack_zerodim_and_defer)invalid_comparisonmake_invalid_op)frequencies)IteratorSequenceIndex)DatetimeArrayPeriodArrayTimedeltaArrayop_namestrc                 C  s   t | }t| |S N)re   rc   )rn   op rr   `/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/pandas/core/arrays/datetimelike.py_make_unpacked_invalid_op   s   rt   methr-   returnc                   s   t   fdd}tt|S )z
    For PeriodArray methods, dispatch to DatetimeArray and re-wrap the results
    in PeriodArray.  We cannot use ._ndarray directly for the affected
    methods because the i8 data has different semantics on NaT values.
    c                   sx   t | jts | g|R i |S | d} |g|R i |}|tu r'tS t |tr2| |jS |d}| |S )NM8[ns]i8)	
isinstancedtyperK   viewr   r   	_box_func_value_from_backing_data)selfargskwargsarrresultZres_i8ru   rr   rs   new_meth   s   



z"_period_dispatch.<locals>.new_meth)r   r   r-   )ru   r   rr   r   rs   _period_dispatch   s   
r   c                      s  e Zd ZU dZded< ded< ded< ded	< d
ed< edddZ	ddddZedddZ	dddZ
dd!d"Zdd$d%Zd&d' Zdd(d)Zdd+d,Zedd.d/Zd0dd1d d5d6Zddd8d9Z	ddd<d=Zedd@dAZeddDdAZd fdHdAZddIdJZd	 fdMdNZd
dOdPZdd fdRdSZeddTdUZeddXdUZedd[dUZeddd^dUZdd fd_dUZd`da ZddQdbddedfZdddgdhZdddjdkZdldm Ze ddodpZ!e"ddqdrZ#ddudvZ$ddwdxZ%eddydzZ&edd{d|Z'e(dfdd~dZ)edddZ*edddZ+edddZ,edddZ-edddZ.edddZ/edddZ0dd Z1e2dZ3e2dZ4e2dZ5e2dZ6e2dZ7e2dZ8e2dZ9e2dZ:e2dZ;e2dZ<e2dZ=e2dZ>e dddZ?e dddZ@e dddZAe dddZBe d ddZCe d!ddZDe d"ddZEe d#ddZFdd ZGdd ZHd$ddZIe d%ddZJe dd ZKe dd ZLe d&ddZMe d'ddĄZNdQdŜd(ddɄZOePdʃdd̄ ZQdd΄ ZRePdσddф ZSddӄ ZTdddՄZUdddׄZVeWd) fdd܄ZXeWddQdݜd*ddZYeWddQdݜd*ddZZdQddd+ddZ[eWddQdݜd*ddZ\dd,ddZ]d-ddZ^  Z_S (.  DatetimeLikeArrayMixinz
    Shared Base/Mixin class for DatetimeArray, TimedeltaArray, PeriodArray

    Assumes that __new__/__init__ defines:
        _ndarray

    and that inheriting subclass implements:
        freq
    ztuple[str, ...]_infer_matcheszCallable[[DtypeObj], bool]_is_recognized_dtypeztuple[type, ...]_recognized_scalars
np.ndarray_ndarrayBaseOffset | Nonefreqrv   boolc                 C  s   dS )NTrr   r   rr   rr   rs   _can_hold_na      z#DatetimeLikeArrayMixin._can_hold_naNFrz   Dtype | NonecopyNonec                 C     t | rp   r9   )r   datarz   r   r   rr   rr   rs   __init__   s   zDatetimeLikeArrayMixin.__init__type[DatetimeLikeScalar]c                 C  r   )z
        The scalar associated with this datelike

        * PeriodArray : Period
        * DatetimeArray : Timestamp
        * TimedeltaArray : Timedelta
        r   r   rr   rr   rs   _scalar_type   s   	z#DatetimeLikeArrayMixin._scalar_typevaluero   DTScalarOrNaTc                 C  r   )ay  
        Construct a scalar type from a string.

        Parameters
        ----------
        value : str

        Returns
        -------
        Period, Timestamp, or Timedelta, or NaT
            Whatever the type of ``self._scalar_type`` is.

        Notes
        -----
        This should call ``self._check_compatible_with`` before
        unboxing the result.
        r   r   r   rr   rr   rs   _scalar_from_string      z*DatetimeLikeArrayMixin._scalar_from_string)np.int64 | np.datetime64 | np.timedelta64c                 C  r   )a  
        Unbox the integer value of a scalar `value`.

        Parameters
        ----------
        value : Period, Timestamp, Timedelta, or NaT
            Depending on subclass.

        Returns
        -------
        int

        Examples
        --------
        >>> arr = pd.array(np.array(['1970-01-01'], 'datetime64[ns]'))
        >>> arr._unbox_scalar(arr[0])
        numpy.datetime64('1970-01-01T00:00:00.000000000')
        r   r   rr   rr   rs   _unbox_scalar  s   z$DatetimeLikeArrayMixin._unbox_scalarotherc                 C  r   )a|  
        Verify that `self` and `other` are compatible.

        * DatetimeArray verifies that the timezones (if any) match
        * PeriodArray verifies that the freq matches
        * Timedelta has no verification

        In each case, NaT is considered compatible.

        Parameters
        ----------
        other

        Raises
        ------
        Exception
        r   r   r   rr   rr   rs   _check_compatible_with  r   z-DatetimeLikeArrayMixin._check_compatible_withc                 C  r   )zI
        box function to get object from internal representation
        r   )r   xrr   rr   rs   r|   /     z DatetimeLikeArrayMixin._box_funcc                 C  s   t j|| jddS )z1
        apply box func to passed values
        F)convert)r   Z	map_inferr|   )r   valuesrr   rr   rs   _box_values5  s   z"DatetimeLikeArrayMixin._box_valuesrg   c                   s8    j dkr fddtt D S  fdd jD S )N   c                 3  s    | ]} | V  qd S rp   rr   ).0nr   rr   rs   	<genexpr>=  s    z2DatetimeLikeArrayMixin.__iter__.<locals>.<genexpr>c                 3  s    | ]}  |V  qd S rp   )r|   )r   vr   rr   rs   r   ?  s    )ndimrangelenasi8r   rr   r   rs   __iter__;  s   
zDatetimeLikeArrayMixin.__iter__npt.NDArray[np.int64]c                 C  s   | j dS )z
        Integer representation of the values.

        Returns
        -------
        ndarray
            An ndarray with int64 dtype.
        rx   )r   r{   r   rr   rr   rs   r   A  s   zDatetimeLikeArrayMixin.asi8r   )na_repdate_formatr   str | floatnpt.NDArray[np.object_]c                C  r   )z|
        Helper method for astype when converting to strings.

        Returns
        -------
        ndarray[str]
        r   )r   r   r   rr   rr   rs   _format_native_typesQ  s   
z+DatetimeLikeArrayMixin._format_native_typesboxedc                 C  s   dj S )Nz'{}')format)r   r   rr   rr   rs   
_formatter]  s   z!DatetimeLikeArrayMixin._formatterNpDtype | Nonebool | Nonec                 C  sR   t |r|du rtjdtt d tjt| tdS |du r&tj| j	|dS | j	S )NFaS  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.
stacklevelrz   T)
rD   warningswarnFutureWarningr?   npr^   listobjectr   )r   rz   r   rr   rr   rs   	__array__d  s   z DatetimeLikeArrayMixin.__array__itemr2   c                 C     d S rp   rr   r   r   rr   rr   rs   __getitem__{  r   z"DatetimeLikeArrayMixin.__getitem__(SequenceIndexer | PositionalIndexerTupler3   c                 C  r   rp   rr   r   rr   rr   rs   r     s   keyr0   Self | DTScalarOrNaTc                   s:   t dt |}t|r|S t t|}| ||_|S )z
        This getitem defers to the underlying array, which by-definition can
        only handle list-likes, slices, and integer scalars
        zUnion[Self, DTScalarOrNaT])r   superr   r   	is_scalarr3   _get_getitem_freq_freq)r   r   r   	__class__rr   rs   r     s   

c                 C  s   t | jt}|r| j}|S | jdkrd}|S t| |}d}t |tr9| jdur4|jdur4|j| j }|S | j}|S |tu rB| j}|S t	
|rZt|tj}t |trZ| |S |S )z\
        Find the `freq` attribute to assign to the result of a __getitem__ lookup.
        r   N)ry   rz   rK   r   r   ra   slicestepEllipsiscomZis_bool_indexerr   Zmaybe_booleans_to_slicer{   r   Zuint8r   )r   r   Z	is_periodr   Znew_keyrr   rr   rs   r     s.   


	


z(DatetimeLikeArrayMixin._get_getitem_freq,int | Sequence[int] | Sequence[bool] | sliceNaTType | Any | Sequence[Any]c                   s.   t ||| }t || |rd S |   d S rp   )rb   r   __setitem___maybe_clear_freq)r   r   r   Zno_opr   rr   rs   r     s
   z"DatetimeLikeArrayMixin.__setitem__c                 C  r   rp   rr   r   rr   rr   rs   r     s   z(DatetimeLikeArrayMixin._maybe_clear_freqTc           	        s\  t |}|tkr;| jjdkr"td| } | j}t|| jd| jd}|S | jjdkr/t	| j
ddS | | j | jS t|r[t|trW| j|jd}| }|j||d	d
S |  S t|trht j||dS |jdv r| j}|tjkrtd| j d| d|r| }|S |jdv r| j|ks|jdkrdt| j d| }t|tj| |dS )NMrk   	timestamp)tzboxresomT)r   )r   F)rz   r   r   iuzConverting from z to z? is not supported. Do obj.astype('int64').astype(dtype) insteadmMfzCannot cast z
 to dtype r   )rF   r   rz   kindr   r   r   r   _cresor    r   r   ravelreshapeshaperE   ry   rJ   r   na_valueZconstruct_array_type_from_sequencer   astyper   int64	TypeErrorr   type__name__asarray)	r   rz   r   Zi8dataZ	convertedZ
arr_objectclsr   msgr   rr   rs   r     sH   




zDatetimeLikeArrayMixin.astypec                 C  r   rp   rr   r   rr   rr   rs   r{   	  r   zDatetimeLikeArrayMixin.viewLiteral['M8[ns]']rk   c                 C  r   rp   rr   r   rz   rr   rr   rs   r{     r   Literal['m8[ns]']rm   c                 C  r   rp   rr   r   rr   rr   rs   r{     r   .r(   c                 C  r   rp   rr   r   rr   rr   rs   r{     r   c                   s   t  |S rp   )r   r{   r   r   rr   rs   r{     s   c              
   C  s  t |trz| |}W n ttfy   t|w t || js$|tu rE| |}z| 	| W |S  t
tfyD } zt||d }~ww t|sMt|t|t| krYtdz| j|dd}| 	| W |S  t
tfy } ztt|dd r{nt||W Y d }~|S d }~ww )NzLengths must matchT)allow_objectrz   )ry   ro   r   
ValueErrorr   r:   r   r   r   r   r   rC   r   _validate_listlikerD   getattr)r   r   errrr   rr   rs   _validate_comparison_value#  s>   




z1DatetimeLikeArrayMixin._validate_comparison_value)allow_listlikeunboxr  r  c             
   C  s   t || jrnQt |tr+z| |}W nD ty* } z| ||}t||d}~ww t|| jr4t	}n$t
|rB| ||}t|t || jrN| |}n
| ||}t||s\|S | |S )a  
        Validate that the input value can be cast to our scalar_type.

        Parameters
        ----------
        value : object
        allow_listlike: bool, default False
            When raising an exception, whether the message should say
            listlike inputs are allowed.
        unbox : bool, default True
            Whether to unbox the result before returning.  Note: unbox=False
            skips the setitem compatibility check.

        Returns
        -------
        self._scalar_type or NaT
        N)ry   r   ro   r   r   _validation_error_messager   rN   rz   r   rO   r   r   )r   r   r  r  r   r   rr   rr   rs   _validate_scalarG  s,   


z'DatetimeLikeArrayMixin._validate_scalarc                 C  sr   t |drt|dddkr|j d}n	dt|j d}|r,d| jj d| d}|S d| jj d	| d}|S )
a+  
        Construct an exception message on validation error.

        Some methods allow only scalar inputs, while others allow either scalar
        or listlike.

        Parameters
        ----------
        allow_listlike: bool, default False

        Returns
        -------
        str
        rz   r   r   z array'zvalue should be a 'z!', 'NaT', or array of those. Got z	 instead.z' or 'NaT'. Got )hasattrr   rz   r   r   r   )r   r   r  Zmsg_gotr   rr   rr   rs   r    s   	z0DatetimeLikeArrayMixin._validation_error_messager   c              	   C  s  t |t| r| jjdv r|s|j| jdd}|S t |tr.t|dkr.t| jg | jdS t	|drc|jt
krct|| jv rcz	t| |}W n ttfyb   |rX| Y S | |d}t|w t|dd}t|}t|dd}t|rzt| j|| jd}W n	 ty   Y nw t |jtr|jj| jkr| }t|dd}|rt|jrnt| |js| |d}t|| jjdv r|s|j| jdd}|S )	Nr   Fround_okr   r   rz   TZextract_numpy)ry   r   rz   r   as_unitunitr   r   r   r  r   r   infer_dtyper   r   r   r  r`   pd_arrayrA   rH   
categoriesZ_internal_get_valuesrD   r   )r   r   r   r   rr   rr   rs   r     sJ   	z)DatetimeLikeArrayMixin._validate_listlikec                 C  s,   t |r
| |}n| j|ddS | |S )NT)r  )rC   r   r  _unboxr   rr   rr   rs   _validate_setitem_value  s   
z.DatetimeLikeArrayMixin._validate_setitem_value6np.int64 | np.datetime64 | np.timedelta64 | np.ndarrayc                 C  s,   t |r| |}|S | | |j}|S )zZ
        Unbox either a scalar with _unbox_scalar or an instance of our own type.
        )r   r   r   r   r   r   rr   rr   rs   r    s   


zDatetimeLikeArrayMixin._unboxc                 C  s:   ddl m} t| ||d}||}t|tr| S |jS )Nr   ri   )	na_action)pandasrj   rU   ry   rM   to_numpyr^   )r   Zmapperr  rj   r   rr   rr   rs   map  s   
zDatetimeLikeArrayMixin.mapr   npt.NDArray[np.bool_]c              	   C  sj  |j jdv rtj| jtdS t|}t|t| sg d}|j t	krYt
j|d| j d}|j t	kr5| |S t
j|dd}||vrY|dkrEnd	|v rQt| t	|S tj| jtdS z	t| |}W n tys   t| t	| Y S w tjd
| j  dtt d | j jdv rtd| } || j}z| | W n ttfy   tj| jtd Y S w t| j|jS )z
        Compute boolean array of whether each value is found in the
        passed set of values.

        Parameters
        ----------
        values : np.ndarray or ExtensionArray

        Returns
        -------
        ndarray[bool]
        Zfiucr   )r   timedelta64r   
datetime64dateZperiodT)Zconvert_non_numericZdtype_if_all_natFskipnastringmixedz"The behavior of 'isin' with dtype=z and castable values (e.g. strings) is deprecated. In a future version, these will not be considered matching by isin. Explicitly cast to the appropriate dtype before calling isin instead.r   r   DatetimeArray | TimedeltaArray)rz   r   r   zerosr   r   r_   ry   r   r   r   Zmaybe_convert_objectsrT   r  r   r   r   r   r   r   r?   r   r
  r  r   r   r   )r   r   Z	inferableinferredrr   rr   rs   rT     sN   



zDatetimeLikeArrayMixin.isinc                 C     | j S rp   )_isnanr   rr   rr   rs   rO   X  s   zDatetimeLikeArrayMixin.isnac                 C  s
   | j tkS )z-
        return if each value is nan
        )r   r   r   rr   rr   rs   r"  [     
zDatetimeLikeArrayMixin._isnanc                 C  s   t | j S )zJ
        return if I have any nans; enables various perf speedups
        )r   r"  anyr   rr   rr   rs   _hasnab  s   zDatetimeLikeArrayMixin._hasnar   c                 C  s6   | j r|r
||}|du rtj}t|| j| |S )az  
        Parameters
        ----------
        result : np.ndarray
        fill_value : object, default iNaT
        convert : str, dtype or None

        Returns
        -------
        result : ndarray with values replace by the fill_value

        mask the result if needed, convert to the provided dtype if its not
        None

        This is an internal routine.
        N)r%  r   r   nanputmaskr"  )r   r   
fill_valuer   rr   rr   rs   _maybe_mask_resultsi  s   
z*DatetimeLikeArrayMixin._maybe_mask_results
str | Nonec                 C  s   | j du rdS | j jS )a{  
        Return the frequency object as a string if it's set, otherwise None.

        Examples
        --------
        For DatetimeIndex:

        >>> idx = pd.DatetimeIndex(["1/1/2020 10:00:00+00:00"], freq="D")
        >>> idx.freqstr
        'D'

        The frequency can be inferred if there are more than 2 points:

        >>> idx = pd.DatetimeIndex(["2018-01-01", "2018-01-03", "2018-01-05"],
        ...                        freq="infer")
        >>> idx.freqstr
        '2D'

        For PeriodIndex:

        >>> idx = pd.PeriodIndex(["2023-1", "2023-2", "2023-3"], freq="M")
        >>> idx.freqstr
        'M'
        N)r   freqstrr   rr   rr   rs   r+    s   
zDatetimeLikeArrayMixin.freqstrc                 C  s0   | j dkrdS zt| W S  ty   Y dS w )ax  
        Tries to return a string representing a frequency generated by infer_freq.

        Returns None if it can't autodetect the frequency.

        Examples
        --------
        For DatetimeIndex:

        >>> idx = pd.DatetimeIndex(["2018-01-01", "2018-01-03", "2018-01-05"])
        >>> idx.inferred_freq
        '2D'

        For TimedeltaIndex:

        >>> tdelta_idx = pd.to_timedelta(["0 days", "10 days", "20 days"])
        >>> tdelta_idx
        TimedeltaIndex(['0 days', '10 days', '20 days'],
                       dtype='timedelta64[ns]', freq=None)
        >>> tdelta_idx.inferred_freq
        '10D'
        r   N)r   rf   Z
infer_freqr   r   rr   rr   rs   inferred_freq  s   
z$DatetimeLikeArrayMixin.inferred_freqResolution | Nonec                 C  s4   | j }|d u r	d S zt|W S  ty   Y d S w rp   )r+  r   Zget_reso_from_freqstrKeyError)r   r+  rr   rr   rs   _resolution_obj  s   z&DatetimeLikeArrayMixin._resolution_objc                 C  s   | j jS )zO
        Returns day, hour, minute, second, millisecond or microsecond
        )r/  attrnamer   rr   rr   rs   
resolution  s   z!DatetimeLikeArrayMixin.resolutionc                 C     t j| jddd S )NTZtimeliker   r   Zis_monotonicr   r   rr   rr   rs   _is_monotonic_increasing     z/DatetimeLikeArrayMixin._is_monotonic_increasingc                 C  r2  )NTr3  r   r4  r   rr   rr   rs   _is_monotonic_decreasing  r6  z/DatetimeLikeArrayMixin._is_monotonic_decreasingc                 C  s   t t| jd| jkS )NK)r   rV   r   r   sizer   rr   rr   rs   
_is_unique  s   z!DatetimeLikeArrayMixin._is_uniquec           
      C  s  | j dkrt|dd | jkr||  | | jS z| |}W n ty1   t| || Y S w t|dd }t|rKt	
|t| t|}|S |tu rh|tju r^tj| jtd}|S tj| jtd}|S t| jtstt| } | j|jkrt|t| sz
|j| jdd}W n  ty   t|j }t!| j"|| Y S w |j"}t!| j"||S | #|}|| j"$d|$d}t%|}| j&|B }|' r|tju }	t(|||	 |S )Nr   r   rz   r   Fr  rx   ))r   r   r   r   r   r   r:   rd   rD   rS   Zcomp_method_OBJECT_ARRAYr   r   r   r   r   operatorneZonesr   r  ry   rz   rK   r   TimelikeOpsr   r   r
  r  r   r^   Zasm8r%   r   r  r{   rO   r"  r$  r'  )
r   r   rq   rz   r   Z	other_arrZ
other_valso_maskmaskZ
nat_resultrr   rr   rs   _cmp_method  sR   




z"DatetimeLikeArrayMixin._cmp_method__pow____rpow____mul____rmul____truediv____rtruediv____floordiv____rfloordiv____mod____rmod__
__divmod____rdivmod__@tuple[int | npt.NDArray[np.int64], None | npt.NDArray[np.bool_]]c                 C  sP   t |tr|j}d}||fS t |ttfr|j}d}||fS |j}|j}||fS )zN
        Get the int64 values and b_mask to pass to add_overflowsafe.
        N)ry   r   ordinalr   r   r}   r"  r   )r   r   Zi8valuesr?  rr   rr   rs   _get_i8_values_and_mask.  s   
z.DatetimeLikeArrayMixin._get_i8_values_and_maskc                 C  s6   t | jtr	| jS t|sdS t | jtr| jS dS )zP
        Check if we can preserve self.freq in addition or subtraction.
        N)ry   rz   rK   r   r   r   r   r   rr   rr   rs   _get_arithmetic_result_freqA  s   
z2DatetimeLikeArrayMixin._get_arithmetic_result_freqc           
      C  s(  t | jdstdt| j dt|j td| } ddlm} ddl	m
} |tus.J t|rI| jt d| j d	 }|j||jd
S t|}| |\} }td| } | |\}}t| jtj|dd
}|d| j d	}||j| jd}|d| j d	}| |}	|j|||	dS )Nr   cannot add  and rm   r   rk   )tz_to_dtypezM8[]r   rx   r   r  rz   r   )r   is_np_dtyperz   r   r   r   r   pandas.core.arraysrk   Zpandas.core.arrays.datetimesrT  r   rO   r   Zto_datetime64r   r  _simple_newr   _ensure_matching_resosrO  r   r   r   r   r{   r   rP  )
r   r   rk   rT  r   other_i8r>  
res_valuesrz   new_freqrr   rr   rs   _add_datetimelike_scalarQ  s*   


z/DatetimeLikeArrayMixin._add_datetimelike_scalarc                 C  s6   t | jdstdt| j dt|j ||  S )Nr   rQ  rR  )r   rX  rz   r   r   r   r   rr   rr   rs   _add_datetime_arraylikes  s
   z.DatetimeLikeArrayMixin._add_datetime_arraylikedatetime | np.datetime64c                 C  sZ   | j jdkrtdt| j td| } t|r| t S t|}| 	|\} }| 
|S )Nr   "cannot subtract a datelike from a rk   )rz   r   r   r   r   r   rO   r   r   r[  _sub_datetimelike)r   r   tsrr   rr   rs   _sub_datetimelike_scalar}  s   

z/DatetimeLikeArrayMixin._sub_datetimelike_scalarc                 C  sZ   | j jdkrtdt| j t| t|krtdtd| } | |\} }| 	|S )Nr   rb  $cannot add indices of unequal lengthrk   )
rz   r   r   r   r   r   r   r   r[  rc  r   rr   rr   rs   _sub_datetime_arraylike  s   

z.DatetimeLikeArrayMixin._sub_datetime_arraylikeTimestamp | DatetimeArrayc           
   
   C  s   t d| } ddlm} z| | W n ty- } zt|dd}t|||d }~ww | |\}}t	| j
tj| dd}|d| j d	}| |}	t d
|	}	|j||j|	dS )Nrk   r   rm   comparesubtractrx   r   timedelta64[rU  zTick | NonerW  )r   rY  rm   Z_assert_tzawareness_compatr   ro   replacer   rO  r   r   r   r   r{   r  rP  rZ  rz   )
r   r   rm   r   Znew_messager\  r>  r]  Zres_m8r^  rr   rr   rs   rc    s   


z(DatetimeLikeArrayMixin._sub_datetimeliker   rl   c                 C  s\   t | jdstdt| j ddlm} t	|j
| j}t|j}|||d}||  S )Nr   zcannot add Period to a r   )rl   r   )r   rX  rz   r   r   r   Zpandas.core.arrays.periodrl   r   Zbroadcast_torN  r   rK   r   )r   r   rl   Zi8valsrz   Zparrrr   rr   rs   _add_period  s   
z"DatetimeLikeArrayMixin._add_periodc                 C  r   rp   r   )r   offsetrr   rr   rs   _add_offset  s   z"DatetimeLikeArrayMixin._add_offsetc                 C  sj   t |r tj| jdd| jj}|t t	| j
|| jdS td| } t|}| |\} }| |S )zk
        Add a delta of a timedeltalike

        Returns
        -------
        Same type as self
        rx   r   r  )rO   r   emptyr   r{   r   rz   fillr   r   rZ  r   r   r[  _add_timedeltalike)r   r   
new_valuesrr   rr   rs   _add_timedeltalike_scalar  s   


z0DatetimeLikeArrayMixin._add_timedeltalike_scalarc                 C  s:   t | t |krtdtd| } | |\} }| |S )zl
        Add a delta of a TimedeltaIndex

        Returns
        -------
        Same type as self
        rf  r  )r   r   r   r[  rs  r   rr   rr   rs   _add_timedelta_arraylike  s
   


z/DatetimeLikeArrayMixin._add_timedelta_arraylikeTimedelta | TimedeltaArrayc                 C  s\   t d| } | |\}}t| jtj|dd}|| jj}| 	|}t
| j|| j|dS )Nr  rx   r   rW  )r   rO  r   r   r   r   r{   r   rz   rP  r   rZ  )r   r   r\  r>  rt  r]  r^  rr   rr   rs   rs    s   

z)DatetimeLikeArrayMixin._add_timedeltalikec                 C  sv   t | jtrtdt| j dttj td| } tj	| j
tjd}|t || jj}t| j|| jddS )z$
        Add pd.NaT to self
        zCannot add rR  zTimedeltaArray | DatetimeArrayr   NrW  )ry   rz   rK   r   r   r   r   r   r   rq  r   r   rr  r   r{   r   rZ  r   r   rr   rr   rs   _add_nat  s   

zDatetimeLikeArrayMixin._add_natc                 C  sP   t j| jt jd}|t | jjdv r#td| } |	d| j
 dS |	dS )z+
        Subtract pd.NaT from self
        r   r   zDatetimeArray| TimedeltaArrayrl  rU  ztimedelta64[ns])r   rq  r   r   rr  r   rz   r   r   r{   r  rx  rr   rr   rs   _sub_nat  s   


zDatetimeLikeArrayMixin._sub_natPeriod | PeriodArrayc                   s   t  jtstdt|j dt j td   |  |\}}t	 j
tj| dd}t fdd|D }|d u rG j}n j|B }t||< |S )Ncannot subtract  from rl   rx   r   c                   s   g | ]} j j| qS rr   )r   baser   r   r   rr   rs   
<listcomp>1      z:DatetimeLikeArrayMixin._sub_periodlike.<locals>.<listcomp>)ry   rz   rK   r   r   r   r   r   rO  r   r   r   r   r^   r"  r   )r   r   r\  r>  Znew_i8_dataZnew_datar?  rr   r   rs   _sub_periodlike#  s   


z&DatetimeLikeArrayMixin._sub_periodlikec                 C  s   |t jt jfv s
J t|dkr| jdkr|| |d S tjdt| j dt	t
 d | j|jks:J | j|jf|| dt|}|S )aZ  
        Add or subtract array-like of DateOffset objects

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

        Returns
        -------
        np.ndarray[object]
            Except in fastpath case with length 1 where we operate on the
            contained scalar.
        r   r   z)Adding/subtracting object-dtype array to z not vectorized.r   O)r;  addsubr   r   r   r   r   r   r;   r?   r   r   r   r   )r   r   rq   r]  rr   rr   rs   _addsub_object_array<  s   z+DatetimeLikeArrayMixin._addsub_object_arrayr  namer  c                K  sV   |dvrt d| dt|  tt|}||  fd|i|}t| j|| jdS )N>   ZcummaxZcumminzAccumulation z not supported for r  r   )r   r   r   rW   r   rZ  rz   )r   r  r  r   rq   r   rr   rr   rs   _accumulate`  s
   
z"DatetimeLikeArrayMixin._accumulate__add__c                 C  s  t |dd }t|}|tu r|  }nt|tttjfr"| 	|}nt|t
r-| |}nt|ttjfr;| |}n{t|trMt| jdrM| |}nit|rmt| jts\t| td| }|||jj tj}nIt|dry| |}n=t|r| |tj}n1t|dst|tr|  |S t!|rt| jtst| td| }|||jj tj}nt"S t|tj#rt|jdrddl$m%} |&|S |S )Nrz   r   rl   r   r   ri  )'r   r_   r   ry  ry   r   r   r   r  ru  r   rp  r   r  r_  r   r   rX  rz   rn  
is_integerrK   r'   r   _addsub_int_array_or_scalar_nr;  r  rv  rD   r  rI   r`  rB   NotImplementedndarrayrY  rm   r   r   r   other_dtyper   objrm   rr   rr   rs   r  i  sF   






zDatetimeLikeArrayMixin.__add__c                 C  s
   |  |S rp   )r  r   rr   rr   rs   __radd__  s   
zDatetimeLikeArrayMixin.__radd____sub__c                 C  s  t |dd }t|}|tu r|  }nt|tttjfr#| 	| }nt|t
r/| | }nt|ttjfr=| |}nt|r]t| jtsLt| td| }|||jj tj}nat|trh| |}nVt|dru| | }nIt|r| |tj}n=t|dst|tr|  |}n,t|tr| |}n!t!|rt| jtst| td| }|||jj tj}nt"S t|tj#rt|jdrddl$m%} |&|S |S )Nrz   rl   r   r   r   ri  )'r   r_   r   rz  ry   r   r   r   r  ru  r   rp  r   r  re  r   r  rz   rK   r'   r   r  r  r;  r  r   r  rX  rv  rD   r  rI   rg  rB   r  r  rY  rm   r   r  rr   rr   rs   r    sJ   







zDatetimeLikeArrayMixin.__sub__c                 C  s  t |dd }t|dpt|t}|r9t| jdr9t|r%t||  S t|ts5ddl	m
} ||}||  S | jjdkrVt|drV|sVtdt| j dt|j t| jtrpt|drptdt| j d|j t| jdrtd| } |  | S | |  S )	Nrz   r   r   r   rS  r|  r}  rm   )r   r   rX  ry   rI   rz   r   r   r   rY  rk   r   r   r  r   r   r   rK   r   )r   r   r  Zother_is_dt64rk   rr   rr   rs   __rsub__  s*   





zDatetimeLikeArrayMixin.__rsub__c                 C  s4   | | }|d d  | d d < t | jts|j| _| S rp   ry   rz   rK   r   r   r   r   r   rr   rr   rs   __iadd__  
   zDatetimeLikeArrayMixin.__iadd__c                 C  s4   | | }|d d  | d d < t | jts|j| _| S rp   r  r  rr   rr   rs   __isub__  r  zDatetimeLikeArrayMixin.__isub__qsnpt.NDArray[np.float64]interpolationc                   s   t  j||dS )N)r  r  )r   	_quantile)r   r  r  r   rr   rs   r    s   z DatetimeLikeArrayMixin._quantileaxisr  r  AxisInt | Nonec                K  8   t d| t || j tj| j||d}| ||S )a  
        Return the minimum value of the Array or minimum along
        an axis.

        See Also
        --------
        numpy.ndarray.min
        Index.min : Return the minimum value in an Index.
        Series.min : Return the minimum value in a Series.
        rr   r  )nvZvalidate_minvalidate_minmax_axisr   rR   Znanminr   _wrap_reduction_resultr   r  r  r   r   rr   rr   rs   min     zDatetimeLikeArrayMixin.minc                K  r  )a  
        Return the maximum value of the Array or maximum along
        an axis.

        See Also
        --------
        numpy.ndarray.max
        Index.max : Return the maximum value in an Index.
        Series.max : Return the maximum value in a Series.
        rr   r  )r  Zvalidate_maxr  r   rR   Znanmaxr   r  r  rr   rr   rs   max.  r  zDatetimeLikeArrayMixin.maxr   )r  r  c                C  sF   t | jtrtdt| j dtj| j||| 	 d}| 
||S )a  
        Return the mean value of the Array.

        Parameters
        ----------
        skipna : bool, default True
            Whether to ignore any NaT elements.
        axis : int, optional, default 0

        Returns
        -------
        scalar
            Timestamp or Timedelta.

        See Also
        --------
        numpy.ndarray.mean : Returns the average of array elements along a given axis.
        Series.mean : Return the mean value in a Series.

        Notes
        -----
        mean is only defined for Datetime and Timedelta dtypes, not for Period.

        Examples
        --------
        For :class:`pandas.DatetimeIndex`:

        >>> idx = pd.date_range('2001-01-01 00:00', periods=3)
        >>> idx
        DatetimeIndex(['2001-01-01', '2001-01-02', '2001-01-03'],
                      dtype='datetime64[ns]', freq='D')
        >>> idx.mean()
        Timestamp('2001-01-02 00:00:00')

        For :class:`pandas.TimedeltaIndex`:

        >>> tdelta_idx = pd.to_timedelta([1, 2, 3], unit='D')
        >>> tdelta_idx
        TimedeltaIndex(['1 days', '2 days', '3 days'],
                        dtype='timedelta64[ns]', freq=None)
        >>> tdelta_idx.mean()
        Timedelta('2 days 00:00:00')
        zmean is not implemented for zX since the meaning is ambiguous.  An alternative is obj.to_timestamp(how='start').mean()r  r  r?  )ry   rz   rK   r   r   r   rR   Znanmeanr   rO   r  )r   r  r  r   rr   rr   rs   mean@  s   ,zDatetimeLikeArrayMixin.meanc                K  sH   t d| |d urt|| jkrtdtj| j||d}| ||S )Nrr   z abs(axis) must be less than ndimr  )	r  Zvalidate_medianabsr   r   rR   Z	nanmedianr   r  r  rr   rr   rs   mediany  s
   zDatetimeLikeArrayMixin.mediandropnac                 C  sH   d }|r|   }tj| d|d}|| jj}ttj|}| 	|S )Nrx   )r?  )
rO   rP   moder{   r   rz   r   r   r  r~   )r   r  r?  Zi8modesZnpmodesrr   rr   rs   _mode  s   
zDatetimeLikeArrayMixin._modehowhas_dropped_na	min_countintngroupsidsnpt.NDArray[np.intp]c                K  s  | j }|jdkr)|dv rtd| d|dv r(tjd| d| dtt d	 n2t|trO|dv r:td
| d|dv rNtjd| d| dtt d	 n|dv r[td| d| j	
d}ddlm}	 |	|}
|	||
|d}|j|f|||d d|}|j|jv r|S |j dksJ |dv rddlm} t| j trtdtd| } d| j d}|
|}|j||j dS |
| j	j }| |S )Nr   )sumprodZcumsumcumprodvarskewz!datetime64 type does not support z operations)r$  allr  zh' with datetime64 dtypes is deprecated and will raise in a future version. Use (obj != pd.Timestamp(0)).z() instead.r   zPeriod type does not support ze' with PeriodDtype is deprecated and will raise in a future version. Use (obj != pd.Period(0, freq)).)r  r  r  r  z"timedelta64 type does not support rw   r   )WrappedCythonOp)r  r   r  )r  r  Zcomp_idsr?  )ZstdZsemri  z-'std' and 'sem' are not valid for PeriodDtyper  zm8[rU  r   )rz   r   r   r   r   r   r?   ry   rK   r   r{   Zpandas.core.groupby.opsr  Zget_kind_from_howZ_cython_op_ndim_compatr  Zcast_blocklistrY  rm   r   r  rZ  r~   )r   r  r  r  r  r  r   rz   Znpvaluesr  r   rq   r]  rm   	new_dtyperr   rr   rs   _groupby_op  sl   



	


z"DatetimeLikeArrayMixin._groupby_oprv   r   )NNF)rz   r   r   r   rv   r   )rv   r   )r   ro   rv   r   )r   r   rv   r   )r   r   rv   r   rv   r   )rv   rg   )rv   r   )r   r   rv   r   )F)r   r   )NN)rz   r   r   r   rv   r   )r   r2   rv   r   )r   r   rv   r3   )r   r0   rv   r   )rv   r   )r   r   r   r   rv   r   rv   r   T)r   r   rv   r3   )rz   r   rv   rk   )rz   r   rv   rm   ).)rz   r   rv   r(   rp   )r  r   r  r   )r  r   rv   ro   )r   r   )rv   r  )r   r(   rv   r  )rv   r  )r   r   rv   r   )rv   r*  )rv   r-  rv   ro   )rv   rM  )rv   rk   )r   rk   rv   rk   )r   ra  rv   rm   )r   rk   rv   rm   )r   rh  rv   rm   )r   r   rv   rl   )r   rm   )r   rw  )r   r{  rv   r   )r   r   )r  ro   r  r   rv   r3   )r  r  r  ro   rv   r3   )r  r  r  r   )r  r   r  r  )r  r   )
r  ro   r  r   r  r  r  r  r  r  )`r   
__module____qualname____doc____annotations__r>   r   r   propertyr   r   r   r   r|   r   r   r   r   r   r   r   r   r   r   r   r   r{   r   r  r  r   r  r   r  rZ   r  rT   rO   r"  r%  r   r)  r+  r,  r/  r1  r5  r7  r:  r@  rt   rA  rB  rC  rD  rE  rF  rG  rH  rI  rJ  rK  rL  rO  rP  r_  r`  re  rg  rc  rn  rp  ru  rv  rs  ry  rz  r  r  r  rc   r  r  r  r  r  r  r   r  r  r  r  r  r  r  __classcell__rr   rr   r   rs   r      s  
 





9	(=:U	
9!	

#	
7
7"	9	r   c                   @  s$   e Zd ZdZeddddd	Zd
S )DatelikeOpszK
    Common ops for DatetimeIndex/PeriodIndex, but not TimedeltaIndex.
    zNhttps://docs.python.org/3/library/datetime.html#strftime-and-strptime-behavior)URLr   ro   rv   r   c                 C  sD   | j |tjd}t rddlm} t||tjddS |jtddS )a  
        Convert to Index using specified date_format.

        Return an Index of formatted strings specified by date_format, which
        supports the same string format as the python standard library. Details
        of the string format can be found in `python string format
        doc <%(URL)s>`__.

        Formats supported by the C `strftime` API but not by the python string format
        doc (such as `"%%R"`, `"%%r"`) are not officially supported and should be
        preferably replaced with their supported equivalents (such as `"%%H:%%M"`,
        `"%%I:%%M:%%S %%p"`).

        Note that `PeriodIndex` support additional directives, detailed in
        `Period.strftime`.

        Parameters
        ----------
        date_format : str
            Date format string (e.g. "%%Y-%%m-%%d").

        Returns
        -------
        ndarray[object]
            NumPy ndarray of formatted strings.

        See Also
        --------
        to_datetime : Convert the given argument to datetime.
        DatetimeIndex.normalize : Return DatetimeIndex with times to midnight.
        DatetimeIndex.round : Round the DatetimeIndex to the specified freq.
        DatetimeIndex.floor : Floor the DatetimeIndex to the specified freq.
        Timestamp.strftime : Format a single Timestamp.
        Period.strftime : Format a single Period.

        Examples
        --------
        >>> rng = pd.date_range(pd.Timestamp("2018-03-10 09:00"),
        ...                     periods=3, freq='s')
        >>> rng.strftime('%%B %%d, %%Y, %%r')
        Index(['March 10, 2018, 09:00:00 AM', 'March 10, 2018, 09:00:01 AM',
               'March 10, 2018, 09:00:02 AM'],
              dtype='object')
        )r   r   r   )StringDtyper   r   Fr   )	r   r   r&  r   r  r  r  r   r   )r   r   r   r  rr   rr   rs   strftime  s
   1zDatelikeOps.strftimeN)r   ro   rv   r   )r   r  r  r  r=   r  rr   rr   rr   rs   r    s    r  aO	  
    Perform {op} operation on the data to the specified `freq`.

    Parameters
    ----------
    freq : str or Offset
        The frequency level to {op} the index to. Must be a fixed
        frequency like 'S' (second) not 'ME' (month end). See
        :ref:`frequency aliases <timeseries.offset_aliases>` for
        a list of possible `freq` values.
    ambiguous : 'infer', bool-ndarray, 'NaT', default 'raise'
        Only relevant for DatetimeIndex:

        - 'infer' will attempt to infer fall dst-transition hours based on
          order
        - bool-ndarray where True signifies a DST time, False designates
          a non-DST time (note that this flag is only applicable for
          ambiguous times)
        - 'NaT' will return NaT where there are ambiguous times
        - 'raise' will raise an AmbiguousTimeError if there are ambiguous
          times.

    nonexistent : 'shift_forward', 'shift_backward', 'NaT', timedelta, default 'raise'
        A nonexistent time does not exist in a particular timezone
        where clocks moved forward due to DST.

        - 'shift_forward' will shift the nonexistent time forward to the
          closest existing time
        - 'shift_backward' will shift the nonexistent time backward to the
          closest existing time
        - 'NaT' will return NaT where there are nonexistent times
        - timedelta objects will shift nonexistent times by the timedelta
        - 'raise' will raise an NonExistentTimeError if there are
          nonexistent times.

    Returns
    -------
    DatetimeIndex, TimedeltaIndex, or Series
        Index of the same type for a DatetimeIndex or TimedeltaIndex,
        or a Series with the same index for a Series.

    Raises
    ------
    ValueError if the `freq` cannot be converted.

    Notes
    -----
    If the timestamps have a timezone, {op}ing will take place relative to the
    local ("wall") time and re-localized to the same timezone. When {op}ing
    near daylight savings time, use ``nonexistent`` and ``ambiguous`` to
    control the re-localization behavior.

    Examples
    --------
    **DatetimeIndex**

    >>> rng = pd.date_range('1/1/2018 11:59:00', periods=3, freq='min')
    >>> rng
    DatetimeIndex(['2018-01-01 11:59:00', '2018-01-01 12:00:00',
                   '2018-01-01 12:01:00'],
                  dtype='datetime64[ns]', freq='min')
    a  >>> rng.round('h')
    DatetimeIndex(['2018-01-01 12:00:00', '2018-01-01 12:00:00',
                   '2018-01-01 12:00:00'],
                  dtype='datetime64[ns]', freq=None)

    **Series**

    >>> pd.Series(rng).dt.round("h")
    0   2018-01-01 12:00:00
    1   2018-01-01 12:00:00
    2   2018-01-01 12:00:00
    dtype: datetime64[ns]

    When rounding near a daylight savings time transition, use ``ambiguous`` or
    ``nonexistent`` to control how the timestamp should be re-localized.

    >>> rng_tz = pd.DatetimeIndex(["2021-10-31 03:30:00"], tz="Europe/Amsterdam")

    >>> rng_tz.floor("2h", ambiguous=False)
    DatetimeIndex(['2021-10-31 02:00:00+01:00'],
                  dtype='datetime64[ns, Europe/Amsterdam]', freq=None)

    >>> rng_tz.floor("2h", ambiguous=True)
    DatetimeIndex(['2021-10-31 02:00:00+02:00'],
                  dtype='datetime64[ns, Europe/Amsterdam]', freq=None)
    a  >>> rng.floor('h')
    DatetimeIndex(['2018-01-01 11:00:00', '2018-01-01 12:00:00',
                   '2018-01-01 12:00:00'],
                  dtype='datetime64[ns]', freq=None)

    **Series**

    >>> pd.Series(rng).dt.floor("h")
    0   2018-01-01 11:00:00
    1   2018-01-01 12:00:00
    2   2018-01-01 12:00:00
    dtype: datetime64[ns]

    When rounding near a daylight savings time transition, use ``ambiguous`` or
    ``nonexistent`` to control how the timestamp should be re-localized.

    >>> rng_tz = pd.DatetimeIndex(["2021-10-31 03:30:00"], tz="Europe/Amsterdam")

    >>> rng_tz.floor("2h", ambiguous=False)
    DatetimeIndex(['2021-10-31 02:00:00+01:00'],
                 dtype='datetime64[ns, Europe/Amsterdam]', freq=None)

    >>> rng_tz.floor("2h", ambiguous=True)
    DatetimeIndex(['2021-10-31 02:00:00+02:00'],
                  dtype='datetime64[ns, Europe/Amsterdam]', freq=None)
    a  >>> rng.ceil('h')
    DatetimeIndex(['2018-01-01 12:00:00', '2018-01-01 12:00:00',
                   '2018-01-01 13:00:00'],
                  dtype='datetime64[ns]', freq=None)

    **Series**

    >>> pd.Series(rng).dt.ceil("h")
    0   2018-01-01 12:00:00
    1   2018-01-01 12:00:00
    2   2018-01-01 13:00:00
    dtype: datetime64[ns]

    When rounding near a daylight savings time transition, use ``ambiguous`` or
    ``nonexistent`` to control how the timestamp should be re-localized.

    >>> rng_tz = pd.DatetimeIndex(["2021-10-31 01:30:00"], tz="Europe/Amsterdam")

    >>> rng_tz.ceil("h", ambiguous=False)
    DatetimeIndex(['2021-10-31 02:00:00+01:00'],
                  dtype='datetime64[ns, Europe/Amsterdam]', freq=None)

    >>> rng_tz.ceil("h", ambiguous=True)
    DatetimeIndex(['2021-10-31 02:00:00+02:00'],
                  dtype='datetime64[ns, Europe/Amsterdam]', freq=None)
    c                      s  e Zd ZU dZded< dejdfded
dZedd Z	e
dd ZejdfddZedgddZeedhddZediddZedjdd Zedkd"d#Zdldmd'd(Zd)d* Zdn fd.d/Zd0d1 Zeee jd2d3	4	4dodpd9d:Zeee jd;d3	4	4dodpd<d=Zeee jd>d3	4	4dodpd?d@Z dd$dAdqdEdFZ!dd$dAdqdGdHZ"dfdIdJZ#drdKdLZ$ds fdNdOZ%	$	dtdu fdRdSZ&e	Tdvdw fdXdYZ'dxdy fd\d]Z(dzdadbZ)e
d{dcddZ*  Z+S )|r=  zK
    Common ops for TimedeltaIndex/DatetimeIndex, but not PeriodIndex.
    znp.dtype_default_dtypeNFr   r   rv   r   c           	      C  s  t jt| j dtt d |d urt|}t|dd}t|t	r)|j
dtd}t|dd }|d u }|tjur:|nd }t|t| rx|rFn|d u rN|j}n|r]|jr]t|}t||j}|d urq||jkrqtd| d	|j |j}|j}n'|d u rt|tjr|jjd
v r|j}n| j}t|tjr|jdkr||}t|tjstdt|j dt| j d|jdvrtd|jdkr|d u r| j}|| j}n#t|dr||}nt|tr| jj}| d|j d}||}| ||}|dkrtdt| j d|r|  }|r*t|}|jjdkr*t|t!s*tdt"j#| ||d || _$|d u rI|d urKt| %| | d S d S d S )NzV.__init__ is deprecated and will be removed in a future version. Use pd.array instead.r   Tr	  r   r  r   dtype=z does not match data dtype ZMmrx   zUnexpected type 'z'. 'values' must be a z6, ndarray, or Series or Index containing one of those.)r      z.Only 1-dimensional input arrays are supported.r   8[rU  inferz#Frequency inference not allowed in z$.__init__. Use 'pd.array()' instead.r   (TimedeltaArray/Index freq must be a Tick)r   rz   )&r   r   r   r   r   r?   rF   r`   ry   r]   r  r   r   r   
no_defaultr   r"   _validate_inferred_freqrz   r   r   r   r  r   r  r{   r   r   rX  rI   r  _validate_dtyper   r   r   r   r   _validate_frequency)	r   r   rz   r   r   r,  Zexplicit_noner   r  rr   rr   rs   r     s   







zTimelikeOps.__init__c                 C  r   rp   r   )r   r   rz   rr   rr   rs   r    s   zTimelikeOps._validate_dtypec                 C  r!  )zK
        Return the frequency object if it is set, otherwise None.
        r   r   rr   rr   rs   r     s   zTimelikeOps.freqc                 C  sV   |d ur&t |}| | | | jjdkrt|tstd| jdkr&td|| _	d S )Nr   r  r   zCannot set freq with ndim > 1)
r"   r  rz   r   ry   r   r   r   r   r   r   rr   rr   rs   r     s   

validate_kwdsdictc                 C  s   |du r	d| _ dS |dkr| j du rt| j| _ dS dS |tju r#dS | j du r=t|}t| j| |fi | || _ dS t|}t|| j  dS )z
        Constructor helper to pin the appropriate `freq` attribute.  Assumes
        that self._freq is currently set to any freq inferred in
        _from_sequence_not_strict.
        Nr  )r   r"   r,  r   r  r   r  r  )r   r   r  rr   rr   rs   _maybe_pin_freq*  s   




zTimelikeOps._maybe_pin_freqr   r   c              
   K  s   |j }|jdks||jkrdS z | jd|d dt|||jd|}t|j|js-t	W dS  t	yO } zdt
|v r?|t	d| d|j |d}~ww )am  
        Validate that a frequency is compatible with the values of a given
        Datetime Array/Index or Timedelta Array/Index

        Parameters
        ----------
        index : DatetimeIndex or TimedeltaIndex
            The index on which to determine if the given frequency is valid
        freq : DateOffset
            The frequency to validate
        r   N)startendperiodsr   r  z	non-fixedInferred frequency 9 from passed values does not conform to passed frequency rr   )r,  r9  r+  _generate_ranger   r  r   Zarray_equalr   r   ro   )r   indexr   r   r   Zon_freqr   rr   rr   rs   r  K  s8   zTimelikeOps._validate_frequencyr  
int | Noner3   c                 O  r   rp   r   )r   r  r  r  r   r   r   rr   rr   rs   r  w  r   zTimelikeOps._generate_ranger  c                 C  s   t | jjS rp   )r   r   rz   r   rr   rr   rs   r     s   zTimelikeOps._cresoro   c                 C  s
   t | jS rp   )dtype_to_unitrz   r   rr   rr   rs   r    r#  zTimelikeOps.unitTr  r  c                 C  s~   |dvrt dt| jj d| d}t| j||d}t| jtjr(|j}ntd| j}t	||d}t
| j||| jdS )	N)smsusnsz)Supported units are 's', 'ms', 'us', 'ns'r  rU  r  rk   rV  rW  )r   r   rz   r   r   r   ry   r   r   rI   r   rZ  r   )r   r  r  rz   rt  r  r   rr   rr   rs   r
    s   zTimelikeOps.as_unitc                 C  s@   | j |j kr| j |j k r| |j} | |fS || j}| |fS rp   )r   r
  r  r   rr   rr   rs   r[    s   z"TimelikeOps._ensure_matching_resosufuncnp.ufuncmethodc                   s`   |t jt jt jfv r"t|dkr"|d | u r"t||| jfi |S t j||g|R i |S )Nr   r   )	r   isnanisinfisfiniter   r   r   r   __array_ufunc__)r   r  r  Zinputsr   r   rr   rs   r    s
   zTimelikeOps.__array_ufunc__c           
      C  s   t | jtr!td| } | d }|||||}|j| j||dS | d}ttj	|}t
|| j}|dkr:|  S t|||}	| j|	td}|| jj}| j|| jdS )Nrk   )	ambiguousnonexistentrx   r   r(  r   )ry   rz   rI   r   Ztz_localize_roundr   r{   r   r  r&   r   r   r$   r)  r   r   rZ  )
r   r   r  r  r  Znaiver   r   ZnanosZ	result_i8rr   rr   rs   r    s    


zTimelikeOps._roundround)rq   raiser  r5   r  r6   c                 C     |  |tj||S rp   )r  r#   ZNEAREST_HALF_EVENr   r   r  r  rr   rr   rs   r       zTimelikeOps.roundfloorc                 C  r  rp   )r  r#   ZMINUS_INFTYr  rr   rr   rs   r    r  zTimelikeOps.floorceilc                 C  r  rp   )r  r#   Z
PLUS_INFTYr  rr   rr   rs   r    r  zTimelikeOps.ceilr  r  r  r  c                C     t j| j|||  dS Nr  )rR   Znananyr   rO   r   r  r  rr   rr   rs   r$    s   zTimelikeOps.anyc                C  r  r  )rR   Znanallr   rO   r   rr   rr   rs   r    s   zTimelikeOps.allc                 C  s
   d | _ d S rp   r  r   rr   rr   rs   r     s   
zTimelikeOps._maybe_clear_freqc                 C  sh   |du rn&t | dkr t|tr | jjdkrt|tstdn|dks&J t| j}| 	 }||_
|S )z
        Helper to get a view on the same data, with a new freq.

        Parameters
        ----------
        freq : DateOffset, None, or "infer"

        Returns
        -------
        Same type as self
        Nr   r   r  r  )r   ry   r   rz   r   r   r   r"   r,  r{   r   )r   r   r   rr   rr   rs   
_with_freq  s   
zTimelikeOps._with_freqr   c                   s   t | jtjr
| jS t  S rp   )ry   rz   r   r   r   _values_for_jsonr   r   rr   rs   r  	  s   
zTimelikeOps._values_for_jsonuse_na_sentinelsortc                   s   | j d ur-tjt| tjd}|  }|r)| j jdk r)|d d d }|d d d }||fS |r:tdt| j	 dt
 j|dS )Nr   r   zThe 'sort' keyword in zu.factorize is ignored unless arr.freq is not None. To factorize with sort, call pd.factorize(obj, sort=True) instead.)r  )r   r   Zaranger   Zintpr   r   NotImplementedErrorr   r   r   	factorize)r   r  r  codesZuniquesr   rr   rs   r  	  s   
zTimelikeOps.factorizer   	to_concatSequence[Self]r)   c                   s   t  ||}|d  |dkrDdd |D } jd urDt fdd|D rDt|d d |dd  }t fdd|D rD j}||_|S )	Nr   c                 S  s   g | ]}t |r|qS rr   )r   r  rr   rr   rs   r  C	  r  z1TimelikeOps._concat_same_type.<locals>.<listcomp>c                 3  s    | ]	}|j  j kV  qd S rp   r   r  r  rr   rs   r   E	  s    z0TimelikeOps._concat_same_type.<locals>.<genexpr>r  r   c                 3  s.    | ]}|d  d  j  |d d  kV  qdS )r   r  r   Nr  )r   pairr  rr   rs   r   G	  s   , )r   _concat_same_typer   r  zipr   )r   r	  r  new_objpairsr^  r   r  rs   r  6	  s    zTimelikeOps._concat_same_typeCorderc                   s   t  j|d}| j|_|S )N)r  )r   r   r   r   )r   r  r  r   rr   rs   r   L	  s   zTimelikeOps.copyr.   r  rj   c          
   	   K  s^   |dkrt |s| j}	n| j }	tj|	f||||||d| |s%| S t| j|	| jdS )z2
        See NDFrame.interpolate.__doc__.
        Zlinear)r  r  r  limitlimit_direction
limit_arear   )r  r   r   rQ   Zinterpolate_2d_inplacer   rZ  rz   )
r   r  r  r  r  r  r  r   r   Zout_datarr   rr   rs   interpolateQ	  s(   

zTimelikeOps.interpolatec                 C  sP   t | jsdS | j}|tk}t| j}t|}t||| dk	 dk}|S )z
        Check if we are round times at midnight (and no timezone), which will
        be given a more compact __repr__ than other cases. For TimedeltaArray
        we are checking for multiples of 24H.
        Fr   )
r   rX  rz   r   r   r   r!   r   logical_andr  )r   Z
values_intZconsider_valuesr   ZppdZ	even_daysrr   rr   rs   _is_dates_onlyz	  s   
zTimelikeOps._is_dates_only)r   r   rv   r   r  )r  r  )r   r   )r  r  rv   r3   )rv   r  r  r  )r  ro   r  r   rv   r3   )r  r  r  ro   )r  r  )r  r5   r  r6   rv   r3   )r  r  r  r   rv   r   r  r  )TF)r  r   r  r   )r   )r	  r
  r  r)   rv   r3   )r  )r  ro   rv   r3   )
r  r.   r  r  r  rj   r   r   rv   r3   r  ),r   r  r  r  r  r   r  r   classmethodr  r  r   setterr   r  r  r  r>   r   r  r
  r[  r  r  r<   
_round_doc_round_exampler   r  _floor_exampler  _ceil_exampler  r$  r  r   r  r  r  r  r   r  r  r  rr   rr   r   rs   r=    sj   
 \

 *

 
)r=  r   r   cls_nametuple[ArrayLike, bool]c                 C  s  t | dst| ttfst| dkrt| } t| } d}nt| tr+td| dt	| dd} t| t
sAt| trN| jjdv rN| jd	td
} d}| |fS t| tra|  } |  } d}| |fS t| tjtfsrt| } | |fS t| tr| jj| jtdj} d}| |fS )Nrz   r   FzCannot create a z from a MultiIndex.Tr	  r   r   r  r  )r  ry   r   tupler   r   r@   rM   r   r`   r]   r[   rz   r   r  r   Z_maybe_convert_datelike_arrayr  r\   r   rL   r  Ztaker  r   _values)r   r   r   rr   rr   rs   !ensure_arraylike_for_datetimelike	  s6   




	
r$  r  r   c                 C  r   rp   rr   r  rr   rr   rs   validate_periods	  r   r&  int | floatr  c                 C  r   rp   rr   r%  rr   rr   rs   r&  	  r   int | float | Noner  c                 C  sL   | dur$t | rtjdtt d t| } | S t | s$td|  | S )a9  
    If a `periods` argument is passed to the Datetime/Timedelta Array/Index
    constructor, cast it to an integer.

    Parameters
    ----------
    periods : None, float, int

    Returns
    -------
    periods : None or int

    Raises
    ------
    TypeError
        if periods is None, float, or int
    NzNon-integer 'periods' in pd.date_range, pd.timedelta_range, pd.period_range, and pd.interval_range are deprecated and will raise in a future version.r   zperiods must be a number, got )	r   Zis_floatr   r   r   r?   r  r  r   r%  rr   rr   rs   r&  	  s   

r   r   r,  c                 C  s>   |dur| dur| |krt d| d| j | du r|} | S )a
  
    If the user passes a freq and another freq is inferred from passed data,
    require that they match.

    Parameters
    ----------
    freq : DateOffset or None
    inferred_freq : DateOffset or None

    Returns
    -------
    freq : DateOffset or None
    Nr  r  )r   r+  )r   r,  rr   rr   rs   r  	  s   r  rz   'DatetimeTZDtype | np.dtype | ArrowDtypec                 C  sJ   t | tr| jS t | tr| jdvrtd| d| jjS t| d S )z
    Return the unit str corresponding to the dtype's resolution.

    Parameters
    ----------
    dtype : DatetimeTZDtype or np.dtype
        If np.dtype, we assume it is a datetime64 dtype.

    Returns
    -------
    str
    r   r  z does not have a resolution.r   )	ry   rI   r  rG   r   r   Zpyarrow_dtyper   Zdatetime_datar   rr   rr   rs   r  
  s   


r  )rn   ro   )ru   r-   rv   r-   )r   r   r   ro   rv   r!  )r  r   rv   r   )r  r'  rv   r  )r  r(  rv   r  )r   r   r,  r   rv   r   )rz   r)  rv   ro   )
__future__r   r   r   	functoolsr   r;  typingr   r   r   r	   r
   r   r   r   r   numpyr   Zpandas._configr   Zpandas._libsr   r   Zpandas._libs.arraysr   Zpandas._libs.tslibsr   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   Zpandas._libs.tslibs.fieldsr#   r$   Zpandas._libs.tslibs.np_datetimer%   Zpandas._libs.tslibs.timedeltasr&   Zpandas._libs.tslibs.timestampsr'   Zpandas._typingr(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   Zpandas.compat.numpyr8   r  Zpandas.errorsr9   r:   r;   Zpandas.util._decoratorsr<   r=   r>   Zpandas.util._exceptionsr?   Zpandas.core.dtypes.castr@   Zpandas.core.dtypes.commonrA   rB   rC   rD   rE   rF   Zpandas.core.dtypes.dtypesrG   rH   rI   rJ   rK   Zpandas.core.dtypes.genericrL   rM   Zpandas.core.dtypes.missingrN   rO   Zpandas.corerP   rQ   rR   rS   Zpandas.core.algorithmsrT   rU   rV   Zpandas.core.array_algosrW   Zpandas.core.arraylikerX   Zpandas.core.arrays._mixinsrY   rZ   Zpandas.core.arrays.arrow.arrayr[   Zpandas.core.arrays.baser\   Zpandas.core.arrays.integerr]   Zpandas.core.commoncorecommonr   Zpandas.core.constructionr^   r  r_   r`   Zpandas.core.indexersra   rb   Zpandas.core.ops.commonrc   Zpandas.core.ops.invalidrd   re   Zpandas.tseriesrf   collections.abcrg   rh   r  rj   rY  rk   rl   rm   r   rt   r   r   r  r  r  r  r  r=  r$  r&  r  r  rr   rr   rr   rs   <module>   s    (
LH 


            &>?   
h'

"