
    i|                      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*<   d9d+Zd:d,Z G d- d.euew      Z G d/ d0e      Z G d1 d2e      Z	 	 	 	 	 	 d;d3Zed<d4       Zed=d5       Zd>d6Z	 	 	 	 	 	 d?d7Zd@d8Zy)A    )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   DTScalarOrNaTc                :    t        |       } t        |       |      S N)rg   re   )op_nameops     \/app/cer_product_mecsu/.venv/lib/python3.12/site-packages/pandas/core/arrays/datetimelike.py_make_unpacked_invalid_oprx      s    		!B,#G,R00    c                J     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                @   t        | j                  t              s | g|i |S | j                  d      } |g|i |}|t        u rt        S t        |t
              r| j                  |j                        S |j                  d      }| j                  |      S )NM8[ns]i8)	
isinstancedtyperM   viewr   r   	_box_func_value_from_backing_data)selfargskwargsarrresultres_i8meths         rw   new_methz"_period_dispatch.<locals>.new_meth   s    $**k2.t.v..ii!c+D+F+S=J	*>>&--00T"&&v..ry   )r   r   r1   )r   r   s   ` rw   _period_dispatchr      s*     4[/ / 8ry   c                      e Zd ZU dZded<   ded<   ded<   ded	<   d
ed<   edpd       Z	 dq	 	 	 	 	 drdZedsd       Z	dtdZ
	 	 	 	 dudZdvdZd ZdwdZdxdZedyd       Zddd	 	 	 dzdZd{d|dZ	 d}	 	 	 	 	 d~dZedd       Ze	 	 	 	 dd       Zd fdZdd Z	 	 	 	 	 	 d fd!Zdd"Zdd fd$Zedd%       Zedd&       Zedd'       Zeddd(       Zdd fd)Zd fd*Zd+ Zdd#d,	 	 	 dd-Zd{dd.Zd{dd/Zd0 Z e!dd1       Z"e#ddd2       Z$dd3Z%dd4Z&edd5       Z'edpd6       Z(e)df	 	 	 dd7Z*edd8       Z+edd9       Z,edd:       Z-edd;       Z.edpd<       Z/edpd=       Z0edpd>       Z1d? Z2 e3d@      Z4 e3dA      Z5 e3dB      Z6 e3dC      Z7 e3dD      Z8 e3dE      Z9 e3dF      Z: e3dG      Z; e3dH      Z< e3dI      Z= e3dJ      Z> e3dK      Z?e!	 	 ddL       Z@e!ddM       ZAe!ddN       ZBe!ddO       ZCe!	 	 	 	 ddP       ZDe!ddQ       ZEe!ddR       ZFe!ddS       ZGdT ZHdU ZIddVZJe!ddW       ZKe!ddX       ZLe!dwdY       ZMe!ddZ       ZNe!dd[       ZOd#d\dd]ZP eQd^      d_        ZRd` ZS eQda      db        ZTdc ZUdddZVddeZWeX	 	 	 	 	 	 d fdf       ZYeXdd#dgddh       ZZeXdd#dgddi       Z[d#djdkddlZ\eXdd#dgddm       Z]dddnZ^	 	 	 	 	 	 	 	 	 	 ddo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freqc                     y)NT r   s    rw   _can_hold_naz#DatetimeLikeArrayMixin._can_hold_na   s    ry   NFc                    t        |       rt   r=   )r   datar   r   copys        rw   __init__zDatetimeLikeArrayMixin.__init__   s     "$''ry   c                    t        |       )z
        The scalar associated with this datelike

        * PeriodArray : Period
        * DatetimeArray : Timestamp
        * TimedeltaArray : Timedelta
        r   r   s    rw   _scalar_typez#DatetimeLikeArrayMixin._scalar_type   s     "$''ry   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   values     rw   _scalar_from_stringz*DatetimeLikeArrayMixin._scalar_from_string       $ "$''ry   c                    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     rw   _unbox_scalarz$DatetimeLikeArrayMixin._unbox_scalar  s    * "$''ry   c                    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   others     rw   _check_compatible_withz-DatetimeLikeArrayMixin._check_compatible_with  r   ry   c                    t        |       )zI
        box function to get object from internal representation
        r   )r   xs     rw   r   z DatetimeLikeArrayMixin._box_func/  s     "$''ry   c                F    t        j                  || j                  d      S )z1
        apply box func to passed values
        F)convert)r   	map_inferr   r   valuess     rw   _box_valuesz"DatetimeLikeArrayMixin._box_values5  s     }}VT^^UCCry   c                      j                   dkD  r fdt        t                     D        S  fd j                  D        S )N   c              3  (   K   | ]	  }|     y wrt   r   ).0nr   s     rw   	<genexpr>z2DatetimeLikeArrayMixin.__iter__.<locals>.<genexpr>=  s     6DG6s   c              3  @   K   | ]  }j                  |        y wrt   )r   )r   vr   s     rw   r   z2DatetimeLikeArrayMixin.__iter__.<locals>.<genexpr>?  s     9!DNN1%9s   )ndimrangelenasi8r   s   `rw   __iter__zDatetimeLikeArrayMixin.__iter__;  s1    99q=6U3t9%5669tyy99ry   c                8    | j                   j                  d      S )z
        Integer representation of the values.

        Returns
        -------
        ndarray
            An ndarray with int64 dtype.
        r}   )r   r   r   s    rw   r   zDatetimeLikeArrayMixin.asi8A  s     }}!!$''ry   r   )na_repdate_formatc                   t        |       )z|
        Helper method for astype when converting to strings.

        Returns
        -------
        ndarray[str]
        r   )r   r   r   s      rw   _format_native_typesz+DatetimeLikeArrayMixin._format_native_typesQ  s     "$''ry   c                    dj                   S )Nz'{}')format)r   boxeds     rw   
