
    `Vg5                      d dl mZ d dlmZ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mZ d dlZd dlZd dlmZmZ d dlmZ d dlmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z& d dl'm(Z(m)Z) d d	l*m+Z+ d d
l,m-Z- d dl.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8 d dl9m:Z; d dl<m=Z=m>Z>m?Z? d dl@mAZAmBZBmCZC d dlDmEZE d dlFmGZGmHZHmIZImJZJmKZKmLZLmMZMmNZNmOZOmPZPmQZQmRZRmSZSmTZTmUZUmVZV d dlWmXZXmYZY d dlZm[Z[m\Z\ d dl]m^Z^m_Z_ d dl`maZambZb d dlcmdZdmeZemfZfmgZg d dlhmiZi d dljmkZkmlZl d dlmmnZn d dlompZp d dlqmrc msZt d dlumvZwmxZxmyZy d dlzm{Z{m|Z| d dl}m~Z~ d dlmZmZ d dlmZ er
d dlmZmZmZ ee0ef   Z ed d!"      Z G d# d$e      Z G d% d!eiek      Z G d& d'e      Zd(Zd)Zd*Zd+Z ed,d-"      Z G d. d-e      Zd6d/Zed7d0       Zed8d1       Zd9d2Z	 	 d:d3Zd4 Zd;d5Zy)<    )annotations)datetime	timedeltaN)
TYPE_CHECKINGAnyCallableLiteralSequenceTypeVarUnioncastfinaloverload)algoslib)NDArrayBacked)
BaseOffsetIncompatibleFrequencyNaTNaTTypePeriod
ResolutionTick	Timestampdelta_to_nanosecondsget_unit_from_dtypeiNaTints_to_pydatetimeints_to_pytimedelta	to_offset)RoundToround_nsint64)compare_mismatched_resolutions)integer_op_not_supported)
	ArrayLikeDatetimeLikeScalarDtypeDtypeObjNpDtypePositionalIndexer2DPositionalIndexerTupleScalarIndexerSequenceIndexernpt)function)AbstractMethodErrorNullFrequencyErrorPerformanceWarning)AppenderSubstitutioncache_readonly)find_stack_level)is_all_stringsis_categorical_dtypeis_datetime64_any_dtypeis_datetime64_dtypeis_datetime64tz_dtypeis_datetime_or_timedelta_dtypeis_dtype_equalis_float_dtypeis_integer_dtypeis_list_likeis_object_dtypeis_period_dtypeis_string_dtypeis_timedelta64_dtypeis_unsigned_integer_dtypepandas_dtype)DatetimeTZDtypeExtensionDtype)ABCCategoricalABCMultiIndex)is_valid_na_for_dtypeisna)nanopsops)checked_add_with_arrisinmodeunique1d)OpsMixin)NDArrayBackedExtensionArrayravel_compat)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)DatetimeArrayPeriodArrayTimedeltaArrayDatetimeLikeArrayTDatetimeLikeArrayMixin)boundc                      e Zd ZdZy)InvalidComparisonzm
    Raised by _validate_comparison_value to indicate to caller it should
    return invalid_comparison.
    N)__name__
__module____qualname____doc__     `/var/www/html/hubwallet-dev/venv/lib/python3.12/site-packages/pandas/core/arrays/datetimelike.pyrh   rh      s    
 	rn   rh   c                      e Zd ZU dZded<   ded<   ded<   ded	<   edpd
       ZdqdrdZedsd       Z	dtdZ
	 du	 	 	 	 	 dvdZ	 du	 	 	 	 	 dwdZedxd       Zd ZdxdZd Zedyd       Zddd	 dzdZdud{dZd|d}dZed~d       Ze	 	 	 	 	 	 dd       Z	 	 	 	 	 	 d fdZddZ	 	 	 	 	 	 d fd Zd! Zdd fd#Zedd$       Zedd%       Zedd&       Zeddd'       Zd|d fd(Ze	 d	 	 	 	 	 	 	 d fd*       Zdd fd+Zd, Zd- Z dd"d"d.	 	 	 	 	 dd/Z!dudd0Z"dudd1Z#d2 Z$d3 Z%	 du	 	 	 dd4Z&e'd5        Z(dd6Z)dd7Z*edd8       Z+edpd9       Z,e-df	 	 	 dd:Z.ed;        Z/e/j`                  dd<       Z/edd=       Z1edd>       Z2edd?       Z3edd@       Z4edA        Z5e	 	 	 	 ddB       Z6edpdC       Z7edpdD       Z8edpdE       Z9dF Z: e;dG      Z< e;dH      Z= e;dI      Z> e;dJ      Z? e;dK      Z@ e;dL      ZA e;dM      ZB e;dN      ZC e;dO      ZD e;dP      ZE e;dQ      ZF e;dR      ZGeHddS       ZIeHddT       ZJeHddU       ZKeHdV        ZLeHddW       ZMeHddX       ZNdY ZOdZ ZP	 	 dd[ZQeHd\        ZReHd]        ZSeHdd^       ZTeHdd_       ZU	 d|	 	 	 	 	 dd`ZV eWda      db        ZXdc ZY eWdd      de        ZZdf Z[ddgZ\ddhZ]dd"diddjZ^dd"diddkZ_d"d)dlddmZ`dd"diddnZadddoZb xZcS )re   z
    Shared Base/Mixin class for DatetimeArray, TimedeltaArray, PeriodArray

    Assumes that __new__/__init__ defines:
        _data
        _freq

    and that the inheriting class has methods:
        _generate_range
    ztuple[str, ...]_infer_matcheszCallable[[DtypeObj], bool]_is_recognized_dtypeztuple[type, ...]_recognized_scalars
