
    Pi|                      U 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mZ d dlZd dl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 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/m0Z0m1Z1 d dl2m3Z3 d dl4m5Z5 d dl6m7Z7 d dl8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEmFZFmGZGmHZH d dlImJZK d dlLmMZMmNZNmOZO d dlPmQZQ d dlRmSZS d dlTmUZU d dlVmWZWmXZXmYZYmZZZm[Z[m\Z\ d dl]m^Z^m_Z_m`Z`maZambZb d dlcmdZdmeZe d dlfmgZgmhZh d dlimjZjmkZkmlZlmmZm d dlnmoZompZpmqZq d dlrmsZs d dltmuZu d dlvmwZwmxZx d dlymzZz d dl{m|Z| d dl}m~Z~ d dlmc mZ d d lmZmZmZ d d!lmZmZ d d"lmZ d d#lmZmZ d d$lmZ er d d%lmZmZmZ d d&l8mZ d d'lmZ d d(lmZmZmZ e;e z  Zd)ed*<   dKd-ZdLd1Z G d2 d3euew          Z G d4 d5e          Z G d6 d7e          ZdMd<ZedNd?            ZedOdA            ZdPdCZdQdGZdRdJZdS )S    )annotations)datetime	timedelta)wrapsN)	TYPE_CHECKINGAnyLiteralSelf	TypeAliasUnioncastfinaloverload)using_string_dtype)
get_option)algoslib)
BaseOffsetDay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	timezones	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SequenceIndexerTakeIndexerTimeAmbiguousTimeNonexistentnpt)function)AbstractMethodErrorInvalidComparisonPerformanceWarning)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)CallableIteratorSequence)TimeUnitIndex)DatetimeArrayPeriodArrayTimedeltaArrayr   DTScalarOrNaTop_namestrc                P    t          |           } t          |           |          S N)rg   re   )rs   ops     s/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/pandas/core/arrays/datetimelike.py_make_unpacked_invalid_opry      s(    		!	!B,#G,,R000    methr1   returnc                b     t                      f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                d   t          | j        t                    s | g|R i |S |                     d          } |g|R i |}|t          u rt          S t          |t
                    r|                     |j                  S |                    d          }|                     |          S )NM8[ns]i8)	
isinstancedtyperM   viewr   r   	_box_func_value_from_backing_data)selfargskwargsarrresultres_i8r{   s         rx   new_methz"_period_dispatch.<locals>.new_meth   s    $*k22 	/4.t...v...ii!!c+D+++F++S==J	** 	1>>&-000T""&&v...rz   )r   r   r1   )r{   r   s   ` rx   _period_dispatchr      s@     4[[/ / / / [/ 8rz   c                      e Zd ZU dZded<   ded<   ded<   ded	<   d
ed<   edd            Z	 dddZedd            Z	ddZ
ddZddZd  Zdd!Zdd#Zedd%            Zd&dd'dd+Zddd.Z	 ddd1Zedd4            Zedd7            Zdƈ fd:Zdd;ZdȈ fd>Zdd?Zddˈ fdAZeddB            ZeddE            ZeddH            ZedddK            ZddЈ fdLZd҈ fdOZdP Zdd@dQddTZdddUZdddWZdX Z e!ddZ            Z"e#ddd]            Z$dd_Z%dd`Z&edda            Z'eddb            Z(e)dfdddZ*eddf            Z+eddg            Z,eddi            Z-eddj            Z.eddk            Z/eddl            Z0eddm            Z1dn Z2 e3do          Z4 e3dp          Z5 e3dq          Z6 e3dr          Z7 e3ds          Z8 e3dt          Z9 e3du          Z: e3dv          Z; e3dw          Z< e3dx          Z= e3dy          Z> e3dz          Z?e!dd|            Z@e!dd}            ZAe!dd~            ZBe!dd            ZCe!dd            ZDe!dd            ZEe!dd            ZFe!dd            ZGd ZHd ZIddZJe!dd            ZKe!dd            ZLe!dd            ZMe!dd            ZNe!dd            ZOd@dddZP eQd          d             ZRd ZS eQd          d             ZTd ZUddZVddZWeXd fd            ZYeXdd@ddd            ZZeXdd@ddd            Z[d@ddddZ\eXdd@ddd            Z]dddZ^ddZ_ x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freqr|   boolc                    dS )NT r   s    rx   _can_hold_naz#DatetimeLikeArrayMixin._can_hold_na   s    trz   NFr   Dtype | NonecopyNonec                     t          |           rv   r=   )r   datar   r   r   s        rx   __init__zDatetimeLikeArrayMixin.__init__   s     "$'''rz   type[DatetimeLikeScalar]c                     t          |           )z
        The scalar associated with this datelike

        * PeriodArray : Period
        * DatetimeArray : Timestamp
        * TimedeltaArray : Timedelta
        r   r   s    rx   _scalar_typez#DatetimeLikeArrayMixin._scalar_type   s     "$'''rz   valuert   rr   c                     t          |           )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   s     rx   _scalar_from_stringz*DatetimeLikeArrayMixin._scalar_from_string       $ "$'''rz   )np.int64 | np.datetime64 | np.timedelta64c                     t          |           )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])
        np.datetime64('1970-01-01T00:00:00.000000000')
        r   r   s     rx   _unbox_scalarz$DatetimeLikeArrayMixin._unbox_scalar  s    * "$'''rz   otherc                     t          |           )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   s     rx   _check_compatible_withz-DatetimeLikeArrayMixin._check_compatible_with  r   rz   c                     t          |           )zI
        box function to get object from internal representation
        r   )r   xs     rx   r   z DatetimeLikeArrayMixin._box_func/  s     "$'''rz   c                :    t          j        || j        d          S )z1
        apply box func to passed values
        F)convert)r   	map_inferr   r   valuess     rx   _box_valuesz"DatetimeLikeArrayMixin._box_values5  s     }VT^UCCCCrz   rj   c                      j         dk    r( fdt          t                               D             S  fd j        D             S )N   c              3  (   K   | ]}|         V  d S rv   r   ).0nr   s     rx   	<genexpr>z2DatetimeLikeArrayMixin.__iter__.<locals>.<genexpr>=  s'      66DG666666rz   c              3  B   K   | ]}                     |          V  d S rv   )r   )r   vr   s     rx   r   z2DatetimeLikeArrayMixin.__iter__.<locals>.<genexpr>?  s/      99!DNN1%%999999rz   )ndimrangelenasi8r   s   `rx   __iter__zDatetimeLikeArrayMixin.__iter__;  sR    9q==6666U3t99%5%566669999ty9999rz   npt.NDArray[np.int64]c                6    | j                             d          S )z
        Integer representation of the values.

        Returns
        -------
        ndarray
            An ndarray with int64 dtype.
        r   )r   r   r   s    rx   r   zDatetimeLikeArrayMixin.asi8A  s     }!!$'''rz   r   )na_repdate_formatr   str | floatnpt.NDArray[np.object_]c                    t          |           )z|
        Helper method for astype when converting to strings.

        Returns
        -------
        ndarray[str]
        r   )r   r   r   s      rx   _format_native_typesz+DatetimeLikeArrayMixin._format_native_typesQ  s     "$'''rz   boxedCallable[[object], str]c                    dj         S )Nz'{}')format)r   r   s     rx   
_formatterz!DatetimeLikeArrayMixin._formatter]  s
    }rz   NpDtype | Nonebool | Nonec                4   t          |          r;|du rt          d          t          j        t	          |           t
                    S |du rt          j        | j        |          S | j        }| j        r |                                }d|j	        _
        |S )NFz:Unable to avoid copy while creating an array as requested.r   T)rF   