_formatterz!DatetimeLikeArrayMixin._formatter]  s    }}ry   c                >   t        |      r3|du rt        d      t        j                  t	        |       t
              S |du r!t        j                  | j                  |      S | j                  }| j                  r!|j                         }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       rw   	__array__z DatetimeLikeArrayMixin.__array__d  s     5!u} P  88DJf554<88DMM77>>[[]F%*FLL"ry   c                     y rt   r   r   keys     rw   __getitem__z"DatetimeLikeArrayMixin.__getitem__x      @Cry   c                     y rt   r   r   s     rw   r   z"DatetimeLikeArrayMixin.__getitem__{  s     ry   c                    t        t        t        t        f   t        |   |            }t        j                  |      r|S t        t        |      }| j                  |      |_	        |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      rw   r   z"DatetimeLikeArrayMixin.__getitem__  s]     eD-/0%'2Ec2JK== M $'F --c2ry   c                :   t        | j                  t              }|r| j                  }|S | j                  dk7  rd}|S t        | |      }d}t        |t              rA| j                  '|j                  |j                  | j                  z  }|S | j                  }|S |t        u r| j                  }|S t        j                  |      rSt        j                  |j                  t        j                              }t        |t              r| j!                  |      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        rw   r   z(DatetimeLikeArrayMixin._get_getitem_freq  s    tzz;7	99D& % YY!^D"  &dC0CD#u%99(SXX-A88dii/D   99D   yy
 	 $$S)55chhrxx6HIgu-11'::ry   c                f    t        |||       }t        | 	  ||       |ry | j                          y rt   )rd   r   __setitem___maybe_clear_freq)r   r   r   no_opr   s       rw   r   z"DatetimeLikeArrayMixin.__setitem__  s6     &c5$7 	C' ry   c                     y rt   r   r   s    rw   r   z(DatetimeLikeArrayMixin._maybe_clear_freq  s     	ry   Tc                `   t        |      }|t        k(  r| j                  j                  dk(  r=t	        d|       } | j
                  }t        || j                  d| j                        }|S | j                  j                  dk(  rt        | j                  d      S | j                  | j
                  j                               j                  | j                        S t        |      r`t!        |t"              r@| j%                  |j&                        }|j)                         }|j+                  ||d	
      S | j%                         S t!        |t"              rt,        	| ]  ||      S |j                  dv rO| j
                  }|t0        j2                  k7  rt5        d| j                   d| d      |r|j7                         }|S |j                  dv r| j                  |k7  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
            rw   r  zDatetimeLikeArrayMixin.astype  s   
 U#F?zz#%OT2 .ww#		 ! C'*4==dCC##DIIOO$56>>tzzJJU#%0!66enn6M
002))*E)NN0022~.7>%d>33ZZ4 YYF &tzzl$ug >C C 
 MjjD TZZ5%8UZZ3=N !d!4!4 5ZwGCC. ::d%00ry   c                     y rt   r   r   s    rw   r   zDatetimeLikeArrayMixin.view  s    ry   c                     y rt   r   r   r   s     rw   r   zDatetimeLikeArrayMixin.view	  s    ?Bry   c                     y rt   r   r  s     rw   r   zDatetimeLikeArrayMixin.view  r   ry   c                     y rt   r   r  s     rw   r   zDatetimeLikeArrayMixin.view  s    <?ry   c                "    t         |   |      S rt   )r   r   )r   r   r   s     rw   r   zDatetimeLikeArrayMixin.view  s     w|E""ry   c                4    t         |   ||       d | _        y rt   )r   _putmaskr   )r   maskr   r   s      rw   r  zDatetimeLikeArrayMixin._putmask  s    u%
ry   c                ~   t        |t              r	 | j                  |      }t        || j                        s|t        u r%| j                  |      }	 | j                  |       |S t        |      st        |      t        |      t        |       k7  rt        d      	 | j                  |d      }| j                  |       |S # t        t        f$ r}t        |      |d }~ww xY w# t        $ r}t        |      |d }~ww xY w# t        $ r.}t        t        |dd             rnt        |      |Y d }~|S d }~ww xY w)NzLengths must matchT)allow_objectr   )r~   strr   r   r   r>   r   r   r   r   r  rE   r   _validate_listlikerF   getattr)r   r   errs      rw   _validate_comparison_valuez1DatetimeLikeArrayMixin._validate_comparison_value  sD   eS!8007
 eT556%3,%%e,E8++E2, # e$#E**Z3t9$122<//D/I++E2 ;  56 8'.C78  8'.C78  <"75'4#@A+E2;  <sG   C C( $D C%C  C%(	D1C==D	D<#D77D<)allow_listlikeunboxc                  t        || j                        rnt        |t              r	 | j                  |      }nt        || j                        rt        }nmt        |      r| j                  ||      }t        |      t        || j                        r| j                  |      }n| j                  ||      }t        |      |s|S | j                  |      S # t        $ r#}| j                  ||      }t        |      |d}~ww xY w)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   r  r   r   _validation_error_messager  rP   r   r   rQ   r   r   )r   r   r  r  r  r  s         rw   _validate_scalarz'DatetimeLikeArrayMixin._validate_scalarC  s    0 eT../s#.007
 #5$**5E%[ 00GCC. t778 %%e,E 00GCC.  L!!%((9  .44UNKn#-.s   C 	D#DDc                   t        |d      r t        |dd      dkD  r|j                   d}ndt        |      j                   d}|rd| j
                  j                   d| d}|S d| j
                  j                   d	| d}|S )
a+  
        Construct an exception message on validation error.

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

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

        Returns
        -------
        str
        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   r  msg_gotr  s        rw   r   z0DatetimeLikeArrayMixin._validation_error_message  s     5'"wufa'@1'DV,G$u+../q1G%d&7&7&@&@%A B**1)=  
 &d&7&7&@&@%A Biy*  
