
    ip                       d 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 ddl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 ddlmZ dd	lmZ dd
lm Z m!Z!m"Z"m#Z# ddl$m%Z% ddl&m'Z'm(Z( ddl)m*Z* ddl+m,Z,m-Z- ddl.m/Z/m0Z0m1Z1m2Z2 ddl3m4c m5Z6 ddl7m4c m8c m9Z: ddl7m;Z; ddl<m=Z= ddl>m?Z? ddl@mAZA erddlBmCZC ddlDmDZD ddlEmFZFmGZGmHZHmIZI ddlJmKZK  eLe:j                        ZM G d de=e      ZN G d deNe      ZOy)z;
Base and utility classes for tseries type pandas objects.
    )annotations)ABCabstractmethod)TYPE_CHECKINGAnyLiteralSelfcastfinalN)NaTlib)
BaseOffset
ResolutionTick	Timedelta	Timestampparsing	to_offset)abbrev_to_npy_unit)function)InvalidIndexErrorNullFrequencyErrorOutOfBoundsDatetimeOutOfBoundsTimedelta)cache_readonly)
is_integeris_list_like)concat_compat)CategoricalDtypePeriodDtype)DatetimeArrayExtensionArrayPeriodArrayTimedeltaArray)Index)NDArrayBackedExtensionIndex)
RangeIndex)to_timedelta)Sequence)datetime)AxisJoinHowTimeUnitnpt)CategoricalIndexc                      e Zd ZU dZdZded<   dddd"dZed#d	       Zej                  d$d
       Zed%d       Z