ValueErrornpr`   listobjectr   	_readonlyr   flags	writeable)r   r   r   r   s       rx   	__array__z DatetimeLikeArrayMixin.__array__d  s     5!! 	6u}} P   8DJJf55554<<8DM7777> 	+[[]]F%*FL"rz   keyr6   c                    d S rv   r   r   r   s     rx   __getitem__z"DatetimeLikeArrayMixin.__getitem__x      @Crz   (SequenceIndexer | PositionalIndexerTupler
   c                    d S rv   r   r   s     rx   r   z"DatetimeLikeArrayMixin.__getitem__{  s	     srz   r4   Self | DTScalarOrNaTc                   t          t          t          t          f         t	                                          |                    }t          j        |          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
        )
r   r   r
   rr   superr   r   	is_scalar_get_getitem_freq_freq)r   r   r   	__class__s      rx   r   z"DatetimeLikeArrayMixin.__getitem__  st     eD-/0%''2E2Ec2J2JKK=   	(M $''F --c22rz   c                   t          | j        t                    }|r| j        }n| j        dk    rd}nt          | |          }d}t          |t                    r&| j        |j        |j        | j        z  }n| j        }n|t          u r| j        }not          j
        |          r[t          j        |                    t          j                            }t          |t                    r|                     |          S |S )z\
        Find the `freq` attribute to assign to the result of a __getitem__ lookup.
        r   N)r   r   rM   r   r   rc   slicestepEllipsiscomis_bool_indexerr   maybe_booleans_to_slicer   r   uint8r   )r   r   	is_periodr   new_keys        rx   r   z(DatetimeLikeArrayMixin._get_getitem_freq  s     tz;77	 	;9DDY!^^DD%dC00CD#u%% ;9(SX-A8di/DD9DD y$S)) ;5chhrx6H6HIIgu-- ;11':::rz   ,int | Sequence[int] | Sequence[bool] | sliceNaTType | Any | Sequence[Any]c                    t          |||           }t                                          ||           |rd S |                                  d S rv   )rd   r   __setitem___maybe_clear_freq)r   r   r   no_opr   s       rx   r   z"DatetimeLikeArrayMixin.__setitem__  sW     &c5$77 	C''' 	F     rz   c                    d S rv   r   r   s    rx   r   z(DatetimeLikeArrayMixin._maybe_clear_freq  s	     	rz   Tc                h   t          |          }|t          k    r| j        j        dk    r6t	          d|           } | j        }t          || j        d| j                  }|S | j        j        dk    rt          | j
        d          S |                     | j                                                                      | j                  S t          |          rpt!          |t"                    rG|                     |j                  }|                                }|                    ||d	
          S |                                 S t!          |t"                    r#t-                                          ||          S |j        dv rJ| j        }|t0          j        k    rt5          d| j         d| d          |r|                                }|S |j        dv r| j        |k    s|j        dk    r)dt9          |           j         d| }t5          |          t1          j        | |          S )NMro   	timestamp)tzboxresomT)r  )r   F)r   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   )rH   r   r   kindr   r   r"   r  _cresor#   r   r   ravelreshapeshaperG   r   rL   r   na_valueconstruct_array_type_from_sequencer   astyper   int64	TypeErrorr   type__name__asarray)
r   r   r   i8data	converted
arr_objectclsr   msgr   s
            rx   r  zDatetimeLikeArrayMixin.astype  sH   
 U##F??z#%%OT22 .w#	  	 ! C''*4=dCCCC##DIOO$5$566>>tzJJJU## 	1%00 3!66en6MM
0022))*E)NNN00222~.. 	177>>%d>333Z4 YF  Ctz C Cu C C C  
  'MjD  TZ5%8%8UZ3=N=N Hd!4GGGGCC.. :d%0000rz   c                    d S rv   r   r   s    rx   r   zDatetimeLikeArrayMixin.view  s    Crz   Literal['M8[ns]']ro   c                    d S rv   r   r   r   s     rx   r   zDatetimeLikeArrayMixin.view	  s    ?Bsrz   Literal['m8[ns]']rq   c                    d S rv   r   r!  s     rx   r   zDatetimeLikeArrayMixin.view  r   rz   .r,   c                    d S rv   r   r!  s     rx   r   zDatetimeLikeArrayMixin.view  s    <?Crz   c                F    t                                          |          S rv   )r   r   )r   r   r   s     rx   r   zDatetimeLikeArrayMixin.view  s     ww||E"""rz   masknpt.NDArray[np.bool_]c                Z    t                                          ||           d | _        d S rv   )r   _putmaskr   )r   r&  r   r   s      rx   r)  zDatetimeLikeArrayMixin._putmask  s(    u%%%


rz   c                
   t          |t                    r@	 |                     |          }n)# t          t          f$ r}t          |          |d }~ww xY wt          || j                  s	|t          u rN|                     |          }	 | 	                    |           n# t          $ r}t          |          |d }~ww xY wt          |          st          |          t          |          t          |           k    rt          d          	 |                     |d          }| 	                    |           nF# t          $ r9}t          t          |dd                     rnt          |          |Y d }~nd }~ww xY w|S )NzLengths must matchT)allow_objectr   )r   rt   r   r   r   r>   r   r   r   r   r  rE   r   _validate_listlikerF   getattr)r   r   errs      rx   _validate_comparison_valuez1DatetimeLikeArrayMixin._validate_comparison_value  s   eS!! 	880077 56 8 8 8'..C78 eT566 	<%3,,%%e,,E8++E2222 8 8 8'..C78 e$$ 	<#E***ZZ3t99$$1222<//D/II++E2222 < < <"75'4#@#@AA <+E22; DDDD< sD   - AAA
B   
B?*B::B?,D= =
F /E;;F )allow_listlikeunboxr0  r1  c               l   t          || j                  rnt          |t                    rO	 |                     |          }n# t          $ r+}|                     ||          }t          |          |d}~ww xY wt          || j                  rt          }nt          |          r%|                     ||          }t          |          t          || j                  r|                     |          }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)r   r   rt   r   r   _validation_error_messager  rP   r   r   rQ   r   r   )r   r   r0  r1  r.  r  s         rx   _validate_scalarz'DatetimeLikeArrayMixin._validate_scalarC  sJ   0 eT.// 	!s## 	!.0077 . . .44UNKKnn#-. #5$*55 	!EE%[[ 	! 00GGCC.. t788 	! %%e,,EE 00GGCC..  	 L!!%(((s   A 
A9&A44A9c                    t          |d          r t          |dd          dk    r|j         d}ndt          |          j         d}|rd| j        j         d| d}n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
        r   r   r   z array'zvalue should be a 'z!', 'NaT', or array of those. Got z	 instead.z' or 'NaT'. Got )hasattrr-  r   r  r  r   )r   r   r0  msg_gotr  s        rx   r3  z0DatetimeLikeArrayMixin._validation_error_message  s     5'"" 	2wufa'@'@1'D'D,,,GG1$u++.111G 		=d&7&@ = =*1= = = C*d&7&@ * ** * *  
rz   r+  c                <   t          |t          |                     r>| j        j        dv r.|s,| j        |j        k    r|                    | j        d          }|S t          |t                    r<t          |          dk    r)t          |                               g | j                  S t          |d          r|j        t          k    rt          j        |          | j        v rl	 t          |                               |          }nH# t          t          f$ r4}|r|cY d }~S |                     |d          }t          |          |d }~ww xY wt          |t                    rt#          |          }t          |t$          j                  r,|j        t          k    rt          j        |d| j                  }t+          |d	          }t-          |          }t+          |d	          }t/          |          r;	 t          |                               || j                  }n# t          $ r Y nw xY wt          |j        t0                    r:|j        j        | j        k    r%|                                }t+          |d	          }|rt7          |j                  rnLt          |                               |j                  s%|                     |d          }t          |          | j        j        dv r|s|                    | j        d          }|S )
Nr	  Fround_okr   r   r   Tconvert_non_numericdtype_if_all_natextract_numpy)r   r  r   r  unitas_unitr   r   r  r7  r   r   infer_dtyper   r   r  r3  rB   r   ndarraymaybe_convert_objectsrb   pd_arrayrC   rJ   
categories_internal_get_valuesrF   r   )r   r   r+  r.  r  s        rx   r,  z)DatetimeLikeArrayMixin._validate_listlike  s   eT$ZZ(( 	z$&&|&	UZ@W@Wdi%@@LeT"" 	Cs5zzQ::,,Rtz,BBB5'"" 
	2u{f'<'< u%%)<<<2 JJ55e<<EE"I. 2 2 2# %$88EEC#C..c1	2 eT"" 	C;EBBEeRZ(( 	U[F-B-B -4$*  E e4888e4888%   	 T

11%tz1JJ    ek#344 	A%332244%e4@@@ 	!OEK88 	!d00== 	!00==CC.. :?d""<"MM$)eM<<Es6   )"D EE E&&EE?)H) )
H65H6c                    t          |          r|                     |          }n|                     |d          S |                     |          S )NT)r0  )rE   r,  r4  _unboxr   s     rx   _validate_setitem_valuez.DatetimeLikeArrayMixin._validate_setitem_value  sS     	E++E22EE((t(DDD{{5!!!rz   6np.int64 | np.datetime64 | np.timedelta64 | np.ndarrayc                    t          j        |          r|                     |          }n|                     |           |j        }|S )zZ
        Unbox either a scalar with _unbox_scalar or an instance of our own type.
        )r   r   r   r   r   r   s     rx   rJ  zDatetimeLikeArrayMixin._unbox  sM    
 = 	#&&u--EE ''...NErz   	na_actionLiteral['ignore'] | Nonec                    ddl m} t          | ||          } ||          }t          |t                    r|                                S |j        S )Nr   rm   )rN  )pandasrn   rW   r   rO   to_numpyr`   )r   mapperrN  rn   r   s        rx   mapzDatetimeLikeArrayMixin.map  s_          49===vfm,, 	 ??$$$<rz   r   c                (   |j         j        dv r t          j        | j        t
                    S t          |          }t          |t          |                     s|j         t          k    rit          j        |d| j                   }|j         t          k    r|                     |          S t          |                     t                    |          S t          j        | j        t
                    S | j         j        dv r*t          d|           } |                    | j                  }	 |                     |           n7# t$          t&          f$ r# t          j        | j        t
                    cY S w xY 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]
        fiucr   Tr<  r	  DatetimeArray | TimedeltaArray)r   r  r   zerosr  r   ra   r   r  r   r   rE  rV   r  r   rB  rA  r   r  r   r   r   s     rx   rV   zDatetimeLikeArrayMixin.isin  sx    <&&8DJd3333/77&$t**-- 	4|v%%2(,%)Z  
 <6))99V,,,  F 3 3V<<<8DJd3333:?d""8$??D^^DI..F	4 ''////:& 	4 	4 	48DJd333333	4 DIv{+++s   -E 1E76E7c                    | j         S rv   )_isnanr   s    rx   rQ   zDatetimeLikeArrayMixin.isna>  s
    {rz   c                "    | j         t          k    S )z-
        return if each value is nan
        )r   r!   r   s    rx   rZ  zDatetimeLikeArrayMixin._isnanA  s    
 yD  rz   c                N    t          | j                                                  S )zJ
        return if I have any nans; enables various perf speedups
        )r   rZ  anyr   s    rx   _hasnazDatetimeLikeArrayMixin._hasnaH  s    
 DKOO%%&&&rz   r   c                    | j         r@|r|                    |          }|t          j        }t          j        || 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.
        )r^  r  r   nanputmaskrZ  )r   r   