ry   c                   t        |t        |             rR| j                  j                  dv r8|s6| j                  |j                  k7  r|j                  | j                  d      }|S t        |t              r4t        |      dk(  r&t        |       j                  g | j                        S t        |d      rO|j                  t        k(  r<t        j                  |      | j                  v r	 t        |       j                  |      }t        |t              rt#        |      }t        |t$        j&                        r5|j                  t        k(  r"t        j(                  |d| j                        }t+        |d	      }t-        |      }t+        |d	      }t/        |      r'	 t        |       j                  || j                        }t        |j                  t0              r@|j2                  j                  | j                  k(  r|j5                         }t+        |d	      }|rt7        |j                        rnAt        |       j9                  |j                        s| j!                  |d      }t        |      | j                  j                  dv r|s|j                  | j                  d      }|S # t        t        f$ r,}|r|cY d }~S | j!                  |d      }t        |      |d }~ww xY w# t        $ r Y 6w xY w)
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  r$  r   r   infer_dtyper   r   r  r   rB   r   ndarraymaybe_convert_objectsrb   pd_arrayrC   rJ   
categories_internal_get_valuesrF   r   )r   r   r  r  r  s        rw   r  z)DatetimeLikeArrayMixin._validate_listlike  sd   eT$Z(zz$&|		UZZ@Wdii%@LeT"s5zQ:,,Rtzz,BB5'"u{{f'< u%)<)<<2 J55e<E eT";EBEeRZZ(U[[F-B --4$**E e48e48%  T
11%tzz1J ekk#34%%3224%e4@OEKK8d00=00=CC. ::??d"<MM$))eM<E_ #I. 2#$88EC#C.c1	26  s6   -J4 "&K2 4K/K*K/K**K/2	K?>K?c                    t        |      r| j                  |      }n| j                  |d      S | j                  |      S )NT)r  )rE   r  r!  _unboxr   s     rw   _validate_setitem_valuez.DatetimeLikeArrayMixin._validate_setitem_value  s?    ++E2E((t(DD{{5!!ry   c                    t        j                  |      r| j                  |      }|S | j                  |       |j                  }|S )zZ
        Unbox either a scalar with _unbox_scalar or an instance of our own type.
        )r   r   r   r   r   r   s     rw   r7  zDatetimeLikeArrayMixin._unbox  sE    
 ==&&u-E
  ''.NNEry   c                    ddl m} t        | ||      } ||      }t        |t              r|j                         S |j                  S )Nr   rm   )	na_action)pandasrn   rW   r~   rO   to_numpyr`   )r   mapperr;  rn   r   s        rw   mapzDatetimeLikeArrayMixin.map  s=     49=vfm,??$$<<ry   c                L   |j                   j                  dv r%t        j                  | j                  t
              S t        |      }t        |t        |             s|j                   t        k(  ret        j                  |d| j                         }|j                   t        k7  r| j                  |      S t        | j                  t              |      S t        j                  | j                  t
              S | j                   j                  dv r't        d|       } |j                  | j                         }	 | j#                  |       t        | j(                  |j(                        S # t$        t&        f$ r( t        j                  | j                  t
              cY S w xY w)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   boolra   r~   r  r   r   r2  rV   r  r   r/  r.  r   r  r   r   r   s     rw   rV   zDatetimeLikeArrayMixin.isin  s<    <<&88DJJd33/7&$t*-||v%22(,%)ZZ
 <<6)99V,,  F 3V<<88DJJd33::??d"8$?D^^DII.F	4 ''/ DIIv{{++ :& 	488DJJd33	4s   ;E, ,4F#"F#c                    | j                   S rt   )_isnanr   s    rw   rQ   zDatetimeLikeArrayMixin.isna>  s    {{ry   c                (    | j                   t        k(  S )z-
        return if each value is nan
        )r   r!   r   s    rw   rF  zDatetimeLikeArrayMixin._isnanA  s    
 yyD  ry   c                H    t        | j                  j                               S )zJ
        return if I have any nans; enables various perf speedups
        )rD  rF  anyr   s    rw   _hasnazDatetimeLikeArrayMixin._hasnaH  s    
 DKKOO%&&ry   c                    | j                   rF|r|j                  |      }|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.
        )rJ  r  r   nanputmaskrF  )r   r   
fill_valuer   s       rw   _maybe_mask_resultsz*DatetimeLikeArrayMixin._maybe_mask_resultsO  sD    & ;;w/!VV
JJvt{{J7ry   c                H    | j                   y| 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    rw   rQ  zDatetimeLikeArrayMixin.freqstrm  s"    @ 99yy   ry   c                l    | j                   dk7  ry	 t        j                  |       S # t        $ r Y y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    rw   inferred_freqz$DatetimeLikeArrayMixin.inferred_freq  s:    : 99>	))$// 		s   ' 	33c                j    | j                   }|y 	 t        j                  |      S # t        $ r Y y w xY wrt   )rQ  r   get_reso_from_freqstrKeyError)r   rQ  s     rw   _resolution_objz&DatetimeLikeArrayMixin._resolution_obj  s;    ,,?	33G<< 		s   & 	22c                .    | j                   j                  S )zO
        Returns day, hour, minute, second, millisecond or microsecond
        )rX  attrnamer   s    rw   
resolutionz!DatetimeLikeArrayMixin.resolution  s     ##,,,ry   c                J    t        j                  | j                  d      d   S )NTtimeliker   r   is_monotonicr   r   s    rw   _is_monotonic_increasingz/DatetimeLikeArrayMixin._is_monotonic_increasing      !!$))d;A>>ry   c                J    t        j                  | j                  d      d   S )NTr]  r   r_  r   s    rw   _is_monotonic_decreasingz/DatetimeLikeArrayMixin._is_monotonic_decreasing  rb  ry   c                v    t        t        | j                  j                  d                  | j                  k(  S )NK)r   rX   r   r   sizer   s    rw   
_is_uniquez!DatetimeLikeArrayMixin._is_unique  s(    8DIIOOC012dii??ry   c                   | j                   dkD  rXt        |dd       | j                  k(  r> || j                         |j                               j	                  | j                        S 	 | j                  |      }t        |dd       }t        |      r?t        j                  |t!        j"                  | j%                  t&                    |      }|S |t(        u r`|t*        j,                  u r't!        j.                  | j                  t0              }|S t!        j2                  | j                  t0              }|S t        | j                  t4              st7        t8        |       } | j:                  |j:                  k7  rWt        |t=        |             s	 |j?                  | j@                  d      }n#|jJ                  }tI        | jJ                  ||      S | jM                  |      } || jJ                  jO                  d      |jO                  d            }tQ        |      }| jR                  |z  }|jU                         r)|t*        j,                  u }	t!        jV                  |||	       |S # t        $ r> t        |d      r"t        |j                  t              rt        cY S t        | ||      cY S w xY w# tB        $ r9 t!        jD                  |jF                        }tI        | jJ                  ||      cY S w xY w)Nr   r   r   r   Fr'  r}   ),r   r  r   r   r   r  r>   r$  r~   r   rI   NotImplementedrf   rF   rU   comp_method_OBJECT_ARRAYr   r  r  r   r   operatorneonesrD  rC  rM   r   TimelikeOpsr   r  r/  r.  r   r`   asm8r)   r   r7  r   rQ   rF  rI  rM  )
r   r   rv   r   r   	other_arr
other_valso_maskr  
nat_results
             rw   _cmp_methodz"DatetimeLikeArrayMixin._cmp_method  sP   99q=WUGT:djjHdjjlEKKM2::4::FF	733E:E w-5! 11BJJt{{623UF MC<X[[ 48 M $**D9M$**k2T*D{{ell*!%d4 %dii% H !&I9$--TVWW[['
DMM&&t,jood.CDe{{V#88:x{{*JJJvtZ0a ! 	7ug&:ekk:+N%%%dE266	7: & $&HHUZZ$8	= MM9b  s*   )I* J4 *5J1!J10J14?K65K6__pow____rpow____mul____rmul____truediv____rtruediv____floordiv____rfloordiv____mod____rmod__
__divmod____rdivmod__c                    t        |t              r|j                  }d}||fS t        |t        t        f      r|j
                  }d}||fS |j                  }|j                  }||fS )zN
        Get the int64 values and b_mask to pass to add_overflowsafe.
        N)r~   r   ordinalr   r   r   rF  r   )r   r   i8valuesr  s       rw   _get_i8_values_and_maskz.DatetimeLikeArrayMixin._get_i8_values_and_mask!  sq     eV$}}HD ~ 	956||HD
 ~ <<DzzH~ry   c                J   t        | j                  t              r| j                  S t	        j
                  |      syt        | j                  t              r| j                  S | j                  j                  dk(  rt        |t              r| j                  S | j                  j                  dk(  rGt        |t              r7|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 y)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     rw   _get_arithmetic_result_freqz2DatetimeLikeArrayMixin._get_arithmetic_result_freq4  s    djj+.99u%		4(99ZZ__#
5)(D99JJOOs"5),!Y%5%5ehh%?
 99OODJJ,499c*5), 99OODJJ,5),499c*99ry   c                   t        j                  | j                  d      s7t        dt	        |       j
                   dt	        |      j
                         t        d|       } ddlm} ddl	m
} |t        usJ t        |      r\| j                  t        j                         j                  d| j                    d	      z   } |j"                  ||j                  
      S t%        |      }| j'                  |      \  } }t        d|       } | j)                  |      \  }}t+        | j,                  t/        j0                  |d
            }|j3                  d| j                    d	      } ||j4                  | j                         }|j3                  d| j                    d	      }| j7                  |      }	 |j"                  |||	      S )Nr   cannot add  and rq   r   ro   )tz_to_dtypezM8[]r   r}   r   r.  r   r   )r   r  r   r  r  r  r   pandas.core.arraysro   pandas.core.arrays.datetimesr  r   rQ   r   to_datetime64r  r.  _simple_newr   _ensure_matching_resosr  r   r   r   r  r   r   r  )
r   r   ro   r  r   other_i8rs  
res_valuesr   new_freqs
             rw   _add_datetimelike_scalarz/DatetimeLikeArrayMixin._add_datetimelike_scalar^  s   tzz3/d4j112%U8L8L7MN  $d+4<C; ]]S%6%6%8%?%?#dii[PQ@R%SSF,=,,V6<<HH% 11%8e$d+77>&!$))RZZ-MN[[3tyyk!34
uxxdii8[[3tyyk!34
33E:(}((5xPPry   c                    t        j                  | j                  d      s7t        dt	        |       j
                   dt	        |      j
                         || z   S )Nr   r  r  )r   r  r   r  r  r  r   s     rw   _add_datetime_arraylikez.DatetimeLikeArrayMixin._add_datetime_arraylike  sS    tzz3/d4j112%U8L8L7MN 
 t|ry   c                   | j                   j                  dk7  r!t        dt        |       j                         t        d|       } t        |      r	| t        z
  S t        |      }| j                  |      \  } }| j                  |      S )Nr   "cannot subtract a datelike from a ro   )r   r   r  r  r  r   rQ   r   r   r  _sub_datetimelike)r   r   tss      rw   _sub_datetimelike_scalarz/DatetimeLikeArrayMixin._sub_datetimelike_scalar  s     ::??c!@dATAT@UVWWOT* ;#:u..r2b%%b))ry   c                   | j                   j                  dk7  r!t        dt        |       j                         t        |       t        |      k7  rt        d      t        d|       } | j                  |      \  } }| j                  |      S )Nr   r  $cannot add indices of unequal lengthro   )
r   r   r  r  r  r   r   r   r  r  r   s     rw   _sub_datetime_arraylikez.DatetimeLikeArrayMixin._sub_datetime_arraylike  s}    ::??c!@dATAT@UVWWt9E
"CDDOT*11%8e%%e,,ry   c                   t        d|       } ddlm} 	 | j                  |       | j                  |      \  }}t        | j                  t        j                  | d            }|j                  d| j                   d	      }| j                  |      }	t        d
|	      }	 |j                   ||j"                  |	      S # t        $ r2}t        |      j                  dd      } t        |      |      |d }~ww xY w)Nro   r   rq   comparesubtractr}   r   timedelta64[r  zTick | Noner  )r   r  rq   _assert_tzawareness_compatr  r  replacer  r  r   r   r   r  r   r.  r  r  r   )
r   r   rq   r  new_messager  rs  r  res_m8r  s
             rw   r  z(DatetimeLikeArrayMixin._sub_datetimelike  s    OT*5	2++E2
  77>&%diiXIT1RS
<		{!!<=33E:x0)~))&8TT  	2c(**9jAK$s)K(c1	2s   C   	C;	-C66C;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         rw   _add_periodz"DatetimeLikeArrayMixin._add_period  ss    tzz3/5d4j6I6I5JKLL 	:

;EJJ'6/d{ry   c                    t        |       rt   r   )r   offsets     rw   _add_offsetz"DatetimeLikeArrayMixin._add_offset  s    !$''ry   c                   t        |      rt        j                  | j                  d      j	                  | j
                  j                        }|j                  t               t        |       j                  || j                        S t        d|       } t        |      }| j                  |      \  } }| j                  |      S )zk
        Add a delta of a timedeltalike

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

        Returns
        -------
        Same type as self
        r  rB  )r   r   r   r  r  r   s     rw   _add_timedelta_arraylikez/DatetimeLikeArrayMixin._add_timedelta_arraylike  sT     t9E
"CDD,d

 
 
' 	e &&u--ry   c                :   | j                  |      \  }}t        | j                  t        j                  |d            }|j                  | j                  j                        }| j                  |      }t        |       j                  || j                  |      S )Nr}   r   r  )r  r   r   r   r  r   r   r   r  r  r  )r   r   r  rs  r  r  r  s          rw   r  z)DatetimeLikeArrayMixin._add_timedeltalike  s    77>&%diiHD1QR
__T]]%8%89
33E: Dz%%** & 
 	
ry   c                   t        | j                  t              r;t        dt	        |       j
                   dt	        t              j
                         t        j                  | j                  t        j                        }|j                  t               |j                  | j                  j                        }t	        |       j                  || 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     rw   _add_natzDatetimeLikeArrayMixin._add_nat  s    
 djj+.d4j112%S	8J8J7KL  $**BHH5DT]]001Dz%%** & 
 	
ry   c                2   t        j                  | j                  t         j                        }|j	                  t
               | j                  j                  dv r+t        d|       } |j                  d| j                   d      S |j                  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   r.  r  s     rw   _sub_natzDatetimeLikeArrayMixin._sub_nat  sq     $**BHH5D::??d"7>D;;dii[:;;;;011ry   c                .   t        | j                  t              s7t        dt	        |      j
                   dt	        |       j
                         t        d|       } | j                  |       | j                  |      \  }}t        | j                  t        j                  | d            }t        j                  |D cg c]  }| j                  j                  |z   c}      }|| j                   }n| j                   |z  }t"        ||<   |S c c}w )Ncannot subtract  from rp   r}   r   )r~   r   rM   r  r  r  r   r   r  r   r   r   r  r`   r   baserF  r   )r   r   r  rs  new_i8_datar   new_datar  s           rw   _sub_periodlikez&DatetimeLikeArrayMixin._sub_periodlike-  s     $**k2"4;#7#7"8tDz?R?R>ST  M4(##E*77>&&tyy"**hYd2ST88EATYY^^a/EF>;;D ;;'D Fs    D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        || j                  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)rl  addsubr   r   r   warningswarnr  r  r?   rA   r   r  r   r  )r   r   rv   r  s       rw   _addsub_object_arrayz+DatetimeLikeArrayMixin._addsub_object_arrayF  s      hllHLL1111u:?tyyA~ dE!H%%,-MM;:&&''79"+-	 zzU[[(C4::u{{*CC(C("**U*;<
ry   )skipnac                   |dvrt        d| dt        |              t        t        |      } || j	                         fd|i|}t        |       j                  || j                        S )N>   cummaxcumminzAccumulation z not supported for r  r   )r  r  r  rY   r   r  r   )r   namer  r   rv   r   s         rw   _accumulatez"DatetimeLikeArrayMixin._accumulatek  sm    ++mD61DT$ZLQRR/6DIIK99&9Dz%%fDJJ%??ry   __add__c                   t        |dd       }t        |      }|t        u r| j                         }nt	        |t
        t        t        j                  f      r| j                  |      }nt	        |t              rXt        j                  | j                  d      r8t        |j                        j!                  d      }| j                  |      }nt	        |t"              r| j%                  |      }nt	        |t&        t        j(                  f      r| j+                  |      }nt	        |t,              r3t        j                  | j                  d      r| j/                  |      }nt        j0                  |      rjt	        | j                  t2              st5        |       t7        d|       }|j9                  ||j                  j:                  z  t<        j>                        }nt        j                  |d      r| jA                  |      }ntC        |      r!| jE                  |t<        j>                        }nt        j                  |d      st	        |tF              r| jI                  |      S tK        |      rit	        | j                  t2              st5        |       t7        d|       }|j9                  ||j                  j:                  z  t<        j>                        }ntL        S t	        |t        jN                        rDt        j                  |j                  d      r$dd	l(m)}  |jT                  ||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   r/  r   r  r   