np.ndarray_ndarrayc                     y)NTrm   selfs    ro   _can_hold_naz#DatetimeLikeArrayMixin._can_hold_na   s    rn   NFc                    t        |       Nr0   )rx   datadtypefreqcopys        ro   __init__zDatetimeLikeArrayMixin.__init__       !$''rn   c                    t        |       )z
        The scalar associated with this datelike

        * PeriodArray : Period
        * DatetimeArray : Timestamp
        * TimedeltaArray : Timedelta
        r|   rw   s    ro   _scalar_typez#DatetimeLikeArrayMixin._scalar_type   s     "$''rn   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|   rx   values     ro   _scalar_from_stringz*DatetimeLikeArrayMixin._scalar_from_string   s    $ "$''rn   c                    t        |       )a  
        Unbox the integer value of a scalar `value`.

        Parameters
        ----------
        value : Period, Timestamp, Timedelta, or NaT
            Depending on subclass.
        setitem : bool, default False
            Whether to check compatibility with setitem strictness.

        Returns
        -------
        int

        Examples
        --------
        >>> self._unbox_scalar(Timedelta("10s"))  # doctest: +SKIP
        10000000000
        r|   )rx   r   setitems      ro   _unbox_scalarz$DatetimeLikeArrayMixin._unbox_scalar   s    , "$''rn   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
        setitem : bool, default False
            For __setitem__ we may have stricter compatibility restrictions than
            for comparisons.

        Raises
        ------
        Exception
        r|   rx   otherr   s      ro   _check_compatible_withz-DatetimeLikeArrayMixin._check_compatible_with   s    . "$''rn   c                    | j                   S r{   )ru   rw   s    ro   _datazDatetimeLikeArrayMixin._data  s    }}rn   c                    t        |       )zI
        box function to get object from internal representation
        r|   )rx   xs     ro   	_box_funcz DatetimeLikeArrayMixin._box_func  s     "$''rn   c                F    t        j                  || j                  d      S )z1
        apply box func to passed values
        F)convert)r   	map_inferr   )rx   valuess     ro   _box_valuesz"DatetimeLikeArrayMixin._box_values  s     }}VT^^UCCrn   c                      j                   dkD  r fdt        t                     D        S  fd j                  D        S )N   c              3  (   K   | ]	  }|     y wr{   rm   ).0nrx   s     ro   	<genexpr>z2DatetimeLikeArrayMixin.__iter__.<locals>.<genexpr>#  s     6DG6s   c              3  @   K   | ]  }j                  |        y wr{   )r   )r   vrx   s     ro   r   z2DatetimeLikeArrayMixin.__iter__.<locals>.<genexpr>%  s     9!DNN1%9s   )ndimrangelenasi8rw   s   `ro   __iter__zDatetimeLikeArrayMixin.__iter__!  s1    99q=6U3t9%5669tyy99rn   c                8    | j                   j                  d      S )z
        Integer representation of the values.

        Returns
        -------
        ndarray
            An ndarray with int64 dtype.
        i8)ru   viewrw   s    ro   r   zDatetimeLikeArrayMixin.asi8'  s     }}!!$''rn   r   )na_repdate_formatc                   t        |       )z|
        Helper method for astype when converting to strings.

        Returns
        -------
        ndarray[str]
        r|   )rx   r   r   s      ro   _format_native_typesz+DatetimeLikeArrayMixin._format_native_types7  s     "$''rn   c                    dj                   S )Nz'{}')format)rx   boxeds     ro   
_formatterz!DatetimeLikeArrayMixin._formatterC  s    }}rn   c                x    t        |      r$t        j                  t        |       t              S | j
                  S )Nr~   )rA   nprX   listobjectru   rx   r~   s     ro   	__array__z DatetimeLikeArrayMixin.__array__J  s)    5!88DJf55}}rn   c                     y r{   rm   rx   items     ro   __getitem__z"DatetimeLikeArrayMixin.__getitem__P      rn   c                     y r{   rm   r   s     ro   r   z"DatetimeLikeArrayMixin.__getitem__T  s    
 	rn   c                    t        d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
        z(Union[DatetimeLikeArrayT, DTScalarOrNaT])r   superr   r   	is_scalarrd   _get_getitem_freq_freq)rx   keyresult	__class__s      ro   r   z"DatetimeLikeArrayMixin.__getitem__[  sW     68KC8P
 == M ,f5F--c2rn   c                0   t        | j                        }|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)rB   r~   r   r   r[   
isinstanceslicestepEllipsiscomis_bool_indexerr   maybe_booleans_to_slicer   r   uint8r   )rx   r   	is_periodr   new_keys        ro   r   z(DatetimeLikeArrayMixin._get_getitem_freqp  s    $DJJ/	99D& % YY!^D"  &dC0CD#u%99(SXX-A88dii/D   99D   yy
 	 $$S)55chhrxx6HIgu-11'::rn   c                f    t        |||       }t        | 	  ||       |ry | j                          y r{   )r\   r   __setitem___maybe_clear_freq)rx   r   r   no_opr   s       ro   r   z"DatetimeLikeArrayMixin.__setitem__  s6     &c5$7 	C' rn   c                     y r{   rm   rw   s    ro   r   z(DatetimeLikeArrayMixin._maybe_clear_freq  s     	rn   Tc                x   t        |      }t        |      r| j                  j                  dk(  rHt	        d|       } | j
                  }t        || j                  | j                  d| j                        }|S | j                  j                  dk(  rt        | j                  d      S | j                  | j
                  j                               j                  | j                        S t!        |t"              rt$        | M  ||      S t)        |      r| j+                         S t-        |      r | j
                  }t/        |      r|j1                  d	      }|t2        j4                  k7  r6t7        j8                  d
| j                   d| dt:        t=                      n| j
                  dk  j?                         r~t7        j8                  d
| j                   d| dt:        t=                      nH|t2        j@                  k7  r5t7        j8                  d
| j                   d| dt:        t=                      |r|jC                         }|S tE        |      rtG        | j                  |      rtI        |      r&dtK        |       jL                   d| }tO        |      t3        jP                  | |      S )NMra   	timestamp)tzr   boxresomT)r   r   uint64zThe behavior of .astype from z to z is deprecated. In a future version, this astype will return exactly the specified dtype instead of uint64, and will raise if that conversion overflows.
stacklevelr   z is deprecated. In a future version, this astype will raise if the conversion overflows, as it did in this case with negative int64 values.z is deprecated. In a future version, this astype will return exactly the specified dtype instead of int64, and will raise if that conversion overflows.zCannot cast z
 to dtype r   ))rF   rA   r~   kindr   r   r   r   r   _resor   ru   r   ravelreshapeshaper   rH   r   astyperC   r   r?   rE   r   r   r   warningswarnFutureWarningr6   anyint64r   r<   r=   r>   typeri   	TypeErrorasarray)rx   r~   r   i8data	convertedr   msgr   s          ro   r   zDatetimeLikeArrayMixin.astype  sJ   
 U#5!zz#%OT2 .ww#	 ! C'*4==dCC##DIIOO$56>>tzzJJ~.7>%d>33U#,,..e$ YYF(/X.BII%MM7

|4w O> > &#3#5 ii!m((*MM7

|4w O; ; &#3#5 "(("3DJJ<tE7 K: : "/1 M*51"4::u5E" !d!4!4 5ZwGCC. ::d%00rn   c                     y r{   rm   rw   s    ro   r   zDatetimeLikeArrayMixin.view  r   rn   c                     y r{   rm   r   s     ro   r   zDatetimeLikeArrayMixin.view  r   rn   c                     y r{   rm   r   s     ro   r   zDatetimeLikeArrayMixin.view  r   rn   c                     y r{   rm   r   s     ro   r   zDatetimeLikeArrayMixin.view	  r   rn   c                "    t         |   |      S r{   )r   r   )rx   r~   r   s     ro   r   zDatetimeLikeArrayMixin.view  s     w|E""rn   r   c                |   t         	|   ||      }|d   j                  }d }t        |      rj                  }nr|dk(  rm|D cg c]  }t        |      s| }}j                  Ft        fd|D              r2t        |d d |dd        }t        fd|D              rj                  }||_        |S c c}w )Nr   c              3  P   K   | ]  }|j                   j                   k(    y wr{   r   )r   r   objs     ro   r   z;DatetimeLikeArrayMixin._concat_same_type.<locals>.<genexpr>(  s     +R1AFFchh,>+Rs   #&r   c              3  Z   K   | ]"  }|d    d   j                   z   |d   d    k(   $ yw)r   r   r   Nr   )r   pairr   s     ro   r   z;DatetimeLikeArrayMixin._concat_same_type.<locals>.<genexpr>*  s/     NtAwr{SXX-a;Ns   (+)	r   _concat_same_typer~   rB   r   r   allzipr   )
cls	to_concataxisnew_objr~   new_freqr   pairsr   r   s
           @ro   r   z(DatetimeLikeArrayMixin._concat_same_type  s     '+It<l		5!xxHQY %.8qQ8I8xx#+R	+R(RIcrNIabM:NNN"xxH  9s   B9B9c                J    t         |   |      }| j                  |_        |S )N)order)r   r   r   r   )rx   r	  r  r   s      ro   r   zDatetimeLikeArrayMixin.copy0  s#    ',U,+		rn   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        |      w xY w# t        t        f$ r}t        |      |d }~ww xY w# t        t        f$ 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   
ValueErrorr   rh   rs   r   r   r   r   r@   r   _validate_listlikerA   getattr)rx   r   errs      ro   _validate_comparison_valuez1DatetimeLikeArrayMixin._validate_comparison_value:  sM   eS!/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 /'../ 45 8'.C78 45 <"75'4#@A+E2;  <s;   C C# $D C #D2C>>DE#D>>Ec                   t        || j                        rt        }nt        || j                        r| j                  |      }n| j
                  t        u r7t        j                  |      r"t        j                  || j                        }n| j                  |      }t        j                  dt        |       d| j
                  j                   dt        t!                      |}| j#                  |d      S )Nr   zPassing zA to shift is deprecated and will raise in a future version, pass z	 instead.r   Tr   )rK   r~   r   r   rs   r   r   r   