fill_valuer   s       rx   _maybe_mask_resultsz*DatetimeLikeArrayMixin._maybe_mask_resultsO  sO    & ; 	8 0w//!V
Jvt{J777rz   
str | Nonec                ,    | j         dS | j         j        S )a  
        Return the frequency object as a string if it's set, otherwise None.

        See Also
        --------
        DatetimeIndex.inferred_freq : Returns a string representing a frequency
            generated by infer_freq.

        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   s    rx   rf  zDatetimeLikeArrayMixin.freqstrm  s    @ 94y  rz   c                h    | j         dk    rdS 	 t          j        |           S # t          $ r Y dS w xY w)a  
        Tries to return a string representing a frequency generated by infer_freq.

        Returns None if it can't autodetect the frequency.

        See Also
        --------
        DatetimeIndex.freqstr : Return the frequency object as a string if it's set,
            otherwise None.

        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[us]', freq=None)
        >>> tdelta_idx.inferred_freq
        '10D'
        r   N)r   rh   
infer_freqr   r   s    rx   inferred_freqz$DatetimeLikeArrayMixin.inferred_freq  sL    : 9>>4	)$/// 	 	 	44	s   # 
11Resolution | Nonec                d    | j         }|d S 	 t          j        |          S # t          $ r Y d S w xY wrv   )rf  r   get_reso_from_freqstrKeyError)r   rf  s     rx   _resolution_objz&DatetimeLikeArrayMixin._resolution_obj  sK    ,?4	3G<<< 	 	 	44	s   ! 
//c                    | j         j        S )zO
        Returns day, hour, minute, second, millisecond or microsecond
        )rn  attrnamer   s    rx   
resolutionz!DatetimeLikeArrayMixin.resolution  s     #,,rz   c                D    t          j        | j        d          d         S )NTtimeliker   r   is_monotonicr   r   s    rx   _is_monotonic_increasingz/DatetimeLikeArrayMixin._is_monotonic_increasing      !$)d;;;A>>rz   c                D    t          j        | j        d          d         S )NTrs  r   ru  r   s    rx   _is_monotonic_decreasingz/DatetimeLikeArrayMixin._is_monotonic_decreasing  rx  rz   c                |    t          t          | j                            d                              | j        k    S )NK)r   rX   r   r  sizer   s    rx   
_is_uniquez!DatetimeLikeArrayMixin._is_unique  s-    8DIOOC001122di??rz   c                   | j         dk    rbt          |dd           | j        k    rH ||                                 |                                                              | j                  S 	 |                     |          }nT# t          $ rG t          |d          r#t          |j	        t                    r	t          cY S t          | ||          cY S w xY wt          |dd           }t          |          rBt          j        |t!          j        |                     t&                              |          }|S |t(          u rQ|t*          j        u r!t!          j        | j        t0                    }n t!          j        | j        t0                    }|S t          | j	        t4                    st7          t8          |           } | j        |j        k    rt          |t=          |                     s]	 |                    | j         d          }n\# tB          $ r2 t!          j"        |j#                  }tI          | j%        ||          cY S w xY w|j%        }tI          | j%        ||          S | &                    |          } || j%        '                    d          |'                    d                    }tQ          |          }| j)        |z  }|*                                r$|t*          j        u }	t!          j+        |||	           |S )Nr   r  r   r   Fr:  r   ),r   r-  r  r  r  r/  r>   r7  r   r   rI   NotImplementedrf   rF   rU   comp_method_OBJECT_ARRAYr   r  r  r   r   operatorneonesr   rX  rM   r   TimelikeOpsr  r  rB  rA  r   r`   asm8r)   r   rJ  r   rQ   rZ  r]  ra  )
r   r   rw   r   r   	other_arr
other_valso_maskr&  
nat_results
             rx   _cmp_methodz"DatetimeLikeArrayMixin._cmp_method  s   9q==WUGT::djHH2djjllEKKMM22::4:FFF	733E::EE  	7 	7 	7ug&& &:ek:+N+N &%%%%%dE266666	7
 w--5!! 	 1BJt{{62233U F MC<<X[  4888$*D999M$*k22 	XT**D{el**!%d44 X %di% H H%   $&HUZ$8$8	= M9b       !&I9$-TVWWW[[''
DM&&t,,jood.C.CDDe{V#88:: 	1x{*JJvtZ000s*   /B ;CCC2H 9I
I__pow____rpow____mul____rmul____truediv____rtruediv____floordiv____rfloordiv____mod____rmod__
__divmod____rdivmod__@tuple[int | npt.NDArray[np.int64], None | npt.NDArray[np.bool_]]c                    t          |t                    r
|j        }d}n4t          |t          t          f          r
|j        }d}n|j        }|j        }||fS )zN
        Get the int64 values and b_mask to pass to add_overflowsafe.
        N)r   r   ordinalr   r   r   rZ  r   )r   r   i8valuesr&  s       rx   _get_i8_values_and_maskz.DatetimeLikeArrayMixin._get_i8_values_and_mask!  sc     eV$$ 		"}HDD	9566 	"|HDD <DzH~rz   c                   t          | j        t                    r| j        S t	          j        |          sdS t          | j        t                    r| j        S | j        j        dk    rt          |t                    r| j        S | j        j        dk    r<t          |t                    r'|j
        t          j        |j
                  r| j        S t	          j        | j        d          r6t          | j        t                    rt          |t                    r| j        S t	          j        | j        d          r6t          |t                    r!t          | j        t                    r| j        S dS )zP
        Check if we can preserve self.freq in addition or subtraction.
        Nr  r  )r   r   rM   r   r   r   r   r  r   r   r  r%   is_utcis_np_dtyper   r   s     rx   _get_arithmetic_result_freqz2DatetimeLikeArrayMixin._get_arithmetic_result_freq4  sS    dj+.. 	9u%% 	4	4(( 	9Z_##
5)(D(D#9JOs""5),, #!Y%5eh%?%?!
 9ODJ,,	49c**	 5),,	 9ODJ,,	5),,	 49c**	
 9trz   c                   t          j        | j        d          s9t          dt	          |           j         dt	          |          j                   t          d|           } ddlm} ddl	m
} |t          usJ t          |          rN| j        t          j                                        d| j         d	          z   } |j        ||j        
          S t%          |          }|                     |          \  } }t          d|           } |                     |          \  }}t+          | j        t/          j        |d
                    }|                    d| j         d	          } ||j        | j                  }|                    d| j         d	          }|                     |          }	 |j        |||	          S )Nr  cannot add  and rq   r   ro   )tz_to_dtypezM8[]r   r   r  rA  r   r   )r   r  r   r  r  r  r   pandas.core.arraysro   pandas.core.arrays.datetimesr  r   rQ   r   to_datetime64r  rA  _simple_newr   _ensure_matching_resosr  r   r   r   r  r   r  r  )
r   r   ro   r  r   other_i8r  
res_valuesr   new_freqs
             rx   _add_datetimelike_scalarz/DatetimeLikeArrayMixin._add_datetimelike_scalar^  s   tz3// 	Nd4jj1NNU8LNN   $d++444444<<<<<<C;; 	I ]S%6%8%8%?%?@Rdi@R@R@R%S%SSF,=,V6<HHHH%  11%88e$d++77>>&!$)RZ-M-M-MNN[[!3ty!3!3!344