datetime64r  r   r  
is_integerrM   r+   r   _addsub_int_array_or_scalar_nrl  r  r  rF   r  rK   r  rD   rj  r1  r  rq   r  r   r   other_dtyper   tdobjrq   s          rw   r  zDatetimeLikeArrayMixin.__add__t  sX   eWd3.u5 C<:>--/Fi@A33E:Fs#

D(I(005B33B7Fz*%%e,F"--892259Fv&3??4::s+K%%e,F^^E" djj+6.t44}d+C44USYY\\5I8<<XF __[#.2259F[)..uhllCF__[#.*3
 //66k*djj+6.t44}d+C44USYY\\5I8<<XF "!fbjj)coofllC.P90>00v||LLry   c                $    | j                  |      S rt   )r  r   s     rw   __radd__zDatetimeLikeArrayMixin.__radd__  s    ||E""ry   __sub__c                   t        |dd       }t        |      }|t        u r| j                         }nt	        |t
        t        t        j                  f      r| j                  |       }nt	        |t              rYt        j                  | j                  d      r9t        |j                        j!                  d      }| j                  |       }n#t	        |t"              r| j%                  |       }nt	        |t&        t        j(                  f      r| j+                  |      }nt        j,                  |      rjt	        | j                  t.              st1        |       t3        d|       }|j5                  ||j                  j6                  z  t8        j:                        }nMt	        |t<              r| j?                  |      }n*t        j                  |d      r| jA                  |       }n tC        |      r!| jE                  |t8        j:                        }nt        j                  |d      st	        |tF              r| jI                  |      }nt	        |t.              r| j?                  |      }nztK        |      rit	        | j                  t.              st1        |       t3        d|       }|j5                  ||j                  j6                  z  t8        j:                        }ntL        S t	        |t        jN                        rDt        j                  |j                  d      r$dd	l(m)}  |jT                  ||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   r/  r   r  r   r  r  r  rM   r+   r   r  r  rl  r  r   r  r  rF   r  rK   r  rD   rj  r1  r  rq   r  r  s          rw   r  zDatetimeLikeArrayMixin.__sub__  sh   eWd3.u5 C<:>--/Fi@A33UF;Fs#