is_integer_from_ordinalr   r   r   r   ri   r   r6   _unbox)rx   
fill_valuenew_fills      ro   _validate_shift_valuez,DatetimeLikeArrayMixin._validate_shift_value^  s     TZZ8J
D$<$<=**:6J
   F*s~~j/I!//
K,,Z8 MM4
+, -8$$--.i9  ,- "J{{:t{44rn   )allow_listliker   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)av  
        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.
        setitem : bool, default True
            Whether to check compatibility with setitem strictness.
        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
        Nr  )r   r   r  r   r  _validation_error_messager   rK   r~   r   rL   rs   r   )rx   r   r  r   r  r  r   s          ro   _validate_scalarz'DatetimeLikeArrayMixin._validate_scalar}  s    6 eT../s#.007
 #5$**5E%[ 00GCC. t778%%e,E 00GCC.  L!!%!995  .44UNKn#-.s   C 	D%DDc                    |r2d| j                   j                   dt        |      j                   d}|S d| j                   j                   dt        |      j                   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
        zvalue should be a 'z"', 'NaT', or array of those. Got 'z
' instead.z' or 'NaT'. Got ')r   ri   r   )rx   r   r  r   s       ro   r  z0DatetimeLikeArrayMixin._validation_error_message  s     %d&7&7&@&@%A B++/;+?+?*@
L  
 &d&7&7&@&@%A BU,,-Z9  
rn   c                   t        |t        |             r|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        |d      }t        |      }t        |d      }t!        |      r'	 t        |       j	                  || j
                        }t#        |j
                        rGt%        |j&                  j
                  | j
                        r|j)                         }t        |d      }|rt+        |j
                        r	 |S t        |       j-                  |j
                        s| j                  |d      }t        |      |S # t        t        f$ r$ |r|cY S | j                  |d      }t        |      w xY w# t        $ r Y w xY w)Nr   r   r~   Textract_numpy)r   r   r   r   _from_sequencer~   hasattrr   r   infer_dtyperq   r  r   r  rZ   pd_arrayr7   r8   r=   
categories_internal_get_valuesrA   rr   )rx   r   r  r   s       ro   r  z)DatetimeLikeArrayMixin._validate_listlike  s   eT$Z(LeT"s5zQ:,,Rtzz,BB5'"u{{f'< u%)<)<<) J55e<E e48e48%  T
11%tzz1J  ,e..44djjA224%e4@OEKK8 	 d00=00=CC. G #I. )#$88EC#C.(	)$  s$   G (&G= G:G:=	H	H	c                    t        |      s| j                  |dd      S | j                  |      }| j                  |      S )NTF)r  r   )r@   r  r  r  r   s     ro   _validate_searchsorted_valuez3DatetimeLikeArrayMixin._validate_searchsorted_value	  sA    E"((tU(SS++E2E{{5!!rn   c                    t        |      r| j                  |      }n| j                  |d      S | j                  |d      S )NT)r  r  )r@   r  r  r  r   s     ro   _validate_setitem_valuez.DatetimeLikeArrayMixin._validate_setitem_value  sC    ++E2E((t(DD{{5${//rn   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   ru   r   s      ro   r  zDatetimeLikeArrayMixin._unbox  sO     ==&&ug&>E
  ''w'?NNErn   c                P    ddl m}  ||       j                  |      j                  S )Nr   )Index)pandasr/  maprX   )rx   mapperr/  s      ro   r1  zDatetimeLikeArrayMixin.map,  s      	!T{v&,,,rn   c                R   t        |d      st        j                  |      }|j                  j                  dv r%t        j
                  | j                  t              S t        |t        |             sg d}|j                  t        k(  rit        j                  |d      }||vrN|dk(  rnHd|v rt        | j                  t              |      S t        j
                  | j                  t              S 	 t        |       j                  |      }	 | j#                  |       t        | j&                  |j&                        S # t         $ r" t        | j                  t              |      cY S w xY w# 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 : set or sequence of values

        Returns
        -------
        ndarray[bool]
        r~   )fiucr   )r   timedelta64r   
datetime64dateperiodF)skipnastringmixed)r$  r   r   r~   r   zerosr   boolr   r   r   r   r%  rP   r   r#  r  r   r   r   )rx   r   	inferableinferreds       ro   rP   zDatetimeLikeArrayMixin.isin7  sQ    vw'ZZ'F<< 4488DJJd33&$t*-I ||v%??6%@9,8+ H,#DKK$7@@!xx

$??9d226:	4''/
 DIIv{{++  9DKK/889
 :& 	488DJJd33	4s$   5E E/ (E,+E,/4F&%F&c                    | j                   S r{   )_isnanrw   s    ro   rL   zDatetimeLikeArrayMixin.isnao  s    {{rn   c                (    | j                   t        k(  S )z-
        return if each value is nan
        )r   r   rw   s    ro   rD  zDatetimeLikeArrayMixin._isnanr  s    
 yyD  rn   c                H    t        | j                  j                               S )zJ
        return if I have any nans; enables various perf speedups
        )r@  rD  r   rw   s    ro   _hasnazDatetimeLikeArrayMixin._hasnay  s    
 DKKOO%&&rn   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.
        )rG  r   r   nanputmaskrD  )rx   r   r  r   s       ro   _maybe_mask_resultsz*DatetimeLikeArrayMixin._maybe_mask_results  sD    & ;;w/!VV
JJvt{{J7rn   c                    | j                   S )zK
        Return the frequency object if it is set, otherwise None.
        r   rw   s    ro   r   zDatetimeLikeArrayMixin.freq  s    
 zzrn   c                    |7t        |      }| j                  | |       | j                  dkD  rt        d      || _        y )Nr   zCannot set freq with ndim > 1)r    _validate_frequencyr   r  r   r   s     ro   r   zDatetimeLikeArrayMixin.freq  s@    e$E$$T51yy1} !@AA