uxdi888[[!3ty!3!3!344
33E::(}(5xPPPPrz   c                    t          j        | j        d          s9t          dt	          |           j         dt	          |          j                   || z   S )Nr  r  r  )r   r  r   r  r  r  r   s     rx   _add_datetime_arraylikez.DatetimeLikeArrayMixin._add_datetime_arraylike  s[    tz3// 	Nd4jj1NNU8LNN  
 t|rz   datetime | np.datetime64c                4   | j         j        dk    r$t          dt          |           j                   t          d|           } t          |          r
| t          z
  S t          |          }| 	                    |          \  } }| 
                    |          S )Nr  "cannot subtract a datelike from a ro   )r   r  r  r  r  r   rQ   r   r   r  _sub_datetimelike)r   r   tss      rx   _sub_datetimelike_scalarz/DatetimeLikeArrayMixin._sub_datetimelike_scalar  s     :?c!!VdATVVWWWOT** ;; 	#:u..r22b%%b)))rz   c                B   | j         j        dk    r$t          dt          |           j                   t          |           t          |          k    rt          d          t          d|           } |                     |          \  } }| 	                    |          S )Nr  r  $cannot add indices of unequal lengthro   )
r   r  r  r  r  r   r   r   r  r  r   s     rx   _sub_datetime_arraylikez.DatetimeLikeArrayMixin._sub_datetime_arraylike  s    :?c!!VdATVVWWWt99E

""CDDDOT**11%88e%%e,,,rz   Timestamp | DatetimeArrayc                2   t          d|           } ddlm} 	 |                     |           nN# t          $ rA}t          |                              dd          } t          |          |          |d }~ww xY w|                     |          \  }}t          | j
        t          j        | d                    }|                    d| j         d	          }|                     |          }	t          d
|	          }	 |j        ||j        |	          S )Nro   r   rq   comparesubtractr   r   timedelta64[r  zTick | Noner  )r   r  rq   _assert_tzawareness_compatr  rt   replacer  r  r   r   r   r  r   rA  r  r  r   )
r   r   rq   r.  new_messager  r  r  res_m8r  s
             rx   r  z(DatetimeLikeArrayMixin._sub_datetimelike  s*   OT**555555	2++E2222 	2 	2 	2c((**9jAAK$s))K((c1	2  77>>&%diXIT1R1R1RSS
!<	!<!<!<==33E::x00)~)&8TTTTs   . 
A9<A44A9r   rp   c                   t          j        | j        d          s$t          dt	          |           j                   ddlm} t          j	        |j
        | j                  }t          |j                  } |||          }|| z   S )Nr  zcannot add Period to a r   )rp   r   )r   r  r   r  r  r  pandas.core.arrays.periodrp   r   broadcast_tor  r  rM   r   )r   r   rp   i8valsr   parrs         rx   _add_periodz"DatetimeLikeArrayMixin._add_period  s    tz3// 	MKd4jj6IKKLLL 	:99999
;;EJ''{6///d{rz   c                     t          |           rv   r   )r   offsets     rx   _add_offsetz"DatetimeLikeArrayMixin._add_offset  s    !$'''rz   c                   t          |          r{t          j        | j        d                              | j        j                  }|                    t                     t          |           
                    || j                  S t          d|           } t          |          }|                     |          \  } }|                     |          S )zk
        Add a delta of a timedeltalike

        Returns
        -------
        Same type as self
        r   r   rW  )rQ   r   emptyr  r   r   r   fillr!   r  r  r   r   r  _add_timedeltalike)r   r   
new_valuess      rx   _add_timedeltalike_scalarz0DatetimeLikeArrayMixin._add_timedeltalike_scalar  s     ;; 	H$*D999>>t}?RSSJOOD!!!::))*DJ)GGG 4d;;%  11%88e&&u---rz   c                    t          |           t          |          k    rt          d          t          d|                               |          \  } }|                     |          S )zl
        Add a delta of a TimedeltaIndex

        Returns
        -------
        Same type as self
        r  rW  )r   r   r   r  r  r   s     rx   _add_timedelta_arraylikez/DatetimeLikeArrayMixin._add_timedelta_arraylike  si     t99E

""CDDD,d
 

 
 
'
' 	e &&u---rz   Timedelta | TimedeltaArrayc                @   |                      |          \  }}t          | j        t          j        |d                    }|                    | j        j                  }|                     |          }t          |           
                    || j        |          S )Nr   r   r  )r  r   r   r   r  r   r   r   r  r  r  )r   r   r  r  r  r  r  s          rx   r  z)DatetimeLikeArrayMixin._add_timedeltalike  s    77>>&%diHD1Q1Q1QRR
__T]%899
33E:: Dzz%%* & 
 
 	
rz   c                   t          | j        t                    r>t          dt	          |           j         dt	          t                    j                   t          j        | j	        t          j
                  }|                    t                     |                    | j        j                  }t	          |                               || j        d          S )z$
        Add pd.NaT to self
        zCannot add r  r   Nr  )r   r   rM   r  r  r  r   r   r  r  r  r  r!   r   r   r  r   r   s     rx   _add_natzDatetimeLikeArrayMixin._add_nat  s    
 dj+.. 	Ld4jj1LLS		8JLL   $*BH555DT]011Dzz%%* & 
 
 	
rz   c                "   t          j        | j        t           j                  }|                    t
                     | j        j        dv r.t          d|           } |	                    d| j
         d          S |	                    d          S )z+
        Subtract pd.NaT from self
        r   r	  zDatetimeArray| TimedeltaArrayr  r  ztimedelta64[ns])r   r  r  r  r  r!   r   r  r   r   rA  r  s     rx   _sub_natzDatetimeLikeArrayMixin._sub_nat  s     $*BH555D:?d""7>>D;;:di:::;;;;;0111rz   Period | PeriodArrayc                    t           j        t                    s9t          dt	          |          j         dt	                     j                   t          d                                 |                                |          \  }}t           j
        t          j        | d                    }t          j         fd|D                       }| j        }n
 j        |z  }t          ||<   |S )Ncannot subtract  from rp   r   r   c                .    g | ]}j         j        |z  S r   )r   base)r   r   r   s     rx   
<listcomp>z:DatetimeLikeArrayMixin._sub_periodlike.<locals>.<listcomp>;  s"    EEEATY^a/EEErz   )r   r   rM   r  r  r  r   r   r  r   r   r   r  r`   rZ  r   )r   r   r  r  new_i8_datanew_datar&  s   `      rx   _sub_periodlikez&DatetimeLikeArrayMixin._sub_periodlike-  s     $*k22 	T4;;#7TTtDzz?RTT   M4((##E***77>>&&ty"*hYd2S2S2STT8EEEEEEEFF>;DD ;'Drz   c                   |t           j        t           j        fv sJ t          |          dk    r| j        dk    r || |d                   S t          d          r>t          j        dt          |           j	         dt          t                                 | j        |j        k    sJ | j        |j        f             ||                     d          t          j        |                    }|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   performance_warningsz)Adding/subtracting object-dtype array to z not vectorized.)
stacklevelO)r  addsubr   r   r   warningswarnr  r  r?   rA   r  r  r   r  )r   r   rw   r  s       rx   _addsub_object_arrayz+DatetimeLikeArrayMixin._addsub_object_arrayF  s      hlHL11111u::??tyA~~ 2dE!H%%%,-- 	M9::&9 9 9"+--	    zU[(((4:u{*C(((RC(("*U*;*;<<
rz   )skipnanamer  c                  |dvr"t          d| dt          |                      t          t          |          } ||                                 fd|i|}t          |                               || j                  S )N>   cummaxcumminzAccumulation z not supported for r  r   )r  r  r-  rY   r   r  r   )r   r  r  r   rw   r   s         rx   _accumulatez"DatetimeLikeArrayMixin._accumulatek  s    +++QDQQT$ZZQQRRR/66DIIKK999&99Dzz%%fDJ%???rz   __add__c                   t          |dd           }t          |          }|t          u r|                                 }nt	          |t
          t          t          j        f          r| 	                    |          }nt	          |t                    rYt          j        | j        d          r?t          |j                                      d          }| 	                    |          }n=t	          |t"                    r|                     |          }nt	          |t&          t          j        f          r|                     |          }nt	          |t,                    r1t          j        | j        d          r|                     |          }nt          j        |          rht	          | j        t2                    st5          |           t7          d|           }|                    ||j        j        z  t<          j                  }nt          j        |d          r|                      |          }ntC          |          r!| "                    |t<          j                  }nt          j        |d          st	          |tF                    r| $                    |          S tK          |          rgt	          | j        t2                    st5          |           t7          d|           }|                    ||j        j        z  t<          j                  }ntL          S t	          |t          j'                  r7t          j        |j        d          rdd	l(m)}  |j*        ||j        
          S |S )Nr   Mmdayssr  rp   r  r   r  r   )+r-  ra   r   r  r   r   r   r   timedelta64r  r   r   r  r   r   r   rB  r   r  r   