D(I(005B33RC8Fz*%%uf-F"--892259F^^E" djj+6.t44}d+C44USYY\\5I8<<XFv&))%0F __[#.22E6:F[)..uhllCF__[#.*3
 11%8F[1))%0Fk*djj+6.t44}d+C44USYY\\5I8<<XF "!fbjj)coofllC.P90>00v||LLry   c           	        t        |dd       }t        j                  |d      xs t        |t              }|r|t        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(  rSt        |d      rG|sEt        dt        |       j                    dt        |      j                    d	|j
                   d
      t        | j
                  t"              rDt        j                  |d      r.t        dt        |       j                    d|j
                         t        j                  | j
                  d      rt%        d|       } |  |z   S | |z
  }|j
                  j                  dk(  r7t        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   r$  r  r  r  rM   r   )r   r   r  other_is_dt64ro   flippeds         rw   __rsub__zDatetimeLikeArrayMixin.__rsub__  s   eWd3S9 
Z>
 S__TZZ= }}U# '$..e%;<<444U%++N4<ZZ__#w(? "4:#6#6"7v;''(%++a9  

K0S__[RU5V.tDz/B/B.C6%++WXX__TZZ-($/DEU?",==$"4:#6#6"7vd5k>R>R=ST  xry   c                v    | |z   }|d d  | d d  t        | j                  t              s|j                  | _        | S rt   r~   r   rM   r   r   r   r   r   s      rw   __iadd__zDatetimeLikeArrayMixin.__iadd__  6    )Q$**k2DJry   c                v    | |z
  }|d d  | d d  t        | j                  t              s|j                  | _        | S rt   r  r  s      rw   __isub__zDatetimeLikeArrayMixin.__isub__"  r  ry   c                &    t         |   ||      S )N)qsinterpolation)r   	_quantile)r   r  r  r   s      rw   r  z DatetimeLikeArrayMixin._quantile.  s     w Bm DDry   axisr  c                   t        j                  d|       t        j                  || j                         t	        j
                  | 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        rw   minzDatetimeLikeArrayMixin.min6  O     	F#
dii0t}}4G**488ry   c                   t        j                  d|       t        j                  || j                         t	        j
                  | 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        rw   maxzDatetimeLikeArrayMixin.maxH  r  ry   r   )r  r  c                   t        | j                  t              r"t        dt	        |       j
                   d      t        j                  | j                  ||| 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       rw   meanzDatetimeLikeArrayMixin.meanZ  su    Z djj+..tDz/B/B.C D7 7  MMV$))+
 **488ry   c                   t        j                  d|       |#t        |      | j                  k\  rt	        d      t        j                  | j                  ||      }| j                  ||      S )Nr   z abs(axis) must be less than ndimr  )	r  validate_medianabsr   r   rT   	nanmedianr   r  r  s        rw   medianzDatetimeLikeArrayMixin.median  s^    