ed&d       Zeed'd              Zed&d       Zed(d       Zd)dZd*dZ fdZdZdd	 	 	 	 	 	 	 d+dZed        Z fdZd,d& fdZed-d       Zd.dZd/dZd0dZe	 	 	 	 	 	 d1d       Zd2dZd3d4d Z d! Z! xZ"S )5DatetimeIndexOpsMixinzM
    Common ops mixin to support a unified interface datetimelike Index.
    Fz,DatetimeArray | TimedeltaArray | PeriodArray_dataTr   skipnaaxisc               <    | 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')
        r3   )r2   mean)selfr4   r5   s      ]/app/cer_product_mecsu/.venv/lib/python3.12/site-packages/pandas/core/indexes/datetimelike.pyr7   zDatetimeIndexOpsMixin.mean`   s    Z zzf488    c                .    | j                   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>
        r2   freqr8   s    r9   r=   zDatetimeIndexOpsMixin.freq   s    8 zzr:   c                &    || j                   _        y Nr<   )r8   values     r9   r=   zDatetimeIndexOpsMixin.freq   s      

r:   c                .    | j                   j                  S r@   )r2   asi8r>   s    r9   rC   zDatetimeIndexOpsMixin.asi8       zzr:   c                    ddl m} | j                  j                  Gt	        | j                  t
        |f      r+t        | j                  j                        j                  }|S | j                  j                  S )a  
        Return the frequency object as a string if it's set, otherwise None.

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

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

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

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

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

        For PeriodIndex:

        >>> idx = pd.PeriodIndex(["2023-1", "2023-2", "2023-3"], freq="M")
        >>> idx.freqstr
        'M'
        r   )PeriodIndex)	pandasrF   r2   freqstr
isinstancer#   r    r=   _freqstr)r8   rF   r=   s      r9   rH   zDatetimeIndexOpsMixin.freqstr   s\    @ 	'::)jJJk2/
 tzz/88DK::%%%r:   c                     y r@    r>   s    r9   _resolution_objz%DatetimeIndexOpsMixin._resolution_obj   s    -0r:   c                .    | j                   j                  S )zO
        Returns day, hour, minute, second, millisecond or microsecond
        )r2   
resolutionr>   s    r9   rO   z DatetimeIndexOpsMixin.resolution   s    
 zz$$$r:   c                .    | j                   j                  S r@   )r2   _hasnar>   s    r9   hasnanszDatetimeIndexOpsMixin.hasnans   s    zz   r:   c                "   | j                  |      ryt        |t              sy|j                  j                  dv ryt        |t        |             sd}| j                  j                  }|j                  t        k(  r|j                  |v }n>t        |j                  t              r$t        d|      }|j                  j                  |v }|r	  t        |       |      }t        |       t        |      k7  ry| j                  |j                  k(  r*t!        j"                  | j$                  |j$                        S | j                  j                  dk(  r| j&                  |j&                  k(  s| j                  j                  dk(  r]	 | j                  j)                  |j                        \  }}t!        j"                  |j+                  d      |j+                  d            S y# t        t        t        f$ r Y yw xY w# t,        t.        f$ r Y yw xY w)zL
        Determines if two Index objects contain the same elements.
        TFiufcr/   Mmi8)is_rI   r%   dtypekindtyper2   _infer_matchesobjectinferred_typer   r
   
categories
ValueError	TypeErrorOverflowErrornparray_equalrC   tz_ensure_matching_resosviewr   r   )r8   other
should_try	inferableleftrights         r9   equalszDatetimeIndexOpsMixin.equals   s    88E?%'[['E4:.J

11I{{f$"00I=
EKK)9:/7"--;;yH
!&DJu-E :e$ZZ5;;&>>$))UZZ88jjoo$EHH)<TWAWI"jj??Le ~~diiouzz$7GHH) #I}= !
 !!  ()=> s$   G" (G< "G98G9<HHc                |    t        |       	 | j                  |       y# t        t        t        t
        f$ r Y yw xY w)a  
        Return a boolean indicating whether the provided key is in the index.

        Parameters
        ----------
        key : label
            The key to check if it is present in the index.

        Returns
        -------
        bool
            Whether the key search is in the index.

        Raises
        ------
        TypeError
            If the key is not hashable.

        See Also
        --------
        Index.isin : Returns an ndarray of boolean dtype indicating whether the
            list-like key is in the index.

        Examples
        --------
        >>> idx = pd.Index([1, 2, 3, 4])
        >>> idx
        Index([1, 2, 3, 4], dtype='int64')
        >>> 2 in idx
        True
        >>> 6 in idx
        False
        FT)hashget_locKeyErrorra   r`   r   )r8   keys     r9   __contains__z"DatetimeIndexOpsMixin.__contains__  s@    D 	S		LL  )Z1BC 		s    ;;c                |    t        j                  t        |      j                               }t        |   ||      S r@   )rc   asarrayr(   to_numpysuper_convert_tolerance)r8   	tolerancetarget	__class__s      r9   rx   z(DatetimeIndexOpsMixin._convert_toleranceG  s1    JJ|I6??AB	w))V<<r:   r   N)date_formatc               @    |t        | j                  ||            z   S )N)na_repr|   )list_get_values_for_csv)r8   headerr~   r|   s       r9   _format_with_headerz)DatetimeIndexOpsMixin._format_with_headerO  s+    
 $$F$L
 
 	