rn   c                H    | j                   y| j                   j                  S )zU
        Return the frequency object as a string if its set, otherwise None.
        N)r   freqstrrw   s    ro   rQ  zDatetimeLikeArrayMixin.freqstr  s!    
 99yy   rn   c                l    | j                   dk7  ry	 t        j                  |       S # t        $ r Y yw xY w)z
        Tries to return a string representing a frequency generated by infer_freq.

        Returns None if it can't autodetect the frequency.
        r   N)r   r`   
infer_freqr  rw   s    ro   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r{   )rQ  r   get_reso_from_freqstrKeyError)rx   rQ  s     ro   _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  attrnamerw   s    ro   
resolutionz!DatetimeLikeArrayMixin.resolution  s     ##,,,rn   c                z   |j                   }|j                  dk(  s||j                  k(  ry	  | j                  d|d   dt	        |      |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   z	non-fixedInferred frequency 9 from passed values does not conform to passed frequency rm   )
rT  sizerQ  _generate_ranger   r   array_equalr   r  r  )r  indexr   kwargsrB  on_freqes          ro   rO  z*DatetimeLikeArrayMixin._validate_frequency  s     &&::?h$,,6	)c)) AhD#e*4KQG >>%**gll;   < 	c!f$  %hZ 088<~G 	s   AB 	B:
+B55B:c                    t        |       r{   r|   )r  r^  r_  r`  r   argsrg  s          ro   rd  z&DatetimeLikeArrayMixin._generate_range   s     "#&&rn   c                J    t        j                  | j                  d      d   S )NTtimeliker   r   is_monotonicr   rw   s    ro   _is_monotonic_increasingz/DatetimeLikeArrayMixin._is_monotonic_increasing	      !!$))d;A>>rn   c                J    t        j                  | j                  d      d   S )NTrm  r   ro  rw   s    ro   _is_monotonic_decreasingz/DatetimeLikeArrayMixin._is_monotonic_decreasing  rr  rn   c                v    t        t        | j                  j                  d                  | j                  k(  S )NK)r   rR   r   r   rc  rw   s    ro   
_is_uniquez!DatetimeLikeArrayMixin._is_unique  s(    8DIIOOC012dii??rn   c           	     \   | j                   dkD  rXt        |dd       | j                  k(  r> || j                         |j                               j	                  | j                        S 	 | j                  |      }t        |dd       }t        |      r^t        j                  d      5  t        j                  |t        j                  | j                  t                    |      }d d d        |S |t         u r`|t"        j$                  u r't        j&                  | j                  t(              }|S t        j*                  | j                  t(              }|S t-        | j.                        st1        t2        |       } | j4                  |j4                  k7  rXt7        |t9        |             s t        j:                  |j<                        }n|j>                  }tA        | j>                  ||      S | jC                  |      } || j>                  jE                  d      |jE                  d            }tG        |      }| jH                  |z  }|jK                         r)|t"        j$                  u }	t        jL                  |||	       |S # t        $ r t        | ||      cY S w xY w# 1 sw Y   S xY w)Nr   r   r~   ignore)r   r   r   )'r   r  r   r   r   r  rh   r^   rA   r   errstaterN   comp_method_OBJECT_ARRAYr   r   r   r   operatorneonesr@  r?  rB   r~   r   TimelikeOpsr   r   r   rX   asm8ru   r#   r  r   rL   rD  r   rJ  )
rx   r   opr~   r   	other_arr
other_valso_maskmask
nat_results
             ro   _cmp_methodz"DatetimeLikeArrayMixin._cmp_method  s   99q=WUGT:djjHdjjlEKKM2::4::FF	733E:E w-5! * 55

4;;v#67 MC<X[[ 48 M $**D9Mtzz*T*DzzU[[(!%d4 !# 4I %I5dmmYPRSS[['
DMM&&t,jood.CDe{{V#88:x{{*JJJvtZ0U ! 	7%dE266	7 Ms   )J (>J!JJ!J+__pow____rpow____mul____rmul____truediv____rtruediv____floordiv____rfloordiv____mod____rmod__
__divmod____rdivmod__c                   t        | j                        s7t        dt        |       j                   dt        |      j                         t        d|       } ddlm} ddlm	} |t        usJ t        |      }|t        u r\| j                  t        j                         j                  d| j                   d      z   } |j                   ||j                  	      S | j"                  |j"                  k7  rt%        d
      | j&                  }t)        ||j*                  | j,                        } ||j.                  | j                        }|j1                  d| j                   d      } |j                   ||| j2                        S )Ncannot add  and rc   r   ra   )tz_to_dtypezM8[]r   z`Addition between TimedeltaArray and Timestamp with mis-matched resolutions is not yet supported.arr_mask)r   unitr~   r   )rD   r~   r   r   ri   r   pandas.core.arraysra   pandas.core.arrays.datetimesr  r   r   ru   to_datetime64r   _unit_simple_newr   NotImplementedErrorr   rO   r   rD  r   r   r   )rx   r   ra   r  r   r   r~   
res_valuess           ro   _add_datetimelike_scalarz/DatetimeLikeArrayMixin._add_datetimelike_scalarZ  sM   #DJJ/d4j112%U8L8L7MN  $d+4<C% C< ]]S%6%6%8%?%?#djj\QR@S%TTF,=,,V6<<HH::$%4 
 YY%b%++Luxxdjj9[[3tzzl!!45
(}((5tyyQQrn   c                    t        | j                        s7t        dt        |       j                   dt        |      j                         t        |      }|| z   S )Nr  r  )rD   r~   r   r   ri   rY   rx   r   s     ro   _add_datetime_arraylikez.DatetimeLikeArrayMixin._add_datetime_arraylike{  sW    #DJJ/d4j112%U8L8L7MN 
 /u5t|rn   c                   | j                   j                  dk7  r!t        dt        |       j                         t        d|       } |t        usJ t        |      }|t        u r	| t        z
  S 	 | j                  |       | j                  }t        ||j                   | j                        }|j                  d      S # t        $ r2}t        |      j                  dd      } t        |      |      |d }~ww xY w)Nr   "cannot subtract a datelike from a ra   comparesubtractr  timedelta64[ns])r~   r   r   r   ri   r   r   r   _assert_tzawareness_compatr  replacer   rO   r   rD  r   )rx   r   r  new_messager   r   s         ro   _sub_datetimelike_scalarz/DatetimeLikeArrayMixin._sub_datetimelike_scalar  s    ::??c!@dATAT@UVWWOT*
 C%  C<#:	2++E2
 YY%b5;;,M{{,--  	2c(**9jAK$s)K(c1	2s   .B? ?	C:-C55C:c                "   | j                   j                  dk7  r!t        dt        |       j                         t        |       t        |      k7  rt        d      t        d|       } t        |      }	 | j                  |       | j                  }|j                  }t        || | j                  |j                        }|j                  d      S # t        $ r2}t        |      j                  dd      } t        |      |      |d }~ww xY w)	Nr   r  $cannot add indices of unequal lengthra   r  r  r  b_maskr  )r~   r   r   r   ri   r   r  r   rY   r  r  r  r   rO   rD  r   )rx   r   r  r  self_i8other_i8
new_valuess          ro   _sub_datetime_arraylikez.DatetimeLikeArrayMixin._sub_datetime_arraylike  s    ::??c!@dATAT@UVWWt9E
"CDDOT*.u5	2++E2
 ))::)hYU\\

 011  	2c(**9jAK$s)K(c1	2s   5C 	D-D		Dc                   t        | j                        s!t        dt        |       j                         | j                  |       t        | j                  |j                   | j                        }t        j                  |D cg c]  }| j                  j                  |z   c}      }| j                  rt        || j                  <   |S c c}w )Nzcannot subtract Period from a r  )rB   r~   r   r   ri   r   rO   r   ordinalrD  r   rX   r   baserG  r   )rx   r   new_i8_datar   new_datas        ro   _sub_periodz"DatetimeLikeArrayMixin._sub_period  s    tzz*<T$Z=P=P<QRSS 	##E**II~
 88EATYY^^a/EF;;$'HT[[! Fs    Cc                    t        | j                        s!t        dt        |       j                         ddlm} t        j                  |j                  | j                        } |||j                        }|| z   S )Nzcannot add Period to a r   )rb   r   )rD   r~   r   r   ri   pandas.core.arrays.periodrb   r   broadcast_tor  r   r   )rx   r   rb   i8valsparrs        ro   _add_periodz"DatetimeLikeArrayMixin._add_period  sc    #DJJ/5d4j6I6I5JKLL 	:

;6

3d{rn   c                    t        |       r{   r|   )rx   offsets     ro   _add_offsetz"DatetimeLikeArrayMixin._add_offset  r   rn   c                   t        |      rt        j                  | j                  d      j	                  | j
                  j                        }|j                  t               t        |       j                  || j                        S t        || j                        }t        | j                  || j                        }|j	                  | j
                  j                        }d}t!        | j"                  t$              st'        | j                        r| j"                  }t        |       j                  || j                  |      S )zk
        Add a delta of a timedeltalike

        Returns
        -------
        Same type as self
        r   r   )r   r  Nr  )rL   r   emptyr   r   ru   r~   fillr   r   r  r   r   rO   r   rD  r   r   r   rB   )rx   r   r  incr  s        ro   _add_timedeltalike_scalarz0DatetimeLikeArrayMixin._add_timedeltalike_scalar  s     ;$**D9>>t}}?R?RSJOOD!:))*DJJ)GG #5tzz:)$))S4;;O
__T]]%8%89
dii&/$***EyyH Dz%%djjx & 
 	
rn   c                $   t        |       t        |      k7  rt        d      t        |      }t        d|      }| j                  }|j                  }t        ||| j                  |j                        } t        |       || j                        S )zl
        Add a delta of a TimedeltaIndex

        Returns
        -------
        Same type as self
        r  rc   r  r   )	r   r  rY   r   r   rO   rD  r   r~   )rx   r   r  r  r  s        ro   _add_timedelta_arraylikez/DatetimeLikeArrayMixin._add_timedelta_arraylike  s}     t9E