2v&D	TYY 6?@@!!$--d6J**488ry   c                   d }|r| j                         }t        j                  | j                  d      |      \  }}|j                  | j                  j
                        }t        t        j                  |      }| j                  |      S )Nr}   )r  )
rQ   rR   moder   r   r   r   r   r1  r   )r   dropnar  i8modes_npmodess         rw   _modezDatetimeLikeArrayMixin._mode  sj    99;D__TYYt_4@
,,t}}223rzz7+&&w//ry   c                  | j                   }|j                  dk(  r)|dv rt        d| d      |dv r^t        d| d| d      t        |t              r)|dv rt        d| d	      |dv r%t        d| d
| d      |dv rt        d| d	      | j
                  j                  d      }ddlm}	 |	j                  |      }
 |	||
|      } |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"                  ||j                         S |j                  | j
                  j                         }| j%                  |      S )Nr   )sumprodcumsumcumprodvarskewkurtz,datetime64 type does not support operation 'r#  )rI  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)).)r  r!  r#  r$  r"  z"timedelta64 type does not support r|   r   )WrappedCythonOp)howr   has_dropped_na)	min_countngroupscomp_idsr  )stdsemr  z-'std' and 'sem' are not valid for PeriodDtyperB  zm8[r  r   )r   r   r  r~   rM   r   r   pandas.core.groupby.opsr&  get_kind_from_how_cython_op_ndim_compatr'  cast_blocklistr  rq   r   r.  r  r   )r   r'  r(  r)  r*  idsr   r   npvaluesr&  r   rv   r  rq   	new_dtypes                  rw   _groupby_opz"DatetimeLikeArrayMixin._groupby_op  s    

::QQ"NseST UVVn$u 4475E 
 {+QQ"?uK PQQn$u 77:e;H 
 >>@[QRR ==%%h/;0054O.R..

 

 66R&&&  8+++. 9$**k2 OPP8$?Ddii[*I#3J->--j
@P@PQQ__T]]%8%89
&&z22ry   returnrD  )NNF)r   Dtype | Noner   rD  r7  None)r7  ztype[DatetimeLikeScalar])r   r  r7  rr   )r   rr   r7  z)np.int64 | np.datetime64 | np.timedelta64)r   rr   r7  r9  r7  r   )r7  rj   )r7  znpt.NDArray[np.int64])r   zstr | floatr7  npt.NDArray[np.object_])F)r   rD  r7  zCallable[[object], str])NN)r   zNpDtype | Noner   zbool | Noner7  r   )r   r6   r7  rr   )r   z(SequenceIndexer | PositionalIndexerTupler7  r
   )r   r4   r7  zSelf | DTScalarOrNaT)r7  r   )r   z,int | Sequence[int] | Sequence[bool] | slicer   zNaTType | Any | Sequence[Any]r7  r9  r7  r9  T)r   rD  r7  r
   )r   zLiteral['M8[ns]']r7  ro   )r   zLiteral['m8[ns]']r7  rq   ).)r   r8  r7  r,   rt   )r  npt.NDArray[np.bool_]r7  r9  )r  rD  r  rD  )r  rD  r7  r  )r  rD  )r7  z6np.int64 | np.datetime64 | np.timedelta64 | np.ndarray)r;  zLiteral['ignore'] | None)r   r,   r7  r?  )r7  r?  )r   r   r7  r   )r7  z
str | None)r7  zResolution | None)r7  r  )r7  z@tuple[int | npt.NDArray[np.int64], None | npt.NDArray[np.bool_]])r7  ro   )r   ro   r7  ro   )r   zdatetime | np.datetime64r7  rq   )r   ro   r7  rq   )r   zTimestamp | DatetimeArrayr7  rq   )r   r   r7  rp   )r   rq   r7  r
   )r   zTimedelta | TimedeltaArrayr7  r
   )r   zPeriod | PeriodArrayr7  r;  )r   r;  r7  r   )r  r  r  rD  r7  r
   )r  znpt.NDArray[np.float64]r  r  r7  r
   )r  AxisInt | Noner  rD  )r  rD  r  r@  )r  rD  )