r:   c                6    | j                   j                         S r@   )r2   
_formatterr>   s    r9   _formatter_funcz%DatetimeIndexOpsMixin._formatter_funcX  s    zz$$&&r:   c                    t         |          }| j                  D ]4  }|dk(  s	| j                  }|t	        |      }|j                  d|f       6 |S )zH
        Return a list of tuples of the (attr,formatted_value).
        r=   )rw   _format_attrs_attributesrH   reprappend)r8   attrsattribr=   r{   s       r9   r   z#DatetimeIndexOpsMixin._format_attrs\  s^     %'&& 	-F||#:Dfd^,	- r:   c                d    t         |   |      }| j                  r|d| j                   z  }|S )a  
        Return a summarized representation.

        Parameters
        ----------
        name : str
            name to use in the summary representation

        Returns
        -------
        String with a summarized representation of the index
        namez
Freq: )rw   _summaryr=   rH   )r8   r   resultr{   s      r9   r   zDatetimeIndexOpsMixin._summaryj  s8     !t!,99//Fr:   c                     || j                   kD  S r@   )rM   )r8   resos     r9   _can_partial_date_slicez-DatetimeIndexOpsMixin._can_partial_date_slice  s     d****r:   c                    t         r@   NotImplementedError)r8   r   parseds      r9   _parsed_string_to_boundsz.DatetimeIndexOpsMixin._parsed_string_to_bounds  s    !!r:   c           
        	 | j                   t        | j                   d      r| j                   }t	        |t
              s|j                  }n|}t	        |t        j                        rt        |      }t        j                  ||      \  }}t        j                  |      }||fS # t        $ r t        | dt        | dd             }Y w xY w)N	rule_coderH   inferred_freq)r=   hasattrr   getattrrI   strr   rc   str_r   parse_datetime_string_with_resor   from_attrname)r8   labelr=   rH   r   reso_strr   s          r9   _parse_with_resoz&DatetimeIndexOpsMixin._parse_with_reso  s    	Ryy GDII{$Cyy
 JtS$9nnGGeRWW%JE"BB5'R''1t| # 	R4GD/4,PQD	Rs   .B( (!CCc                    | j                  |      \  }}	 | j                  ||      S # t        $ r}t        |      |d }~ww xY wr@   )r   _partial_date_slicerq   )r8   rr   r   r   errs        r9   _get_string_slicez'DatetimeIndexOpsMixin._get_string_slice  sJ    ,,S1	)++D&99 	)3-S(	)s   ( 	A=Ac                    | j                  |      st        | j                  ||      \  }}| j                  j                  }| j                  j
                  }| j                  rot        |       r&|| d   k  r|| d   k  s|| d   kD  r|| d   kD  rt        |j                   ||      d      }|j                   ||      d      }t        ||      S | ||      k\  }	| ||      k  }
|	|
z  j                         d   S )z
        Parameters
        ----------
        reso : Resolution
        parsed : datetime

        Returns
        -------
        slice or ndarray[intp]
        r   rk   siderl   )r   r`   r   r2   _ndarray_unboxis_monotonic_increasinglenrq   searchsortedslicenonzero)r8   r   r   t1t2valsunboxrk   rl   lhs_maskrhs_masks              r9   r   z)DatetimeIndexOpsMixin._partial_date_slice  s     ++D1..tV<Bzz""

!!''4yd1g"tAw,BbMb4PR8m 
 $$U2YV$<D%%eBig%>Eu%% uRy(HuRy(H x'002155r:   c                B   t        |t              r3	 | j                  |      \  }}| j                        \  }}|dk(  r|S |S t        || j                  j                        s| j	                  d|       |S # t        $ r}| j	                  d||       Y d}~sd}~ww xY w)aL  
        If label is a string, cast it to scalar type according to resolution.

        Parameters
        ----------
        label : object
        side : {'left', 'right'}

        Returns
        -------
        label : object

        Notes
        -----
        Value of `side` parameter should be validated in caller.
        r   Nrk   )rI   r   r   r`   _raise_invalid_indexerr   r2   _recognized_scalars)r8   r   r   r   r   r   loweruppers           r9   _maybe_cast_slice_boundz-DatetimeIndexOpsMixin._maybe_cast_slice_bound  s    " eS!A#44U;  88vFLE5 FN555E4::#A#AB''7  A ++GUC@@	As   A8 8	BBBc                    t         )ae  
        Shift index by desired number of time frequency increments.

        This method is for shifting the values of datetime-like indexes
        by a specified time increment a given number of times.

        Parameters
        ----------
        periods : int, default 1
            Number of periods (or increments) to shift by,
            can be positive or negative.
        freq : pandas.DateOffset, pandas.Timedelta or string, optional
            Frequency increment to shift by.
            If None, the index is shifted by its own `freq` attribute.
            Offset aliases are valid strings, e.g., 'D', 'W', 'M' etc.

        Returns
        -------
        pandas.DatetimeIndex
            Shifted index.

        See Also
        --------
        Index.shift : Shift values of Index.
        PeriodIndex.shift : Shift values of PeriodIndex.
        r   )r8   periodsr=   s      r9   shiftzDatetimeIndexOpsMixin.shift  s
    6 "!r:   c                    	 | j                   j                  |d      }t        ||j                        S # t        t        f$ r+ t	        |t
              st        j                  |      }n|}Y Pw xY w)zT
        Analogue to maybe_cast_indexer for get_indexer instead of get_loc.
        T)allow_objectrY   )