datetime64r  r   r  
is_integerrM   r+   r   _addsub_int_array_or_scalar_nr  r  r  rF   r  rK   r  rD   r  rD  r  rq   r  r   r   other_dtyper   tdobjrq   s          rx   r  zDatetimeLikeArrayMixin.__add__t  s   eWd33.u55 C<<:>--//FFi@AA ,	"33E::FFs## *	"
D(I(I *	"(((0055B33B77FFz** &	"%%e,,FF"-899 #	"22599FFv&& !	"3?4:s+K+K !	"%%e,,FF^E"" 	" dj+66 5.t444}d++C44USY\5I8<XXFF _[#.. 	"22599FF[)) 	"..uhlCCFF_[#.. 	"*3
 3
 	" //666k** 	"dj+66 5.t444}d++C44USY\5I8<XXFF "!fbj)) 	McoflC.P.P 	M9999990>0v|LLLLrz   c                ,    |                      |          S rv   )r  r   s     rx   __radd__zDatetimeLikeArrayMixin.__radd__  s    ||E"""rz   __sub__c                &   t          |dd           }t          |          }|t          u r|                                 }n t	          |t
          t          t          j        f          r| 	                    |           }nt	          |t                    rZt          j        | j        d          r@t          |j                                      d          }| 	                    |           }nRt	          |t"                    r|                     |           }n%t	          |t&          t          j        f          r|                     |          }nt          j        |          rht	          | j        t.                    st1          |           t3          d|           }|                    ||j        j        z  t8          j                  }nqt	          |t<                    r|                     |          }nEt          j        |d          r|                      |           }ntC          |          r!| "                    |t8          j                  }nt          j        |d          st	          |tF                    r| $                    |          }nt	          |t.                    r|                     |          }n}tK          |          rgt	          | j        t.                    st1          |           t3          d|           }|                    ||j        j        z  t8          j                  }ntL          S t	          |t          j'                  r7t          j        |j        d          rdd	l(m)}  |j*        ||j        
          S |S )Nr   r  r  r  rp   r  r  r   r  r   )+r-  ra   r   r  r   r   r   r   r  r  r   r   r  r   r   r   rB  r   r  r   r  r  r   rM   r+   r   r  r  r  r  r   r  r  rF   r  rK   r  rD   r  rD  r  rq   r  r  s          rx   r	  zDatetimeLikeArrayMixin.__sub__  s4   eWd33.u55 C<<:>--//FFi@AA ,	"33UF;;FFs## *	"
D(I(I *	"(((0055B33RC88FFz** &	"%%uf--FF"-899 #	"22599FF^E"" !	" dj+66 5.t444}d++C44USY\5I8<XXFFv&& 	"))%00FF _[#.. 	"22E6::FF[)) 	"..uhlCCFF_[#.. 	"*3
 3
 	" 11%88FF[11 
	"))%00FFk** 	"dj+66 5.t444}d++C44USY\5I8<XXFF "!fbj)) 	McoflC.P.P 	M9999990>0v|LLLLrz   c           	        t          |dd           }t          j        |d          pt          |t                    }|rwt          j        | j        d          r]t          j        |          rt          |          | z
  S t          |t                    sddl	m
}  |j        ||j                  }|| z
  S | j        j        dk    rTt          |d          rD|sBt          dt          |           j         dt          |          j         d	|j         d
          t          | j        t"                    rAt          j        |d          r,t          dt          |           j         d|j                   t          j        | j        d          rt%          d|           } |  |z   S | |z
  }|j        j        dk    r9t          dt          |           j         dt          |          j                   | S )Nr   r  r  r   r  r   r  r  [r  rq   )r-  r   r  r   rK   r   r   r   r   r  ro   r  r  r7  r  r  r  rM   r   )r   r   r  other_is_dt64ro   flippeds         rx   __rsub__zDatetimeLikeArrayMixin.__rsub__  s#   eWd33S99 
Z>
 >
  	#S_TZ== 	# }U## / ''$..e%;<< O<<<<<<44U%+NNN4<Z_##w(?(?## 94::#6 9 9;;'9 9*/+9 9 9   
K00 	#S_[RU5V5V 	#WtDzz/BWW%+WWXXX_TZ-- 	#($//DEU?",=$$T4::#6TTd5kk>RTT   xrz   c                z    | |z   }|d d          | d d <   t          | j        t                    s|j        | _        | S rv   r   r   rM   r   r   r   r   r   s      rx   __iadd__zDatetimeLikeArrayMixin.__iadd__  B    )QQQ$*k22 	%DJrz   c                z    | |z
  }|d d          | d d <   t          | j        t                    s|j        | _        | S rv   r  r  s      rx   __isub__zDatetimeLikeArrayMixin.__isub__"  r  rz   qsnpt.NDArray[np.float64]interpolationc                J    t                                          ||          S )N)r  r  )r   	_quantile)r   r  r  r   s      rx   r  z DatetimeLikeArrayMixin._quantile.  s"     ww  Bm DDDrz   axisr  r  AxisInt | Nonec                   t          j        d|           t          j        || j                   t	          j        | j        ||          }|                     ||          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.
        r   r  )nvvalidate_minvalidate_minmax_axisr   rT   nanminr   _wrap_reduction_resultr   r  r  r   r   s        rx   minzDatetimeLikeArrayMixin.min6  Y     	F###
di000t}4GGG**4888rz   c                   t          j        d|           t          j        || j                   t	          j        | j        ||          }|                     ||          S )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.
        r   r  )r   validate_maxr"  r   rT   nanmaxr   r$  r%  s        rx   maxzDatetimeLikeArrayMixin.maxH  r'  rz   r   )r  r  c               
   t          | j        t                    r%t          dt	          |           j         d          t          j        | j        ||| 	                                          }| 
                    ||          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
            Axis for the function to be applied on.

        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[us]', 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[s]', 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&  )r   r   rM   r  r  r  rT   nanmeanr   rQ   r$  )r   r  r  r   s       rx   meanzDatetimeLikeArrayMixin.meanZ  s    Z dj+.. 	7tDzz/B 7 7 7   MV$))++
 
 
 **4888rz   c                   t          j        d|           |'t          |          | j        k    rt	          d          t          j        | j        ||          }|                     ||          S )Nr   z abs(axis) must be less than ndimr  )	r   validate_medianabsr   r   rT   	nanmedianr   r$  r%  s        rx   medianzDatetimeLikeArrayMixin.median  sk    
2v&&&D		TY 6 6?@@@!$-d6JJJ**4888rz   dropnac                &   d }|r|                                  }t          j        |                     d          |          \  }}|                    | j        j                  }t          t          j        |          }| 	                    |          S )Nr   )r&  )
rQ   rR   moder   r   r   r   r   rD  r   )r   r5  r&  i8modes_npmodess         rx   _modezDatetimeLikeArrayMixin._mode  sy     	99;;D_TYYt__4@@@
,,t}233rz7++&&w///rz   howhas_dropped_na	min_countintngroupsidsnpt.NDArray[np.intp]c                  | j         }|j        dk    r2|dv rt          d| d          |dv rt          d| d| d          n^t          |t                    r2|dv rt          d| d	          |dv rt          d| d
| d          n|dv rt          d| d	          | j                            d          }ddlm}	 |		                    |          }
 |	||
|          } |j
        |f|||d d|}|j        |j        v r|S |j         dk    sJ |dv rvddlm} t          | j         t                    rt          d          t          d|           } d| j         d}|                    |          } |j        ||j                   S |                    | j        j                   }|                     |          S )Nr  )sumprodcumsumcumprodvarskewkurtz,datetime64 type does not support operation 'r6  )r]  allzN' with datetime64 dtypes is no longer supported. Use (obj != pd.Timestamp(0)).z() instead.zPeriod type does not support z operationszK' with PeriodDtype is no longer supported. Use (obj != pd.Period(0, freq)).)rE  rG  rI  rJ  rH  z"timedelta64 type does not support r   r   )WrappedCythonOp)r<  r  r=  )r>  r@  comp_idsr&  )stdsemr  z-'std' and 'sem' are not valid for PeriodDtyperW  zm8[r  r   )r   r  r  r   rM   r   r   pandas.core.groupby.opsrL  get_kind_from_how_cython_op_ndim_compatr<  cast_blocklistr  rq   r   rA  r  r   )r   r<  r=  r>  r@  rA  r   r   npvaluesrL  r  rw   r  rq   	new_dtypes                  rx   _groupby_opz"DatetimeLikeArrayMixin._groupby_op  s    