r'  r  r(  rD  r)  intr*  rA  r2  znpt.NDArray[np.intp])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  r!  r   r  r8  r   r7  r\   r?  rV   rQ   rF  rJ  r!   rO  rQ  rT  rX  r[  ra  rd  rh  ru  rx   rv  rw  rx  ry  rz  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  r  r  r5  __classcell__r   s   @rw   r   r      s    $#44))
  IN('(AE(	(
 ( (((("(	2(.(,(D: 
( 
(  (-$
($
(	 
( AE#2=	( C C5 
 
&<!9! -! 
	!,
71r  B BC C? ?#
"P  %;) 	;)
 ;)z>@D" 
 
" 	  	 2,n ! ! ' ' .24 	< !! !!F ! !F   - - ? ? ? ? @ @7v (	2G(4H'	2G(4H+M:K,^<L,^<L-o>M'	2G(4H*<8J+M:K
	I $ ' 'R Q QB   *-*	* *$ 
- 
- U U& 
 
(.(.$ 
 
 
 
* 2 2&  0 " "H 8< @ i(9 )9v# i(9 )9v'R E#E E 
	E E ,0 9 9" ,0 9 9" &*! 89t /3D 9 90H3 H3 	H3
 H3 H3 "H3ry   r   c                      e Zd ZdZddZy)DatelikeOpszK
    Common ops for DatetimeIndex/PeriodIndex, but not TimedeltaIndex.
    c                    | j                  |t        j                        }t               r(ddlm} t        | |t        j                              S |j                  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   rL  r   r<  rL  r3  r  r   )r   r   r   rL  s       rw   strftimezDatelikeOps.strftime  sP    Z **{266*R*F+rvv*FGG}}V%}00ry   N)r   r  r7  r;  )r  rB  rC  rD  rN  r   ry   rw   rJ  rJ    s    21ry   rJ  c                      e Zd ZdZed        Zed        Zej                  d"d       Ze	d#d       Z
e	ed$d              Ze	 	 	 	 d%d       Zed&d       Zed'd	       Zd(d)dZd Zd* fdZd Z	 	 d+	 	 	 	 	 d,dZ	 	 d+	 	 	 	 	 d,dZ	 	 d+	 	 	 	 	 d,dZdd
dd-dZdd
dd-dZd"dZd.dZd/ fdZ	 	 d0	 	 	 d1 fdZe	 d2	 	 	 	 	 d3 fd       Zd4d5 fdZ	 	 	 	 	 	 	 	 	 	 d6dZdddd	 	 	 	 	 	 	 	 	 d7 fd Z ed8d!       Z! xZ"S )9ro  zK
    Common ops for TimedeltaIndex/DatetimeIndex, but not PeriodIndex.
    c                    t        |       rt   r   )r  r   r   s      rw   _validate_dtypezTimelikeOps._validate_dtype5  s    !#&&ry   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    rw   r   zTimelikeOps.freq9  s    8 zzry   c                    |qt        |      }| j                  | |       | j                  j                  dk(  r!t	        |t
        t        f      st        d      | j                  dkD  rt        d      || _
        y )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     rw   r   zTimelikeOps.freqW  si    e$E$$T51zz#%js.L JKKyy1} !@AA
ry   c                R   |d| _         y|dk(  r(| j                   t        | j                        | _         yy|t        j                  u ry| j                   0t        |      } t        |       j                  | |fi | || _         yt        |      }t        || j                          y)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&   rT  r   
no_defaultr  rV  _validate_inferred_freq)r   r   validate_kwdss      rw   _maybe_pin_freqzTimelikeOps._maybe_pin_freqd  s     <DJW_ zz! 't'9'9:
 " S^^# ZZ T?D*DJ**4GGDJ T?D#D$**5ry   c           	        |j                   }|j                  dk(  s||j                  k(  ry	  | j                  d|d   dt	        |      ||j
                  d|}t        j                  |j                  |j                        st        y# t        $ r0}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   r.  z	non-fixedInferred frequency 9 from passed values does not conform to passed frequency r   )rT  rg  rQ  _generate_ranger   r.  r   array_equalr   r   r  )r  indexr   r   inferredon_freqr  s          rw   rV  zTimelikeOps._validate_frequency  s     &&::?h$,,6	)c)) AhE
ZZ G >>%**gll;   < 	c#h& 	 %hZ 088<~G 	s   AB 	C+C  Cc                    t        |       rt   r   )r  r^  r_  r`  r   r   r   s          rw   rc  zTimelikeOps._generate_range  s     "#&&ry   c                @    t        | j                  j                        S rt   )r    r   r   r   s    rw   r   zTimelikeOps._creso  s    "4==#6#677ry   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    rw   r.  zTimelikeOps.unit  s    6 TZZ((ry   Tc                   |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                  ||| 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   r.  r(  r   r  r4  r   s          rw   r/  zTimelikeOps.as_unit  s    T ..HIIDJJOO,BtfA67(Q
djj"((+"((Iot,//B'2D9I Dz%% & 
 	
ry   c                    | j                   |j                   k7  rS| j                   |j                   k  r| j                  |j                        } | |fS |j                  | j                        }| |fS rt   )r   r/  r.  r   s     rw   r  z"TimelikeOps._ensure_matching_resos  s^    ;;%,,&{{U\\)||EJJ/ U{ dii0U{ry   c                    |t         j                  t         j                  t         j                  fv r2t	        |      dk(  r$|d   | u r t        ||      | j                  fi |S t        |    ||g|i |S )Nr   r   )	r   isnanisinfisfiniter   r  r   r   __array_ufunc__)r   ufuncmethodinputsr   r   s        rw   ru  zTimelikeOps.__array_ufunc__%  sq    bhh"++66Fq q	T! *75&)$--B6BBw&ufHvHHHry   c                L   t        | j                  t              rOt        d|       } | j	                  d       }|j                  ||||      }|j	                  | j                  ||      S | j                  d      }t        t        j                  |      }t        || j                        }|dk(  r| j                         S t        |||      }	| j                  |	t              }|j                  | j                   j                        }| j#                  || j                        S )Nro   )	ambiguousnonexistentr}   r   rN  r   )r~   r   rK   r   tz_localize_roundr   r   r   r1  r*   r   r   r(   rO  r!   r   r  )
r   r   r  rz  r{  naiver   r   nanos	result_i8s
             rw   r~  zTimelikeOps._round0  s    djj/2.D$$T*E\\$iEF%%9+ &   4bjj&)"45A:99;!&$6	))))ET]]001djj99ry   c                F    | j                  |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   rz  r{  s       rw   roundzTimelikeOps.roundF  s     L {{4!:!:I{SSry   c                F    | j                  |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       rw   floorzTimelikeOps.floor  s     L {{4!4!4iMMry   c                F    | j                  |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       rw   ceilzTimelikeOps.ceil	  s     L {{4!3!3YLLry   Nr  c               d    t        j                  | j                  ||| j                               S Nr  )rT   nananyr   rQ   r   r  r  s      rw   rI  zTimelikeOps.any	  s!    }}T]]f499;WWry   c               d    t        j                  | j                  ||| j                               S r  )rT   nanallr   rQ   r  s      rw   r%  zTimelikeOps.all	  s#     }}T]]f499;WWry   c                    d | _         y rt   rS  r   s    rw   r   zTimelikeOps._maybe_clear_freq	  s	    
ry   c                "   |ntt        |       dk(  rJt        |t              r:| j                  j                  dk(  r=t        |t
        t        f      s't        d      |dk(  sJ t        | j                        }| 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
        r   r   rU  rX  )r   r~   r   r   r   r   r   r  r&   rT  r   r   )r   r   r   s      rw   