r2   _validate_listliker`   ra   rI   r"   comasarray_tuplesafer%   rY   )r8   keyarrress      r9   _maybe_cast_listlike_indexerz2DatetimeIndexOpsMixin._maybe_cast_listlike_indexer  sk    	**//T/JC S		** I& 	fn5++F3 	s   6 7A0/A0)r4   boolr5   z
int | None)returnzBaseOffset | None)r   None)r   znpt.NDArray[np.int64])r   r   )r   r   r   r   )rh   r   r   r   )rr   r   r   r   )r   	list[str]r~   r   r|   
str | Noner   r   r@   )r   r   r   r   )r   r   )r   r   r   ztuple[datetime, Resolution])rr   r   r   slice | npt.NDArray[np.intp])r   r   r   r*   r   r   )r   r      Nr   intr   r	   )#__name__
__module____qualname____doc___can_hold_strings__annotations__r7   propertyr=   setterrC   rH   r   r   rM   rO   rR   rm   rs   rx   _default_na_repr   r   r   r   r   r   r   r   r   r   r   r   r   __classcell__r{   s   @r9   r1   r1   X   sz    77%)a -9^  : 
[[      '& '&R 0  0% % ! !+Z'R= O LP
"
,/
>H
	
 ' ', + +",) )6)6 )6 
&	)6 )6VH">+r:   r1   c                      e Zd ZU dZded<   ddgZddgZej                  Z	ej                  Zej                  Zed!d       Zd"dZd Zed#d	       Zd$d%d
Zed&d       Zed'd       Zd(dZd)dZd)dZd)dZd*d+dZd Zd,dZd,dZd-d.dZ fdZ d Z!	 	 	 	 	 	 	 	 d/ fdZ"d#dZ#d0dZ$d1d2 fdZ%d3dZ&d4dZ'd) fdZ(d4 fdZ)	 	 	 d5	 	 	 	 	 d6d Z* xZ+S )7DatetimeTimedeltaMixinze
    Mixin class for methods shared by DatetimeIndex and TimedeltaIndex,
    but not PeriodIndex
    zDatetimeArray | TimedeltaArrayr2   r   r=   c                .    | j                   j                  S r@   )r2   unitr>   s    r9   r   zDatetimeTimedeltaMixin.unit6  rD   r:   c                    | j                   j                  |      }t        |       j                  || j                        S )a  
        Convert to a dtype with the given unit resolution.

        This method is for converting the dtype of a ``DatetimeIndex`` or
        ``TimedeltaIndex`` to a new dtype with the given unit
        resolution/precision.

        Parameters
        ----------
        unit : {'s', 'ms', 'us', 'ns'}

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

        See Also
        --------
        Timestamp.as_unit : Convert to the given unit.
        Timedelta.as_unit : Convert to the given unit.
        DatetimeIndex.as_unit : Convert to the given unit.
        TimedeltaIndex.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   )r2   as_unitr[   _simple_newr   )r8   r   arrs      r9   r   zDatetimeTimedeltaMixin.as_unit:  s7    X jj  &Dz%%c		%::r:   c                    | j                   j                  |      }t        |       j                  || j                        S )Nr   )r2   
_with_freqr[   r   _name)r8   r=   r   s      r9   r   z!DatetimeTimedeltaMixin._with_freqi  s4    jj##D)Dz%%c

%;;r:   c                t    | j                   j                  }|j                         }d|j                  _        |S )NF)r2   r   rg   flags	writeable)r8   datas     r9   valueszDatetimeTimedeltaMixin.valuesm  s/     zz""yy{$

r:   c                   |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                  j                  ||d| j                   | j                        }t        |       j                  || j                        S )ad  
        Shift index by desired number of time frequency increments.
        This method is for shifting the values of datetime-like indexes
        by a specified time increment a given number of times.

        Parameters
        ----------
        periods : int, default 1
            Number of periods (or increments) to shift by,
            can be positive or negative.
        freq : pandas.DateOffset, pandas.Timedelta or string, optional
            Frequency increment to shift by.
            If None, the index is shifted by its own `freq` attribute.
            Offset aliases are valid strings, e.g., 'D', 'W', 'M' etc.

        Returns
        -------
        pandas.DatetimeIndex
            Shifted index.

        See Also
        --------
        Index.shift : Shift values of Index.
        PeriodIndex.shift : Shift values of PeriodIndex.
        Nr   zCannot shift with no freqr   )startendr   r=   r   r   )r=   rI   r   r   r   copyr   r2   _generate_ranger   r[   r   r   )r8   r   r=   offsetr   r   r   s          r9   r   zDatetimeTimedeltaMixin.shiftu  s    4 		 1$$ t^F&= a<3t9>99;99$%@AAQ'DII--2h499,,
 ++S$TYYTYY , 
 Dz%%f499%==r:   c                .    | j                   j                  S )a  
        Return the inferred frequency of the index.

        Returns
        -------
        str or None
            A string representing a frequency generated by ``infer_freq``.
            Returns ``None`` if the frequency cannot be inferred.

        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'
        )r2   r   r>   s    r9   r   z$DatetimeTimedeltaMixin.inferred_freq  s    B zz'''r:   c                    t        t        | j                        }t        |      j	                  | j
                        j                  }t        | d   j                  | d   j                  |z   |      }t        |      S Nr   r   )	r
   r   r=   r   r   r   _valueranger'   )r8   r=   tickrngs       r9   _as_range_indexz&DatetimeTimedeltaMixin._as_range_index  s_     D$))$&&tyy188DGNNDHOOd$:DA#r:   c                n    t        | j                  t              xr t        |j                  t              S r@   )rI   r=   r   r8   rh   s     r9   _can_range_setopz'DatetimeTimedeltaMixin._can_range_setop  s#    $))T*Kz%**d/KKr:   c                   d }t        |      s| j                  }nSt        |t              rCt	        t        |j                  | j                        j                  | j                              }|j                  j                  | j                  j                  j                        }t        | j                        j                  || j                  |      }t!        d| j#                  ||            S )N)r   )rY   r=   r	   )r   r=   rI   r'   r   r   stepr   r   r   rg   r2   r   rY   r[   r   r
   _wrap_setop_result)r8   rh   res_i8new_freq
res_valuesr   s         r9   _wrap_range_setopz(DatetimeTimedeltaMixin._wrap_range_setop  s    6{yyH
+ &++DII6>>tyyIH ]]''

(;(;(A(AB
djj!-- ** . 
 FD33E6BCCr:   c                |    | j                   }|j                   }|j                  ||      }| j                  ||      S Nsort)r   intersectionr
  r8   rh   r  rk   rl   r  s         r9   _range_intersectz'DatetimeTimedeltaMixin._range_intersect  s@    ##%%""5t"4%%eV44r:   c                |    | j                   }|j                   }|j                  ||      }| j                  ||      S r  )r   unionr
  r  s         r9   _range_unionz#DatetimeTimedeltaMixin._range_union  s=    ##%%E-%%eV44r:   c                <   t        d|      }| j                  |      r| j                  ||      S | j                  |      sJt	        j
                  | ||      }| j                  ||      }|j                  d      j                  d      S | j                  ||      S )z_
        intersection specialized to the case with matching dtypes and both non-empty.
        r   r  Ninfer)	r
   r  r  _can_fast_intersectr%   _intersectionr  r   _fast_intersect)r8   rh   r  r   s       r9   r  z$DatetimeTimedeltaMixin._intersection  s     -u5  '((T(::''.((u4@F ,,UF;F$$T*55g>> ''t44r:   c                    | d   |d   k  r| |}}n|| }}t        |d   |d         }|d   }||k  r| d d }|S t        |j                  ||       }|j                  |   }|S r   )minr   
slice_locs_values)	r8   rh   r  rk   rl   r   r   r   lslices	            r9   r  z&DatetimeTimedeltaMixin._fast_intersect  s    7eAh%D%D $r(E"I&a;"1XF
  DOOE378F\\&)Fr:   c                    | j                   y|j                   | j                   k7  ry| j                  sy| j                   j                  dk(  S )NFr   )r=   r   nr  s     r9   r  z*DatetimeTimedeltaMixin._can_fast_intersect,  sC    99ZZ499$-- yy{{ar:   c                    | j                   }|||j                   k7  ry| j                  syt        |       dk(  st        |      dk(  ry| d   |d   k  r| |}}n|| }}|d   }|d   }|||z   k(  xs ||v S )NFr   Tr   )r=   r   r   )r8   rh   r=   rk   rl   right_startleft_ends          r9   _can_fast_unionz&DatetimeTimedeltaMixin._can_fast_union>  s     yy<45::-++ t9>SZ1_ 7eAh%D%DAh8 x$.F;$3FFr:   c                J   | d   |d   k  r| |}}nr|du rj| |}}|d   }|j                  |d      }|j                  d | }t        |j                  |f      }t        |       j	                  || j
                        }	|	S || }}|d   }
|d   }|
|k  r|j                  |
d      }|j                  |d  }t        |j                  |g      }t        |t        | j                              sJ |j                  | j                  k(  sJ t        |       j	                  |      }	|	S |S )Nr   Frk   r   r   r   rl   )
r   r  r   r[   r   r   rI   r2   _freqr=   )r8   rh   r  rk   rl   
left_startlocright_chunkdatesr   r#  	right_ends               r9   _fast_unionz"DatetimeTimedeltaMixin._fast_union\  s@    7eAh%DU] %DaJ$$Zf$=C---K!4<<"=>E$Z++E		+BFM%D8"I	 i$$XG$<C---K!4<<"=>E eT$**%5666 ;;$))+++$Z++E2FMKr:   c                :   t        |t        |             sJ | j                  |j                  k(  sJ | j                  |      r| j	                  ||      S | j                  |      r| j                  ||      }|S t        | !  ||      j                  d      S )Nr  r  )
rI   r[   rY   r  r  r$  r,  rw   _unionr   )r8   rh   r  r   r{   s       r9   r.  zDatetimeTimedeltaMixin._union  s    %d,,,zzU[[(((  '$$U$66&%%e$%7F M7>%.99'BBr:   c                D    d}| j                  |      r| j                  }|S )zK
        Get the freq to attach to the result of a join operation.
        N)r$  r=   )r8   rh   r=   s      r9   _get_join_freqz%DatetimeTimedeltaMixin._get_join_freq  s%     &99Dr:   c                    |j                   | j                   k(  sJ |j                   | j                   f       t        | 	  |||||      \  }}}| j                  |      |j                  _        |||fS r@   )rY   rw   _wrap_join_resultr0  r2   r&  )r8   joinedrh   lidxridxhow
join_indexr{   s          r9   r2  z(DatetimeTimedeltaMixin._wrap_join_result  sv     {{djj(C5;;

*CC(!&!:E4s"

D$ "&!4!4U!;
4%%r:   c                L    | j                   j                  j                  d      S )NrW   )r2   r   rg   r>   s    r9   _get_engine_targetz)DatetimeTimedeltaMixin._get_engine_target  s    zz""''--r:   c                    |j                  | j                  j                  j                        }| j                  j	                  |      S r@   )rg   r2   r   rY   _from_backing_data)r8   r   s     r9   _from_join_targetz(DatetimeTimedeltaMixin._from_join_target  s5    TZZ00667zz,,V44r:   c                h   | j                   rt        |t        t        f      rt	        |j
                        t	        | j
                        kD  rU|dk(  r|j                  | j
                        }n4|j                  | j
                        j                  | j
                        }t        | %  ||      S )Nrl   )
r   rI   r   r   r   r   r   ceilrw   _searchsorted_monotonic)r8   r   r   r{   s      r9   r?  z.DatetimeTimedeltaMixin._searchsorted_monotonic  s    ((59i"89"5::.1CDII1NN wdii0 

499-55dii@w.ud;;r:   c                   d}| j                   t        |      r,|dt        |        dt        |       dz
  fv r| j                   }|S t        |      rBt	        j
                  t        j                  |t        j                        t        |             }t        |t              rA|j                  dv r3|j                  dv s|j                  t        |       dfv r| j                   }|S )z7
        Find the `freq` for self.delete(loc).
        Nr   r   r   r   r   )r   N)r=   r   r   r   r   maybe_indices_to_slicerc   ru   intprI   r   r  r   stop)r8   r(  r=   s      r9   _get_delete_freqz'DatetimeTimedeltaMixin._get_delete_freq  s     99 #1s4yj"c$i!m<<99D   $ 44

3bgg6D	C c5)chh).CyyI-c$i=N1N#yyr:   c                "   | j                   j                  |      }| j                   j                  |      }d}| j                  | j                  ro|t
        u r	 |S |dt        |        fv r#|| j                  z   | d   k(  r| j                  }|S |t        |       k(  r!|| j                  z
  | d   k(  r| j                  }|S t        | j                  t              r| j                  }|S | j                  j                  |      r| j                  }|S )z=
        Find the `freq` for self.insert(loc, item).
        Nr   r   )
r2   _validate_scalar	_box_funcr=   sizer   r   rI   r   is_on_offset)r8   r(  itemrA   r=   s        r9   _get_insert_freqz'DatetimeTimedeltaMixin._get_insert_freq  s    

++D1zz##E*99 yy3;  QT
O+tyy0@DG0K99D  SY&D499,<R,H99D  DIIt, yy  ''-yyr:   c                f    t         |   |      }| j                  |      |j                  _        |S )a  
        Make new Index with passed location(-s) deleted.

        Parameters
        ----------
        loc : int or list of int
            Location of item(-s) which will be deleted.
            Use a list of locations to delete more than one value at the same time.

        Returns
        -------
        Index
            Will be same type as self, except for RangeIndex.

        See Also
        --------
        numpy.delete : Delete any rows and column from NumPy array (ndarray).

        Examples
        --------
        >>> idx = pd.Index(["a", "b", "c"])
        >>> idx.delete(1)
        Index(['a', 'c'], dtype='str')
        >>> idx = pd.Index(["a", "b", "c"])
        >>> idx.delete([0, 2])
        Index(['b'], dtype='str')
        )rw   deleterD  r2   r&  )r8   r(  r   r{   s      r9   rM  zDatetimeTimedeltaMixin.delete  s/    8 $!2237r:   c                    t         |   ||      }t        |t        |             r!| j	                  ||      |j
                  _        |S )a  
        Make new Index inserting new item at location.
        Follows Python numpy.insert semantics for negative values.

        Parameters
        ----------
        loc : int
            The integer location where the new item will be inserted.
        item : object
            The new item to be inserted into the Index.

        Returns
        -------
        Index
            Returns a new Index object resulting from inserting the specified item at
            the specified location within the original Index.

        See Also
        --------
        Index.append : Append a collection of Indexes together.

        Examples
        --------
        >>> idx = pd.Index(["a", "b", "c"])
        >>> idx.insert(1, "x")
        Index(['a', 'x', 'b', 'c'], dtype='str')
        )rw   insertrI   r[   rK  r2   r&  )r8   r(  rJ  r   r{   s       r9   rO  zDatetimeTimedeltaMixin.insert  sA    8 T*fd4j)!%!6!6sD!AFLLr:   c                f   t        j                  d|       t        j                  |t        j                        }t        j                  | ||||fi |}t        j                  |t        |             }t        |t              r,| j                  j                  |      }||j                  _        |S )a  
        Return a new Index of the values selected by the indices.
        For internal compatibility with numpy arrays.

        Parameters
        ----------
        indices : array-like
            Indices to be taken.
        axis : {0 or 'index'}, optional
            The axis over which to select values, always 0 or 'index'.
        allow_fill : bool, default True
            How to handle negative values in `indices`.
            * False: negative values in `indices` indicate positional indices
                from the right (the default). This is similar to
                :func:`numpy.take`.
            * True: negative values in `indices` indicate
                missing values. These values are set to `fill_value`. Any other
                other negative values raise a ``ValueError``.
        fill_value : scalar, default None
            If allow_fill=True and fill_value is not None, indices specified by
            -1 are regarded as NA. If Index doesn't hold NA, raise ValueError.
        **kwargs
            Required for compatibility with numpy.

        Returns
        -------
        Index
            An index formed of elements at the given indices. Will be the same
            type as self, except for RangeIndex.

        See Also
        --------
        numpy.ndarray.take: Return an array formed from the
            elements of a at the given indices.

        Examples
        --------
        >>> idx = pd.Index(["a", "b", "c"])
        >>> idx.take([2, 2, 1, 2])
        Index(['c', 'c', 'b', 'c'], dtype='str')
        rL   r   )nvvalidate_takerc   ru   rB  r&   taker   rA  r   rI   r   r2   _get_getitem_freqr&  )	r8   indicesr5   
allow_fill
fill_valuekwargsr   maybe_slicer=   s	            r9   rS  zDatetimeTimedeltaMixin.take>  s    b 	V$**WBGG4,11'4Z
;A
 00#d)Dk5):://<D!%FLLr:   )r   r-   )r   r-   r   r	   )r   
np.ndarrayr   r   )r   r   )r   r'   r   )r   r	   )F)rh   r%   r  r   r   r%   )rh   r	   r   r   r@   )rh   r	   r   r	   )r4  npt.NDArray[np.intp] | Noner5  r[  r6  r,   r   zEtuple[Self, npt.NDArray[np.intp] | None, npt.NDArray[np.intp] | None])r   rZ  )rk   )r   zLiteral['left', 'right'])r(  zint | slice | Sequence[int])r(  r   )r   TN)r5   r+   rV  r   r   r	   ),r   r   r   r   r   _comparablesr   r%   r   _is_monotonic_increasingis_monotonic_decreasing_is_monotonic_decreasing	is_unique
_is_uniquer   r   r   r   r   r   r   r   r   r  r
  r  r  r  r  r  r$  r,  r.  r0  r2  r9  r<  r?  rD  rK  rM  rO  rS  r   r   s   @r9   r   r   '  sd   
 *)F#L6"K  %<<$<<J -;^<  0>d  (  (J  LD4555.( $G<$LC&& *	&
 *& & 
O&.5
<&,4@ P < < 	< 
<r:   r   )Pr   
__future__r   abcr   r   typingr   r   r   r	   r
   r   numpyrc   pandas._libsr   r   pandas._libs.tslibsr   r   r   r   r   r   r   pandas._libs.tslibs.dtypesr   pandas.compat.numpyr   rQ  pandas.errorsr   r   r   r   pandas.util._decoratorsr   pandas.core.dtypes.commonr   r   pandas.core.dtypes.concatr   pandas.core.dtypes.dtypesr   r    pandas.core.arraysr!   r"   r#   r$   pandas.core.commoncorecommonr   pandas.core.indexes.baseindexesbaseibaser%   pandas.core.indexes.extensionr&   pandas.core.indexes.ranger'   pandas.core.tools.timedeltasr(   collections.abcr)   r*   pandas._typingr+   r,   r-   r.   rG   r/   dict_index_doc_kwargsr1   r   rL   r:   r9   <module>r~     s    #     : .  4
  !   ( ( F 0 5(!  (001 L+7 L+^S	2C S	r:   