:QQQ Us U U UVVVn$$E E E47E E E   % {++ 	SQQQ P P P PQQQn$$H H H7:H H H   % >>>QQQQRRR =%%h//;;;;;;0055_4OOO.R.

 
 
 

 6R&&&  8++++.  999999$*k22 Q OPPP8$??D*di***I#33J->-j
@PQQQQ__T]%899
&&z222rz   r|   r   )NNF)r   r   r   r   r|   r   )r|   r   )r   rt   r|   rr   )r   rr   r|   r   )r   rr   r|   r   r|   r   )r|   rj   )r|   r   )r   r   r|   r   )F)r   r   r|   r   )NN)r   r   r   r   r|   r   )r   r6   r|   rr   )r   r   r|   r
   )r   r4   r|   r   )r|   r   )r   r   r   r   r|   r   r|   r   T)r   r   r|   r
   )r   r  r|   ro   )r   r"  r|   rq   ).)r   r   r|   r,   rv   )r&  r'  r|   r   )r0  r   r1  r   )r0  r   r|   rt   )r+  r   )r|   rL  )rN  rO  )r   r,   r|   r'  )r|   r'  )r   r   r|   r   )r|   rd  )r|   rj  )r|   rt   )r|   r  )r|   ro   )r   ro   r|   ro   )r   r  r|   rq   )r   ro   r|   rq   )r   r  r|   rq   )r   r   r|   rp   )r   rq   r|   r
   )r   r  r|   r
   )r   r  r|   r   )r   r   r|   r   )r  rt   r  r   r|   r
   )r  r  r  rt   r|   r
   )r  r  r  r   )r  r   r  r  )r5  r   )