_with_freqzTimelikeOps._with_freq	  s~     <Y!^
4 <zz#%jc{.K JKK 7?"?T//0Diik	
ry   c                    t        | j                  t        j                        r| j                  S t        |          S rt   )r~   r   r   r   r   _values_for_json)r   r   s    rw   r  zTimelikeOps._values_for_json	  s-    djj"((+== w'))ry   Fc                   | j                   |rX| j                   j                  dk  r?t        j                  t	        |       dz
  ddt        j
                        }| d d d   }||fS t        j                  t	        |       t        j
                        }| 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.)use_na_sentinel)r   r   r   aranger   intpr   NotImplementedErrorr  r  r   	factorize)r   r  sortcodesuniquesr   s        rw   r  zTimelikeOps.factorize	  s    
 99 		a		#d)a-RrwwGtt* '>! 		#d)277;))+'>! &(d)<)<(= >= = 
 w  AAry   r   c                4   t         |   ||      }|d   |dk(  rv|D cg c]  }t        |      s| }}j                  Ot	        fd|D              r;t        |d d |dd  d      }t	        fd|D              rj                  }||_        |S c c}w )Nr   c              3  P   K   | ]  }|j                   j                   k(    y wrt   r   )r   r   r  s     rw   r   z0TimelikeOps._concat_same_type.<locals>.<genexpr>	  s     +R1AFFchh,>+Rs   #&r  r   T)strictc              3  Z   K   | ]"  }|d    d   j                   z   |d   d    k(   $ yw)r   r  r   Nr  )r   pairr  s     rw   r   z0TimelikeOps._concat_same_type.<locals>.<genexpr>	  s/     NtAwr{SXX-a;Ns   (+)r   _concat_same_typer   r   r%  zipr   )	r  	to_concatr  new_objr   pairsr  r  r   s	          @rw   r  zTimelikeOps._concat_same_type	  s     '+It<l19 %.8qQ8I8xx#+R	+R(RIcrNIabM$GNNN"xxH$,GM 9s
   BBc                J    t         |   |      }| j                  |_        |S )N)order)r   r   r   r   )r   r  r  r   s      rw   r   zTimelikeOps.copy	  s#    ',U,+		ry   c          
         |dk7  rt         |s| j                  }	n| j                  j                         }	t        j                  |	f||||||d| |s| S t        |       j                  |	| j                        S )z2
        See NDFrame.interpolate.__doc__.
        linear)rw  r  re  limitlimit_direction
limit_arear   )r  r   r   rS   interpolate_2d_inplacer  r  r   )
r   rw  r  re  r  r  r  r   r   out_datas
             rw   interpolatezTimelikeOps.interpolate	  s      X%%}}H}}))+H&&		
+!		
 		
 KDz%%hdjj%AAry   )
allow_fillrN  r  c                  t         |   ||||      }t        j                  |t        j                        }t        j                  |t        |             }t        |t              r| j                  |      }||_        |S )N)indicesr  rN  r  r   )r   taker   r  r  r   maybe_indices_to_slicer   r~   r   r   r   )	r   r  r  rN  r  r   maybe_slicer   r   s	           rw   r  zTimelikeOps.take
  st     
zPT  
 **WBGG400#d)Dk5)))+6DFLry   c                
   t        j                  | j                        sy| j                  }|t        k7  }t        | j                        }t        |      }t        j                  |||z  dk7        j                         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_andr  )r   
values_intconsider_valuesr   ppd	even_dayss         rw   _is_dates_onlyzTimelikeOps._is_dates_only(
  ss     tzz*YY
$,"4::.d# NN?J4D4IJNNPTUU	ry   r<  )r[  dictr7  r9  )r   r   r7  r9  )r`  
int | Noner7  r
   )r7  rA  )r7  rl   r=  )r.  rl   r(  rD  r7  r
   )rv  znp.ufuncrw  r  )raiser  )rz  r9   r{  r:   r7  r
   )r  r@  r  rD  r7  rD  r>  r:  )TF)r  rD  r  rD  )r   )r  zSequence[Self]r  r-   r7  r
   )C)r  r  r7  r
   )
rw  r2   r  rA  re  rn   r   rD  r7  r
   )
r  r8   r  rD  rN  r   r  r-   r7  r
   r6  )#r  rB  rC  rD  classmethodrQ  rF  r   setterr   r\  rV  rc  r@   r   r.  r/  r  ru  r~  r  r  r  rI  r%  r   r  r  r  r  r   r  r  r  rG  rH  s   @rw   ro  ro  0  s    ' '  : 
[[
 
 6 6@ (  (T '",'	' ' 8 8 ) )8<
@	I:2 $+'.	fT !fT %	fT
 
fTV $+'.	fN !fN %	fN
 
fNV $+'.	fM !fM %	fM
 
fMV -1 X -1 X@* !%BB B2  !  
	 *
$B #$B 	$B
 $B $B 
$BT ! 	
   
0  ry   ro  c                   t        | d      sGt        | t        t        f      s#t	        j
                  |       dk(  rt        |       } t        |       } d}n,t        | t              rt        d| d      t        | d      } t        | t              s(t        | t              r5| j                  j                  dv r| j                  d	t        
      } d}| |fS t        | t              r&| j!                         } | j                         } d}| |fS t        | t        j"                  t$        f      st	        j&                  |       } | |fS t        | t(              r7| j*                  j-                  | j.                  t0              j2                  } d}| |fS )Nr   r   FzCannot create a z from a MultiIndex.Tr,  r   r  rM  r|  )r$  r~   r   tupler   r   rB   rO   r  rb   r_   r]   r   r   r=  r!   _maybe_convert_datelike_arrayr1  r^   r  rN   r4  r  r  r   _values)r   r   cls_names      rw   !ensure_arraylike_for_datetimeliker  B
  s\    4!$u.2774=A3E:D6t<	D-	(*8*4GHIIT6$%4,-$**//T2I}}Wt}4  : 
D-	.113}} : rzz>:;zz$ : 
D.	) ##DJJ3#?GG:ry   c                     y rt   r   r`  s    rw   validate_periodsr  i
  s    -0ry   c                     y rt   r   r  s    rw   r  r  m
  s    +.ry   c                P    | #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
    z periods must be an integer, got )r   r  r  r  s    rw   r  r  q
  s/    $ 3>>'#::7)DEE Nry   c                V    |&|  | |k7  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
    ra  rb  )r   rQ  )r   rT  s     rw   rZ  rZ  
  sO        5%m_ 5?<<." 
 < DKry   c                    t        | t              r| j                  S t        | t              r3| 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   r.  rI   r   r   pyarrow_dtyper   datetime_datar   s    rw   rk  rk  
  sk     %)zz	E:	&::T!x'CDEE""'''E"1%%ry   )ru   r  )r   r1   r7  r1   )r   rD  r  r  r7  ztuple[ArrayLike, bool])r`  r9  r7  r9  )r`  rA  r7  rA  )r`  r  r7  r  )r   r   rT  r   r7  r   )r   z'DatetimeTZDtype | np.dtype | ArrowDtyper7  r  )
__future__r   r   r   	functoolsr   rl  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`   r3  ra   rb   pandas.core.indexersrc   rd   pandas.core.ops.commonre   pandas.core.ops.invalidrf   rg   pandas.tseriesrh   collections.abcri   rj   rk   rl   r<  rn   r  ro   rp   rq   rr   rE  rx   r   r   rJ  ro  r  r  rZ  rk  r   ry   rw   <module>r     s   "  
 
 
   - ,     * K = C    $ / 
 5 K  
  
 ? * ? 2 3     
 <
 '  (  .7y 71
2k3X'B k3\171( 71tK( Kd$$ #$$N 
 0 
 0 
 . 
 .2
,=:&ry   