"CDD.u5%u-))::)XELL

 tDz*DJJ77rn   c                   t        | j                        r;t        dt        |       j                   dt        t
              j                         t        d|       } 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  zTimedeltaArray | DatetimeArrayr   Nr  )rB   r~   r   r   ri   r   r   r   r  r   r   r  r   r   ru   r  rx   r   s     ro   _add_natzDatetimeLikeArrayMixin._add_nat  s    
 4::&d4j112%S	8J8J7KL  4d; $**BHH5DT]]001Dz%%fDJJT%JJrn   c                    t        j                  | j                  t         j                        }|j	                  t
               |j                  d      S )z+
        Subtract pd.NaT from self
        r   r  )r   r  r   r   r  r   r   r  s     ro   _sub_natzDatetimeLikeArrayMixin._sub_nat%  s8     $**BHH5D{{,--rn   c                (   t        | j                        s.t        d|j                   dt        |       j                         t        d|       } | j                  |       t        | j                  |j                   | j                  |j                        }t        j                  |D cg c]  }| j                  j                  |z   c}      }| j                  s|j                  r"| j                  |j                  z  }t        ||<   |S c c}w )Ncannot subtract z-dtype from rb   r  )rB   r~   r   r   ri   r   _require_matching_freqrO   r   rD  r   rX   r   r  rG  r   )rx   r   new_i8_valuesr   r  r  s         ro   _sub_period_arrayz(DatetimeLikeArrayMixin._sub_period_array4  s    tzz*"5;;-|DJ<O<O;PQ  M4(##E*,II

{T[[
 XX=Iatyy~~1IJ
;;%,,;;-D"Jt	 Js   , Dc                   |t         j                  t         j                  fv sJ t        |      dk(  r| j                  dk(  r || |d         S t        j                  dt        |       j                   dt        t                      | j                  |j                  k(  sJ | j                  |j                  f       t        j                         5  t        j                  dt                || j                  d      t!        j"                  |            }d	d	d	       t%        j'                               }t)        |d
      j+                  | j                        }|S # 1 sw Y   JxY w)z
        Add or subtract array-like of DateOffset objects

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

        Returns
        -------
        result : same class as self
        r   r   z)Adding/subtracting object-dtype array to z not vectorized.r   ry  )categoryONTr!  )r|  addsubr   r   r   r   r   ri   r2   r6   r   catch_warningsfilterwarningsr   r   r   r   r&  r   rZ   r   )rx   r   r  r  r   s        ro   _addsub_object_arrayz+DatetimeLikeArrayMixin._addsub_object_arrayH  s'    hllHLL1111u:?tyyA~dE!H%%7Dz""##35')		
 zzU[[(C4::u{{*CC($$& 	A##H}EDKK,bjj.?@J	A
 ***,-vT:BB4::N	A 	As   AE##E,c                t   |4|| j                   k7  r%t        |t              rt        |      }||z  }| |z   S |dk(  st	        |       dk(  r| j                         S | j                   t        d      | d   || j                   z  z   }| d   || j                   z  z   }| j                  ||d| j                         S )a  
        Shift each value by `periods`.

        Note this is different from ExtensionArray.shift, which
        shifts the *position* of each element, padding the end with
        missing values.

        Parameters
        ----------
        periods : int
            Number of periods to shift by.
        freq : pandas.DateOffset, pandas.Timedelta, or str
            Frequency increment to shift by.
        Nr   zCannot shift with no freqr   r]  )r   r   r  r    r   r   r1   rd  )rx   r`  r   r  r^  r_  s         ro   _time_shiftz"DatetimeLikeArrayMixin._time_shiftn  s    " 		 1$$ t^F&= a<3t9>99;99$%@AAQ'DII--2h499,,
 ##%S$TYY#WWrn   __add__c                   t        |dd       }|t        u r| j                         }n t        |t        t
        t        j                  f      r| j                  |      }nt        |t              r| j                  |      }nt        |t        t        j                  f      r| j                  |      }nt        |t              r(t        | j                         r| j#                  |      }nZt%        j&                  |      rbt)        | j                         st+        |       t-        d|       j/                  || j0                  j2                  z  t4        j6                        }nt        |      r| j9                  |      }nt;        |      r!| j=                  |t4        j6                        }nt?        |      stA        |      r| jC                  |      S tE        |      rbt)        | j                         st+        |       t-        d|       j/                  || j0                  j2                  z  t4        j6                        }ntF        S t        |t        jH                        r#t        |j                         rddl%m&}  ||      S |S Nr~   rb   r   )rc   )'r  r   r  r   r   r   r   r8  r  r   r  r   r9  r  r   rD   r~   r  r   r  rB   r$   r   _addsub_int_array_or_scalarr   r   r|  r  r  rA   r  r:   r;   r  r?   NotImplementedndarrayr  rc   rx   r   other_dtyper   rc   s        ro   r  zDatetimeLikeArrayMixin.__add__  s   eWd3 C<]]_Fi@A33E:Fz*%%e,F"--892259Fv&+?

+K%%e,F^^E" #4::..t44-.JJ		#X\\F
 "+.2259F[)..uhllCF -1F{1S//66k*"4::..t44-.JJ		#X\\F "!fbjj).B6<<.P9!&))rn   c                $    | j                  |      S r{   )r  r  s     ro   __radd__zDatetimeLikeArrayMixin.__radd__  s    ||E""rn   __sub__c                (   t        |dd       }|t        u r| j                         }n-t        |t        t
        t        j                  f      r| j                  |       }nt        |t              r| j                  |       }nt        |t        t        j                  f      r| j                  |      }nt        j                  |      rct!        | j"                        st%        |       t'        d|       j)                  || j*                  j,                  z  t.        j0                        }n%t        |t2              r| j5                  |      }nt7        |      r| j9                  |       }nt;        |      r!| j=                  |t.        j0                        }nt?        |      stA        |      r| jC                  |      }nt!        |      r| jE                  |      }nstG        |      rbt!        | j"                        st%        |       t'        d|       j)                  || j*                  j,                  z  t.        j0                        }ntH        S t        |t        jJ                        r#t7        |j"                        rddl&m'}  ||      S |S r  )(r  r   r  r   r   r   r   r8  r  r   r  r   r9  r  r   r  rB   r~   r$   r   r  r   r   r|  r  r   r  rD   r  rA   r  r:   r;   r  r  r?   r  r  r  rc   r  s        ro   r  zDatetimeLikeArrayMixin.__sub__  s    eWd3 C<]]_Fi@A33UF;Fz*%%uf-F"--892259F^^E" #4::..t44-.JJ		#X\\F v&%%e,F "+.22E6:F[)..uhllCF -1F{1S11%8F[)++E2Fk*"4::..t44-.JJ		#X\\F
 "!fbjj).B6<<.P9!&))rn   c                   t        |dd       }t        |      r[t        | j                        rFt	        j
                  |      rt        |      | z
  S t        |t              sddl	m
}  ||      }|| z
  S t        | j                        rXt        |d      rLt        |j                        s7t        dt        |       j                   dt        |      j                         t        | j                        r9t        |      r.t        dt        |       j                   d|j                         t        | j                        rt!        d|       } |  |z   S | |z
   S )Nr~   r   r  r  z from rc   )r  r9   rD   r~   r   r   r   r   re   r  ra   r$  r   r   ri   rB   r   )rx   r   r  ra   s       ro   __rsub__zDatetimeLikeArrayMixin.__rsub__  s,   eWd3";/4H4T }}U# '$..e%;<<%e,4<#DJJ/w'+EKK8 "4:#6#6"7vd5k>R>R=ST  TZZ(-A+-N.tDz/B/B.C6%++WXX!$**-($/DEU?" rn   c                l    | |z   }|d d  | d d  t        | j                        s|j                  | _        | S r{   rB   r~   r   r   rx   r   r   s      ro   __iadd__zDatetimeLikeArrayMixin.__iadd__*  4    )Qtzz*DJrn   c                l    | |z
  }|d d  | d d  t        | j                        s|j                  | _        | S r{   r  r  s      ro   __isub__zDatetimeLikeArrayMixin.__isub__3  r  rn   r  r<  c                  t        j                  d|       t        j                  || j                         t	        | j
                        rt        j                  | j                  j                  d      ||      }|t        u rt        S |j                  d      }|| j                  dk(  r| j                  |      S | j                  |      S 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.
        rm   M8[ns]r  r   r   )nvvalidate_minvalidate_minmax_axisr   rB   r~   rM   nanminru   r   r   r   _from_backing_data_wrap_reduction_resultrx   r  r<  rg  r   s        ro   minzDatetimeLikeArrayMixin.min?  s     	F#
dii04::&]]""8,4F }
[[&F|tyyA~~~f--**622t}}4G**488rn   c                  t        j                  d|       t        j                  || j                         t	        | j
                        rt        j                  | j                  j                  d      ||      }|t        u r|S |j                  d      }|| j                  dk(  r| j                  |      S | j                  |      S 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.
        rm   r  r  r   r   )r  validate_maxr  r   rB   r~   rM   nanmaxru   r   r   r   r   r  r  s        ro   maxzDatetimeLikeArrayMixin.max\  s     	F#
dii04::&]]""8,4F }[[&F|tyyA~~~f--**622t}}4G**488rn   )r<  r  c                   t        | j                        r"t        dt        |       j                   d      t        j                  | j                  ||| j                               }| j                  ||      S )an  
        Return the mean value of the Array.

        .. versionadded:: 0.25.0

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

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

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

        Notes
        -----
        mean is only defined for Datetime and Timedelta dtypes, not for Period.
        zmean is not implemented for zX since the meaning is ambiguous.  An alternative is obj.to_timestamp(how='start').mean()r  r<  r  )
rB   r~   r   r   ri   rM   nanmeanru   rL   r  )rx   r<  r  r   s       ro   meanzDatetimeLikeArrayMixin.meany  sr    4 4::&.tDz/B/B.C D7 7  MMV$))+
 **488rn   c                  t        j                  d|       |#t        |      | j                  k\  rt	        d      t        | j                        rut        j                  | j                  j                  d      ||      }|j                  d      }|| j                  dk(  r| j                  |      S | j                  |      S t        j                  | j                  ||      }| j                  ||      S )Nrm   z abs(axis) must be less than ndimr  r  r   r   )r  validate_medianabsr   r  rB   r~   rM   	nanmedianru   r   r   r   r  r  s        ro   medianzDatetimeLikeArrayMixin.median  s    
2v&D	TYY 6?@@4::&%%""8,4F [[&F|tyyA~~~f--**622!!$--d6J**488rn   c                   d }|r| j                         }t        | j                  d      |      }|j                  | j                  j                        }t        t        j                  |      }| j                  |      S )Nr   )r  )	rL   rQ   r   ru   r~   r   r   r  r   )rx   dropnar  i8modesnpmodess        ro   _modezDatetimeLikeArrayMixin._mode  sb    99;DtyyT2,,t}}223rzz7+&&w//rn   )returnr@  )NNF)r~   Dtype | Noner  None)r  ztype[DatetimeLikeScalar])r   r  r  DTScalarOrNaT)F)r   r  r   r@  r  z)np.int64 | np.datetime64 | np.timedelta64)r   r  r   r@  r  r  )r  rt   )r  znpt.NDArray[np.int64])r  npt.NDArray[np.object_])r   r@  r{   )r~   zNpDtype | Noner  rt   )r   r,   r  r  )rx   rd   r   z(SequenceIndexer | PositionalIndexerTupler  rd   )rx   rd   r   r*   r  z"DatetimeLikeArrayT | DTScalarOrNaT)r  zBaseOffset | None)r   z,int | Sequence[int] | Sequence[bool] | slicer   zNaTType | Any | Sequence[Any]r  r  )Tr   r@  )rx   rd   r  rd   )r~   zLiteral['M8[ns]']r  ra   )r~   zLiteral['m8[ns]']r  rc   ).)r~   r  r  r%   )r   )r  type[DatetimeLikeArrayT]r  zSequence[DatetimeLikeArrayT]r  intr  rd   )C)r  r@  r   r@  r  r@  )r  r@  r  r  )r  r@  )r   r@  r  z6np.int64 | np.datetime64 | np.timedelta64 | np.ndarray)r  znpt.NDArray[np.bool_])r   rt   r  rt   r  r  )r  z
str | None)r  zResolution | Noner  r  )r  r  r  rd   )r  ra   )r   zdatetime | np.datetime64)r   r   r  r  )r   r   r  rb   )r   z,TimedeltaArray | npt.NDArray[np.timedelta64])r   rb   r  r  )r   rt   )rx   rd   r`  r  r  rd   )r  
int | Noner<  r@  )r<  r@  r  r!  )r  r@  )dri   rj   rk   rl   __annotations__r5   ry   r   propertyr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   classmethodr   r   r  r  r  r  r  r*  r,  r  rU   r1  rP   rL   rD  rG  r   rK  r   setterrQ  rT  rX  r[  rO  rd  rq  rt  rw  r  r_   r  r  r  r  r  r  r  r  r  r  r  r  r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r]   r  r  r  r  r  r  r  r  r  r  r  __classcell__r   s   @ro   re   re      s   	 $#44)) ( ( ((* 5:("(-1(	2(2 5:("(-1(	(8  
(D: 
( 
(  4
(	 
(    6 
  ':	+*<!9! -! 
	!,
R1h        #  %/  
	 4"H5F  %<: 	<:
 <: <:|61f"0 &+"	?& - -3,p ! ! ' ' .24 	<   
[[  ! !     - - $ $L '%'	' ' ? ? ? ? @ @1j i(Gz*Hi(Gz*H!-0K">2L">2L#O4Mi(Gz*H .J!-0K
R R@ 	 	 . .4 2 2.  " 	 	(
>8A82 K K" . .  & # #L 6:$X $X+.$X	$XL i(4 )4l# i(5 )5n!F )-T 9: )-T 9: &*a %9N ,0 9&0 0rn   c                  0    e Zd ZdZ ed      dd       Zy)DatelikeOpszK
    Common ops for DatetimeIndex/PeriodIndex, but not TimedeltaIndex.
    zNhttps://docs.python.org/3/library/datetime.html#strftime-and-strptime-behavior)URLc                r    | j                  |t        j                        }|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 <%(URL)s>`__.

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

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

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

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

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

        Examples
        --------
        >>> rng = pd.date_range(pd.Timestamp("2018-03-10 09:00"),
        ...                     periods=3, freq='s')
        >>> rng.strftime('%%B %%d, %%Y, %%r')
        Index(['March 10, 2018, 09:00:00 AM', 'March 10, 2018, 09:00:01 AM',
               'March 10, 2018, 09:00:02 AM'],
              dtype='object')
        )r   r   Fr   )r   r   rI  r   r   )rx   r   r   s      ro   strftimezDatelikeOps.strftime  s1    b **{266*R}}V%}00rn   N)r   r  r  r  )ri   rj   rk   rl   r4   r,  rm   rn   ro   r)  r)    s%     *.1	.1rn   r)  aM	  
    Perform {op} operation on the data to the specified `freq`.

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

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

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

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

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

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

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

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

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

    **Series**

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

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

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

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

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

    **Series**

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

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

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

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

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

    **Series**

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

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

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

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

    >>> rng_tz.ceil("H", ambiguous=True)
    DatetimeIndex(['2021-10-31 02:00:00+02:00'],
                  dtype='datetime64[ns, Europe/Amsterdam]', freq=None)
    TimelikeOpsTr  c                      e Zd ZU dZded<   dej                  dfddZed        Z	e