r<  rt   r=  r   r>  r?  r@  r?  rA  rB  )ar  
__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/  r4  r3  r,  rK  r   rJ  r\   rT  rV   rQ   rZ  r^  r!   rc  rf  ri  rn  rq  rw  rz  r~  r  ry   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  re   r  r  r	  r  r  r  r   r  r&  r+  r/  r4  r;  rV  __classcell__r   s   @rx   r   r      s	          $###4444))))   ^ IN( ( ( ( (
 ( ( ( X(( ( ( ((( ( ( (.( ( ( (,( ( (D D D D: : : : 
( 
( 
( X
(  (-$
( 
( 
( 
( 
( 
(     AE    ( CCC XC   X
     &   <! ! ! ! ! !,   
71 71 71 71 71 71 71r  XBBB XBCCC XC???? X?# # # # # # #
     " " "P  %;) ;) ;) ;) ;) ;)z    >@ @ @ @ @D" " " 
 
 
 U
" 	  	  	  	  \	 2, 2, 2, 2,n    ! ! ! X! ' ' ' X' .24    < !! !! !! X!!F ! ! ! X!F    X - - - X- ? ? ? X? ? ? ? X? @ @ @ X@7 7 7v ('	22G((44H''	22G((44H++M::K,,^<<L,,^<<L--o>>M''	22G((44H**<88J++M::K
   U$ ' ' ' U'R Q Q Q UQB    U * * * U*$ 
- 
- 
- U
- U U U UU& 
 
 
 U
( ( (. . .(. . . .$ 
 
 
 U
 
 
 
 U
* 2 2 2 U2&    U0 " " " U"H 8< @ @ @ @ @ @ i((9 9 )(9v# # # i((9 9 )(9v' ' 'R       E E E E E E ,0 9 9 9 9 9 9" ,0 9 9 9 9 9 9" &*! 89 89 89 89 89 89t /3D 9 9 9 9 9 90 0 0 0 0H3 H3 H3 H3 H3 H3 H3 H3rz   r   c                      e Zd ZdZddZdS )	DatelikeOpszK
    Common ops for DatetimeIndex/PeriodIndex, but not TimedeltaIndex.
    r   rt   r|   r   c                    |                      |t          j                  }t                      r+ddlm} t          | |t          j                            S |                    t          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 <https://docs.python.org/3/library/datetime.html
        #strftime-and-strptime-behavior>`__.

        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='str')
        )r   r   r   )StringDtyper  r   Fr  )	r   r   r`  r   rQ  rf  rF  r  r   )r   r   r   rf  s       rx   strftimezDatelikeOps.strftime  sx    Z **{26*RR 	H******F++rv*F*F*FGGGG}}V%}000rz   N)r   rt   r|   r   )r  r\  r]  r^  rh  r   rz   rx   rd  rd    s2         21 21 21 21 21 21rz   rd  c                      e Zd ZdZed             Zed             Zej        dMd            Ze	dNd	            Z
e	edOd                        ZedPd            ZedQd            ZedRd            ZdSdTdZd ZdU fdZd  Z	 	 dVdWd&Z	 	 dVdWd'Z	 	 dVdWd(Zd)dd*dXd.Zd)dd*dXd/ZdMd0ZdYd1ZdZ fd3Z	 	 d[d\ fd7Ze	 d]d^ fd<            Zd_d` fd?ZdadDZd4d)d8dEdb fdKZ edcdL            Z! xZ"S )dr  zK
    Common ops for TimedeltaIndex/DatetimeIndex, but not PeriodIndex.
    c                     t          |           rv   r   )r  r   r   s      rx   _validate_dtypezTimelikeOps._validate_dtype5  s    !#&&&rz   c                    | j         S )ac  
        Return the frequency object if it is set, otherwise None.

        To learn more about the frequency strings, please see
        :ref:`this link<timeseries.offset_aliases>`.

        See Also
        --------
        DatetimeIndex.freq : Return the frequency object if it is set, otherwise None.
        PeriodIndex.freq : Return the frequency object if it is set, otherwise None.

        Examples
        --------
        >>> datetimeindex = pd.date_range(
        ...     "2022-02-22 02:22:22", periods=10, tz="America/Chicago", freq="h"
        ... )
        >>> datetimeindex
        DatetimeIndex(['2022-02-22 02:22:22-06:00', '2022-02-22 03:22:22-06:00',
                       '2022-02-22 04:22:22-06:00', '2022-02-22 05:22:22-06:00',
                       '2022-02-22 06:22:22-06:00', '2022-02-22 07:22:22-06:00',
                       '2022-02-22 08:22:22-06:00', '2022-02-22 09:22:22-06:00',
                       '2022-02-22 10:22:22-06:00', '2022-02-22 11:22:22-06:00'],
                      dtype='datetime64[us, America/Chicago]', freq='h')
        >>> datetimeindex.freq
        <Hour>
        r   r   s    rx   r   zTimelikeOps.freq9  s    8 zrz   r|   r   c                   |zt          |          }|                     | |           | j        j        dk    r+t	          |t
          t          f          st          d          | j        dk    rt          d          || _
        d S )Nr  (TimedeltaArray/Index freq must be a Tickr   zCannot set freq with ndim > 1)r&   _validate_frequencyr   r  r   r   r   r  r   r   r   r   s     rx   r   zTimelikeOps.freqW  s    e$$E$$T5111z#%%js.L.L% JKKKy1}} !@AAA


rz   validate_kwdsdictc                N   |	d| _         dS |dk    r$| j         t          | j                  | _         dS dS |t          j        u rdS | j         4t          |          } 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.
        Ninfer)r   r&   ri  r   
no_defaultr  rp  _validate_inferred_freq)r   r   rq  s      rx   _maybe_pin_freqzTimelikeOps._maybe_pin_freqd  s     <DJJJW__ z! 't'9::


 "! S^## DZ T??D*DJJ*4GGGGGDJJJ T??D#D$*55555rz   r   r   c           	     h   |j         }|j        dk    s||j        k    rdS 	  | j        d|d         dt	          |          ||j        d|}t          j        |j        |j                  st          dS # t          $ r3}dt          |          v r|t          d| d|j                   |d}~ww xY 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   rA  z	non-fixedInferred frequency 9 from passed values does not conform to passed frequency r   )ri  r}  rf  _generate_ranger   rA  r   array_equalr   r   rt   )r  indexr   r   inferredon_freqr.  s          rx   rp  zTimelikeOps._validate_frequency  s    &:??h$,664	)c) AhE

Z   G >%*gl;; !  ! ! 	 	 	c#hh&& 	 Gh G G8<G G  	s   AA4 4
B1>.B,,B1r{  
int | Noner
   c                     t          |           rv   r   )r  ry  rz  r{  r   r   r   s          rx   r~  zTimelikeOps._generate_range  s     "#&&&rz   r?  c                4    t          | j        j                  S rv   )r    r   r   r   s    rx   r  zTimelikeOps._creso  s    "4=#6777rz   rl   c                *    t          | j                  S )a4  
        The precision unit of the datetime data.

        Returns the precision unit for the dtype.
        It means the smallest time frame that can be stored within this dtype.

        Returns
        -------
        str
            Unit string representation (e.g. "ns").

        See Also
        --------
        TimelikeOps.as_unit : Converts to a specific unit.

        Examples
        --------
        >>> idx = pd.DatetimeIndex(["2020-01-02 01:02:03.004005006"])
        >>> idx.unit
        'ns'
        >>> idx.as_unit("s").unit
        's'
        )dtype_to_unitr   r   s    rx   rA  zTimelikeOps.unit  s    6 TZ(((rz   TrA  r;  r   c                   |dvrt          d          t          j        | j        j         d| d          }t	          | j        ||          }t          | j        t          j                  r|j        }n&t          d|           j        }t          ||          }t          |                               ||| j                  S )	aZ  
        Convert to a dtype with the given unit resolution.

        The limits of timestamp representation depend on the chosen resolution.
        Different resolutions can be converted to each other through as_unit.

        Parameters
        ----------
        unit : {'s', 'ms', 'us', 'ns'}
        round_ok : bool, default True
            If False and the conversion requires rounding, raise ValueError.

        Returns
        -------
        same type as self
            Converted to the specified unit.

        See Also
        --------
        Timestamp.as_unit : Convert to the given unit.

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

        >>> idx = pd.DatetimeIndex(["2020-01-02 01:02:03.004005006"])
        >>> idx
        DatetimeIndex(['2020-01-02 01:02:03.004005006'],
                      dtype='datetime64[ns]', freq=None)
        >>> idx.as_unit("s")
        DatetimeIndex(['2020-01-02 01:02:03'], dtype='datetime64[s]', freq=None)

        For :class:`pandas.TimedeltaIndex`:

        >>> tdelta_idx = pd.to_timedelta(["1 day 3 min 2 us 42 ns"])
        >>> tdelta_idx
        TimedeltaIndex(['1 days 00:03:00.000002042'],
                        dtype='timedelta64[ns]', freq=None)
        >>> tdelta_idx.as_unit("s")
        TimedeltaIndex(['1 days 00:03:00'], dtype='timedelta64[s]', freq=None)
        )r  msusnsz)Supported units are 's', 'ms', 'us', 'ns'z8[r  r:  ro   r  r  )r   r   r   r  r   r   r   r   r  rK   r  r  r   )r   rA  r;  r   r  rU  r  s          rx   rB  zTimelikeOps.as_unit  s    T ...HIIIDJO66t66677(QQQ
dj"(++ 	:"(IIot,,/B'2D999I Dzz%% & 
 
 	
rz   c                    | j         |j         k    rE| j         |j         k     r|                     |j                  } n|                    | j                  }| |fS rv   )r  rB  rA  r   s     rx   r  z"TimelikeOps._ensure_matching_resos  sR    ;%,&&{U\))||EJ//di00U{rz   ufuncnp.ufuncmethodrt   c                    |t           j        t           j        t           j        fv r9t	          |          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  inputsr   r   s        rx   r  zTimelikeOps.__array_ufunc__%  s    bh"+666Fq  q	T!! *75&))$-BB6BBB&uww&ufHvHHHHHHrz   c                v   t          | j        t                    rZt          d|           } |                     d           }|                    ||||          }|                    | j        ||          S |                     d          }t          t          j	        |          }t          || j                  }|dk    r|                                 S t          |||          }	|                     |	t                    }|                    | j        j                  }|                     || j                  S )Nro   )	ambiguousnonexistentr   r   rb  r   )r   r   rK   r   tz_localize_roundr  r   r   rD  r*   r  r   r(   rc  r!   r   r  )
r   r   r7  r  r  naiver   r   nanos	result_i8s
             rx   r  zTimelikeOps._round0  s   dj/22 	..D$$T**E\\$iEEF%%9+ &    4bj&))"455A::99;;!&$66	))))EET]011dj999rz   raiser  r9   r  r:   c                F    |                      |t          j        ||          S )a  
        Perform round operation on the data to the specified `freq`.

        Parameters
        ----------
        freq : str or Offset
            The frequency level to round 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 a ValueError 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 a ValueError 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.

        See Also
        --------
        DatetimeIndex.floor :
            Perform floor operation on the data to the specified `freq`.
        DatetimeIndex.snap :
            Snap time stamps to nearest occurring frequency.

        Notes
        -----
        If the timestamps have a timezone, rounding will take place relative to the
        local ("wall") time and re-localized to the same timezone. When rounding
        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[us]', freq='min')

        >>> rng.round('h')
        DatetimeIndex(['2018-01-01 12:00:00', '2018-01-01 12:00:00',
                       '2018-01-01 12:00:00'],
                      dtype='datetime64[us]', 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[us]

        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[us, Europe/Amsterdam]', freq=None)

        >>> rng_tz.floor("2h", ambiguous=True)
        DatetimeIndex(['2021-10-31 02:00:00+02:00'],
                      dtype='datetime64[us, Europe/Amsterdam]', freq=None)
        )r  r'   NEAREST_HALF_EVENr   r   r  r  s       rx   roundzTimelikeOps.roundF  s     L {{4!:I{SSSrz   c                F    |                      |t          j        ||          S )a  
        Perform floor operation on the data to the specified `freq`.

        Parameters
        ----------
        freq : str or Offset
            The frequency level to floor 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 a ValueError 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 a ValueError 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.

        See Also
        --------
        DatetimeIndex.floor :
            Perform floor operation on the data to the specified `freq`.
        DatetimeIndex.snap :
            Snap time stamps to nearest occurring frequency.

        Notes
        -----
        If the timestamps have a timezone, flooring will take place relative to the
        local ("wall") time and re-localized to the same timezone. When flooring
        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[us]', freq='min')

        >>> rng.floor('h')
        DatetimeIndex(['2018-01-01 11:00:00', '2018-01-01 12:00:00',
                       '2018-01-01 12:00:00'],
                      dtype='datetime64[us]', 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[us]

        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[us, Europe/Amsterdam]', freq=None)

        >>> rng_tz.floor("2h", ambiguous=True)
        DatetimeIndex(['2021-10-31 02:00:00+02:00'],
                      dtype='datetime64[us, Europe/Amsterdam]', freq=None)
        )r  r'   MINUS_INFTYr  s       rx   floorzTimelikeOps.floor  s     L {{4!4iMMMrz   c                F    |                      |t          j        ||          S )a  
        Perform ceil operation on the data to the specified `freq`.

        Parameters
        ----------
        freq : str or Offset
            The frequency level to ceil 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 a ValueError 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 a ValueError 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.

        See Also
        --------
        DatetimeIndex.floor :
            Perform floor operation on the data to the specified `freq`.
        DatetimeIndex.snap :
            Snap time stamps to nearest occurring frequency.

        Notes
        -----
        If the timestamps have a timezone, ceiling will take place relative to the
        local ("wall") time and re-localized to the same timezone. When ceiling
        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[us]', freq='min')

        >>> rng.ceil('h')
        DatetimeIndex(['2018-01-01 12:00:00', '2018-01-01 12:00:00',
                       '2018-01-01 13:00:00'],
                      dtype='datetime64[us]', 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[us]

        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[us, Europe/Amsterdam]', freq=None)

        >>> rng_tz.ceil("h", ambiguous=True)
        DatetimeIndex(['2021-10-31 02:00:00+02:00'],
                      dtype='datetime64[us, Europe/Amsterdam]', freq=None)
        )r  r'   
PLUS_INFTYr  s       rx   ceilzTimelikeOps.ceil	  s     L {{4!3YLLLrz   Nr  r  r  r  c               `    t          j        | j        |||                                           S Nr-  )rT   nananyr   rQ   r   r  r  s      rx   r]  zTimelikeOps.any	  s%    }T]f499;;WWWWrz   c               `    t          j        | j        |||                                           S r  )rT   nanallr   rQ   r  s      rx   rK  zTimelikeOps.all	  s'     }T]f499;;WWWWrz   c                    d | _         d S rv   rm  r   s    rx   r   zTimelikeOps._maybe_clear_freq	  s    


rz   c                B   |nt          |           dk    rQt          |t                    r<| j        j        dk    r+t          |t
          t          f          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  ro  rt  )r   r   r   r   r  r   r   r  r&   ri  r   r   )r   r   r   s      rx   
_with_freqzTimelikeOps._with_freq	  s     <YY!^^
4 < <^z#%%jc{.K.K% JKKK 7????T/00Diikk	
rz   r   c                    t          | j        t          j                  r| j        S t	                                                      S rv   )r   r   r   r   r   _values_for_json)r   r   s    rx   r  zTimelikeOps._values_for_json	  s7    dj"(++ 	!= ww'')))rz   Fuse_na_sentinelsortc                   | j         |rN| j         j        dk     r>t          j        t	          |           dz
  ddt          j                  }| d d d         }nAt          j        t	          |           t          j                  }|                                 }||fS |r%t          dt          |           j	         d          t                                          |          S )Nr   r   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   r   aranger   intpr   NotImplementedErrorr  r  r   	factorize)r   r  r  codesuniquesr   s        rx   r  zTimelikeOps.factorize	  s    
 9  &	a	#d))a-RrwGGGttt*	#d))27;;;))++'>! 	 &=d)< = = =  
 ww   AAArz   r   	to_concatSequence[Self]r-   c                \   t                                          ||          }|d         |dk    ryd |D             }j        ft          fd|D                       rKt	          |d d         |dd          d          }t          fd|D                       rj        }||_        |S )	Nr   c                0    g | ]}t          |          |S r   )r   )r   r   s     rx   r  z1TimelikeOps._concat_same_type.<locals>.<listcomp>	  s#    888qQ8888rz   c              3  8   K   | ]}|j         j         k    V  d S rv   r   )r   r   r  s     rx   r   z0TimelikeOps._concat_same_type.<locals>.<genexpr>	  s,      +R+R1AFch,>+R+R+R+R+R+Rrz   r  r   T)strictc              3  d   K   | ]*}|d          d         j         z   |d         d          k    V  +dS )r   r  r   Nr  )r   pairr  s     rx   r   z0TimelikeOps._concat_same_type.<locals>.<genexpr>	  s?      NNtAwr{SX-a;NNNNNNrz   )r   _concat_same_typer   rK  zipr   )r  r  r  new_objpairsr  r  r   s         @rx   r  zTimelikeOps._concat_same_type	  s     ''++It<<l199 98I888Ix#+R+R+R+R	+R+R+R(R(R#IcrcNIabbM$GGGNNNNNNNNN -"xH$,GMrz   Corderc                d    t                                          |          }| j        |_        |S )N)r  )r   r   r   r   )r   r  r  r   s      rx   r   zTimelikeOps.copy	  s(    '',,U,++	rz   r2   r  rn   r   c          
         |dk    rt           |s| j        }	n| j                                        }	t          j        |	f||||||d| |s| S t          |                               |	| j                  S )z2
        See NDFrame.interpolate.__doc__.
        linear)r  r  r  limitlimit_direction