dd       Ze
dd	       Zd fd
Zd Z eeez   j%                  d            dd       Z eeez   j%                  d            dd       Z eeez   j%                  d            dd       ZdddddZdddddZd dZd Z	 	 d!	 	 	 d" fdZ xZS )#r  zK
    Common ops for TimedeltaIndex/DatetimeIndex, but not PeriodIndex.
    znp.dtype_default_dtypeNFc                   t        |d      }t        |t              r|j                  dt              }t        |dd       }|d u }|t        j                  ur|nd }t        |t        |             r|rnB||j                  }n3|r1|j                  r%t        |      }t        ||j                  d      \  }}|<t        |      }t        ||j                        st        d| d|j                         |j                  }|j                   }n|| j"                  }t        |t$        j&                        s8t)        d	t        |      j*                   d
t        |       j*                   d      |j,                  dvrt)        d      |j                  dk(  r|j/                  | j"                        }| j1                  ||      }|dk(  r"t)        dt        |       j*                   d      |r|j3                         }|rt        |      }t5        j6                  | ||       || _        ||t        |       j;                  | |       y y y )NTr!  r   na_valuer   Fzdtype=z does not match data dtype zUnexpected type 'z'. 'values' must be a z6, ndarray, or Series or Index containing one of those.)r      z.Only 1-dimensional input arrays are supported.r   inferz#Frequency inference not allowed in z$.__init__. Use 'pd.array()' instead.)r   r~   )rZ   r   rW   to_numpyr   r  r   
no_defaultr   r   r    validate_inferred_freqrF   r=   r~   r   ru   r/  r   r  r  ri   r   r   _validate_dtyper   r   r   r   rO  )rx   r   r~   r   r   rT  explicit_none_s           ro   r   zTimelikeOps.__init__  s&   vT:fl+__Wt_<F63>>1ttfd4j){{&++ 0v{{EJa $U+%eV\\:# 'B6<<.Q  LLE__F]''E&"**-#DL$9$9#::P:&&' (++ 
 ;;f$MNN<<4 [[!4!45F$$VU37?5d4j6I6I5J K, , 
 [[]FT?DtF%@
 T%5J**46 &6 rn   c                    t        |       r{   r|   )r  r   r~   s      ro   r8  zTimelikeOps._validate_dtype  s    !#&&rn   c                @    t        | j                  j                        S r{   )r   ru   r~   rw   s    ro   r   zTimelikeOps._reso  s    "4==#6#677rn   c                ,    t        | j                        S r{   )dtype_to_unitr~   rw   s    ro   r  zTimelikeOps._unit  s    
 TZZ((rn   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  ru   r   __array_ufunc__)rx   ufuncmethodinputsrg  r   s        ro   rC  zTimelikeOps.__array_ufunc__  sq    bhh"++66Fq q	T! *75&)$--B6BBw&ufHvHHHrn   c                T   t        | j                        rOt        d|       } | j                  d       }|j	                  ||||      }|j                  | j
                  ||      S | j                  d      }t        t        j                  |      }t        |      j                  }t        t        |      | j                        }t        |||      }	| j                  |	t              }|j                  | j                   j                        }| j#                  || j                        S )Nra   )	ambiguousnonexistentr   r  r   )r;   r~   r   tz_localize_roundr   r   r   r  r    nanosr   r   r"   rK  r   ru   r  )
rx   r   rQ   rH  rI  naiver   r   rM  	result_i8s
             ro   rL  zTimelikeOps._round  s     ,.D$$T*E\\$iEF%%9+ &   4bjj&)$%%$Yt_djjA!&$6	))))ET]]001djj99rn   round)r  c                F    | j                  |t        j                  ||      S r{   )rL  r!   NEAREST_HALF_EVENrx   r   rH  rI  s       ro   rP  zTimelikeOps.round  s    {{4!:!:I{SSrn   floorc                F    | j                  |t        j                  ||      S r{   )rL  r!   MINUS_INFTYrS  s       ro   rT  zTimelikeOps.floor  s    {{4!4!4iMMrn   ceilc                F    | j                  |t        j                  ||      S r{   )rL  r!   
PLUS_INFTYrS  s       ro   rW  zTimelikeOps.ceil  s    {{4!3!3YLLrn   Tr  c               d    t        j                  | j                  ||| j                               S Nr	  )rM   nananyru   rL   rx   r  r<  s      ro   r   zTimelikeOps.any  !    }}T]]f499;WWrn   c               d    t        j                  | j                  ||| j                               S r[  )rM   nanallru   rL   r]  s      ro   r   zTimelikeOps.all  r^  rn   c                    d | _         y r{   rM  rw   s    ro   r   zTimelikeOps._maybe_clear_freq"  s	    
rn   c                    |n;t        |       dk(  rt        |t              rn|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   r4  )r   r   r   r    rT  r   r   )rx   r   arrs      ro   
_with_freqzTimelikeOps._with_freq%  sZ     <Y!^
4 <  7?"?T//0Diik	
rn   c                   | j                   mt        j                  t        |       t        j                        }| j                         }|r)| j                   j                  dk  r|d d d   }|d d d   }||fS t        | !  |      S )Nr   r   r   )na_sentinel)	r   r   aranger   intpr   r   r   	factorize)rx   rf  sortcodesuniquesr   s        ro   ri  zTimelikeOps.factorizeE  sz    
 99 IIc$irww7EiikG		add!$B$-'>!w [ 99rn   r  )r  r  r   )rD  znp.ufuncrE  r  )raiserm  )r  r!  r<  r@  r  r@  r  )r   F)rf  r  rj  r@  )ri   rj   rk   rl   r"  r   r6  r   r$  r8  r5   r   r  rC  rL  r3   