limit_arear   )r  r   r   rS   interpolate_2d_inplacer  r  r   )
r   r  r  r  r  r  r  r   r   out_datas
             rx   interpolatezTimelikeOps.interpolate	  s      X%% 	,}HH}))++H&		
+!		
 		
 		
 		
 		
  	KDzz%%hdj%AAArz   )
allow_fillrb  r  indicesr8   r  rb  r   c               8   t                                          ||||          }t          j        |t          j                  }t          j        |t          |                     }t          |t                    r| 
                    |          }||_        |S )N)r  r  rb  r  r   )r   taker   r  r  r   maybe_indices_to_slicer   r   r   r   r   )	r   r  r  rb  r  r   maybe_slicer   r   s	           rx   r  zTimelikeOps.take
  s     
zPT  
 
 *WBG4440#d))DDk5)) 	 ))+66DFLrz   c                
   t          j        | j                  sdS | j        }|t          k    }t          | j                  }t          |          }t          j        |||z  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   r  r   r   r!   r    r$   r   logical_andrD  )r   
values_intconsider_valuesr  ppd	even_dayss         rx   _is_dates_onlyzTimelikeOps._is_dates_only(
  s     tz** 	5Y
$,"4:..d## N?J4D4IJJNNPPTUU	rz   rY  )rq  rr  r|   r   )r   r   r|   r   )r{  r  r|   r
   )r|   r?  )r|   rl   rZ  )rA  rl   r;  r   r|   r
   )r  r  r  rt   )r  r  )r  r9   r  r:   r|   r
   )r  r  r  r   r|   r   r[  rX  )TF)r  r   r  r   )r   )r  r  r  r-   r|   r
   )r  )r  rt   r|   r
   )
r  r2   r  r?  r  rn   r   r   r|   r
   )
r  r8   r  r   rb  r   r  r-   r|   r
   rW  )#r  r\  r]  r^  classmethodrk  r`  r   setterr   rw  rp  r~  r@   r  rA  rB  r  r  r  r  r  r  r]  rK  r   r  r  r  r  r   r  r  r  ra  rb  s   @rx   r  r  0  s         ' ' ['   X: 
[
 
 
 [
 6 6 6 U6@ ( ( ( [ U(T ' ' ' [' 8 8 8 ^8 ) ) ) ^)8<
 <
 <
 <
 <
@  	I 	I 	I 	I 	I 	I: : :2 $+'.	fT fT fT fT fTV $+'.	fN fN fN fN fNV $+'.	fM fM fM fM fMV -1 X X X X X X -1 X X X X X X      @* * * * * * !%B B B B B B B2        [*      
$B $B $B $BT !       0    X    rz   r  r   r   cls_nametuple[ArrayLike, bool]c                d   t          | d          sUt          | t          t          f          s't	          j        |           dk    rt          |           } t          |           } d}n9t          | t                    rt          d| d          t          | d          } t          | t                    s#t          | t                    r-| j        j        dv r|                     d	t          
          } d}nt          | t                    r+|                                 } |                                 } d}nxt          | t          j        t$          f          st	          j        |           } nBt          | t(                    r-| j                            | j        t0                    j        } d}| |fS )Nr   r   FzCannot create a z from a MultiIndex.Tr?  r  r  rg  r  )r7  r   r   tupler   r   rB   rO   r  rb   r_   r]   r   r  rR  r!   _maybe_convert_datelike_arrayrD  r^   r  rN   rG  r  r  r   _values)r   r   r  s      rx   !ensure_arraylike_for_datetimeliker  B
  s    4!! 7$u.. 	274==A3E3E::D6t<<	D-	(	( 7H8HHHIIIT666$%% 4,--26*/T2I2I}}Wt}44	D-	.	. 1133}}rz>:;; 	z$	D.	)	)  ##DJ3#??G:rz   r{  r   c                    d S rv   r   r{  s    rx   validate_periodsr  i
  s    -0Srz   r?  c                    d S rv   r   r  s    rx   r  r  m
  s    +.3rz   r  c                V    | &t          j        |           st          d|            | S )a.  
    If a `periods` argument is passed to the Datetime/Timedelta Array/Index
    constructor, cast it to an integer.

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

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

    Raises
    ------
    TypeError
        if periods is not None or int
    Nz periods must be an integer, got )r   r   r  r  s    rx   r  r  q
  s7    $ 3>'#:#:D7DDEEE Nrz   r   r   ri  c                V    |&|  | |k    rt          d| d| j                   | |} | 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   rf  )r   ri  s     rx   rv  rv  
  s]        5 5"m " "<" "  
 < DKrz   r   'DatetimeTZDtype | np.dtype | ArrowDtypec                    t          | t                    r| j        S t          | t                    r(| j        dvrt          d| d          | j        j        S t          j        |           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	  zdtype=z does not have a resolution.r   )	r   rK   rA  rI   r  r   pyarrow_dtyper   datetime_datar   s    rx   r  r  
  sy     %)) (z	E:	&	& (:T!!DDDDEEE"''E""1%%rz   )rs   rt   )r{   r1   r|   r1   )r   r   r  rt   r|   r  )r{  r   r|   r   )r{  r?  r|   r?  )r{  r  r|   r  )r   r   ri  r   r|   r   )r   r  r|   rt   )
__future__r   r   r   	functoolsr   r  typingr   r   r	   r
   r   r   r   r   r   r  numpyr   pandas._configr   pandas._config.configr   pandas._libsr   r   pandas._libs.tslibsr   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   pandas._libs.tslibs.fieldsr'   r(   pandas._libs.tslibs.np_datetimer)   pandas._libs.tslibs.timedeltasr*   pandas._libs.tslibs.timestampsr+   pandas._typingr,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   pandas.compat.numpyr<   r   pandas.errorsr=   r>   r?   pandas.util._decoratorsr@   pandas.util._exceptionsrA   pandas.core.dtypes.castrB   pandas.core.dtypes.commonrC   rD   rE   rF   rG   rH   pandas.core.dtypes.dtypesrI   rJ   rK   rL   rM   pandas.core.dtypes.genericrN   rO   pandas.core.dtypes.missingrP   rQ   pandas.corerR   rS   rT   rU   pandas.core.algorithmsrV   rW   rX   pandas.core.array_algosrY   pandas.core.arraylikerZ   pandas.core.arrays._mixinsr[   r\   pandas.core.arrays.arrow.arrayr]   pandas.core.arrays.baser^   pandas.core.arrays.integerr_   pandas.core.commoncorecommonr   pandas.core.constructionr`   rF  ra   rb   pandas.core.indexersrc   rd   pandas.core.ops.commonre   pandas.core.ops.invalidrf   rg   pandas.tseriesrh   collections.abcri   rj   rk   rl   rQ  rn   r  ro   rp   rq   rr   r_  ry   r   r   rd  r  r  r  rv  r  r   rz   rx   <module>r     s3   " " " " " " "              
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
      - - - - - - , , , , , ,                                                *        K J J J J J = = = = = = C C C C C C                                   $ / . . . . .         
      5 4 4 4 4 4 K K K K K K                                          
                    
 ? > > > > > * * * * * *        ? > > > > > 2 2 2 2 2 2 3 3 3 3 3 3                           
        < ; ; ; ; ;       
 ' & & & & &           ('''''          .7 7 7 7 71 1 1 1
   2k3 k3 k3 k3 k3X'B k3 k3 k3\171 71 71 71 71( 71 71 71tK K K K K( K K Kd$ $ $ $N 
 0 0 0 
 0 
 . . . 
 .   2   :& & & & & &rz   