_round_doc_round_exampler   rP  _floor_examplerT  _ceil_examplerW  r   r   r   rd  ri  r&  r'  s   @ro   r  r    s>    %)U A7F ' '
 8 8 ) )	I:( zN*22g2>?T @T zN*22g2>?N @N zM)11V1<=M >M )-T X )-T XD :: : :rn   c                J   t        | d      s;t        j                  |       dk(  rt        |       } t        j                  |       } d}n,t        | t              rt        d| d      t        | d      } t        | t              r| j                  dt        	      } d}| |fS t        | t        j                  t        f      st        j                  |       } | |fS t        | t              r7| j                  j!                  | j"                  t$        
      j&                  } d}| |fS )Nr~   r   FzCannot create a z from a MultiIndex.Tr!  r   r1  rJ  )r$  r   r   r   r   r   rJ   r   rZ   rW   r5  r   r  rV   rI   r'  takerk  r   _values)r}   r   cls_names      ro   !ensure_arraylike_for_datetimelikerv  Z  s    4!774=A:Dzz$	D-	(*8*4GHIIT6$%}}Wt}4 : rzz>:;zz$ : 
D.	) ##DJJ3#?GG:rn   c                     y r{   rm   r`  s    ro   validate_periodsry  x      rn   c                     y r{   rm   rx  s    ro   ry  ry  }  rz  rn   c                    | Et        j                  |       rt        |       } | S t        j                  |       st	        d|        | S )a9  
    If a `periods` argument is passed to the Datetime/Timedelta Array/Index
    constructor, cast it to an integer.

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

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

    Raises
    ------
    TypeError
        if periods is None, float, or int
    zperiods must be a number, got )r   is_floatr  r  r   rx  s    ro   ry  ry    sN    $ << 'lG
 N	 (<WIFGG Nrn   c                ^    |(|  | |k7  rt        d| d| j                         | |} d}| |f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
    freq_infer : bool

    Returns
    -------
    freq : DateOffset or None
    freq_infer : bool

    Notes
    -----
    We assume at this point that `maybe_infer_freq` has been called, so
    `freq` is either a DateOffset object or None.
    ra  rb  F)r  rQ  )r   rT  
freq_infers      ro   r7  r7    sZ    .   5%m_ 5?<<." 
 \ D
rn   c                ^    d}t        | t              s| dk7  rt        |       } | |fS d}d} | |fS )a  
    Comparing a DateOffset to the string "infer" raises, so we need to
    be careful about comparisons.  Make a dummy variable `freq_infer` to
    signify the case where the given freq is "infer" and set freq to None
    to avoid comparison trouble later on.

    Parameters
    ----------
    freq : {DateOffset, None, str}

    Returns
    -------
    freq : {DateOffset, None}
    freq_infer : bool
        Whether we should inherit the freq of passed data.
    Fr4  TN)r   r   r    )r   r  s     ro   maybe_infer_freqr    sG    " JdJ'7?T?D  JDrn   c                j    t        | t              r| 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   )r   rG   r  r   datetime_datar   s    ro   r>  r>    s.     %)zzE"1%%rn   )r   r@  ru  r  )r`  r  r  r  )r`  floatr  r  )r`  zfloat | Noner  r!  )r  ztuple[BaseOffset | None, bool])r~   zDatetimeTZDtype | np.dtyper  r  )
__future__r   r   r   r|  typingr   r   r   r	   r
   r   r   r   r   r   r   numpyr   pandas._libsr   r   pandas._libs.arraysr   pandas._libs.tslibsr   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.timestampsr$   pandas._typingr%   r&   r'   r(   r)   r*   r+   r,   r-   r.   pandas.compat.numpyr/   r  pandas.errorsr0   r1   r2   pandas.util._decoratorsr3   r4   r5   pandas.util._exceptionsr6   pandas.core.dtypes.commonr7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   pandas.core.dtypes.dtypesrG   rH   pandas.core.dtypes.genericrI   rJ   pandas.core.dtypes.missingrK   rL   pandas.corerM   rN   pandas.core.algorithmsrO   rP   rQ   rR   pandas.core.arraylikerS   pandas.core.arrays._mixinsrT   rU   pandas.core.arrays.baserV   pandas.core.arrays.integerrW   pandas.core.commoncorecommonr   pandas.core.constructionrX   r&  rY   rZ   pandas.core.indexersr[   r\   pandas.core.ops.commonr]   pandas.core.ops.invalidr^   r_   pandas.tseriesr`   r  ra   rb   rc   r  rd   	Exceptionrh   re   r)  rn  ro  rp  rq  r-  r  rv  ry  r7  r  r>  rm   rn   ro   <module>r     s   "      .     K C   / 
 
 5    $
  + 3 3     
 <
 '  ('1219QR 		 	X0X'B X0v071( 71t=
~668 ~];G:( G:\< 
 
 
 
8"#"J8&rn   