
    Pip                       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:jM                  ZM G d de=e          ZN G d deNe          ZOdS )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	        dAd            ZedBd            Z
edCd            ZeedDd                        ZedCd            ZedEd            ZdFdZdGdZ fdZd Zd!d"dHd(Zed)             Z fd*ZdIdC fd+ZedJd-            ZdKd.ZdLd1ZdMd3ZedNd6            ZdOd8ZdPdQd=Z d> Z! xZ"S )RDatetimeIndexOpsMixinzM
    Common ops mixin to support a unified interface datetimelike Index.
    Fz,DatetimeArray | TimedeltaArray | PeriodArray_dataTr   skipnaaxisr4   boolr5   
int | Nonec               :    | 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      t/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/pandas/core/indexes/datetimelike.pyr9   zDatetimeIndexOpsMixin.mean`   s    Z zf4888    returnBaseOffset | Nonec                    | 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r:   s    r;   rA   zDatetimeIndexOpsMixin.freq   s    8 zr<   Nonec                    || j         _        d S Nr@   )r:   values     r;   rA   zDatetimeIndexOpsMixin.freq   s      
r<   npt.NDArray[np.int64]c                    | j         j        S rE   )r2   asi8rB   s    r;   rI   zDatetimeIndexOpsMixin.asi8       zr<   strc                    ddl m} | j        j        <t	          | 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)	pandasrM   r2   freqstr
isinstancer#   r    rA   _freqstr)r:   rM   rA   s      r;   rO   zDatetimeIndexOpsMixin.freqstr   sc    @ 	'&&&&&:)jJk2/
 /
) tz//8DK:%%r<   r   c                    d S rE    rB   s    r;   _resolution_objz%DatetimeIndexOpsMixin._resolution_obj   s    -0Sr<   c                    | j         j        S )zO
        Returns day, hour, minute, second, millisecond or microsecond
        )r2   
resolutionrB   s    r;   rV   z DatetimeIndexOpsMixin.resolution   s    
 z$$r<   c                    | j         j        S rE   )r2   _hasnarB   s    r;   hasnanszDatetimeIndexOpsMixin.hasnans   s    z  r<   otherr   c                   |                      |          rdS t          |t                    sdS |j        j        dv rdS t          |t          |                     sd}| j        j        }|j        t          k    r
|j	        |v }n8t          |j        t                    rt          d|          }|j        j	        |v }|r8	  t          |           |          }n# t          t          t          f$ r Y dS w xY wt          |           t          |          k    rdS | j        |j        k    rt!          j        | j        |j                  S | j        j        dk    r| j        |j        k    s| j        j        dk    rv	 | j                            |j                  \  }}t!          j        |                    d          |                    d                    S # t,          t.          f$ r Y dS w xY wdS )zL
        Determines if two Index objects contain the same elements.
        TFiufcr/   Mmi8)is_rP   r%   dtypekindtyper2   _infer_matchesobjectinferred_typer   r
   
categories
ValueError	TypeErrorOverflowErrornparray_equalrI   tz_ensure_matching_resosviewr   r   )r:   rZ   
should_try	inferableleftrights         r;   equalszDatetimeIndexOpsMixin.equals   s    88E?? 	4%'' 	!5[''5E4::.. 	!J
1I{f$$"0I=

EK)9:: I/77"-;yH
 !!&DJJu--EE"I}= ! ! !
 !55! ::e$$5Z5;&&>$)UZ888jo$$EH)<)<TWAWAWI"j??LLe ~diioouzz$7G7GHHH ()=>   uu us$   ?C C32C38"G G*)G*keyc                    t          |           	 |                     |           n$# t          t          t          t
          f$ r Y dS w xY wdS )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KeyErrorri   rh   r   )r:   ru   s     r;   __contains__z"DatetimeIndexOpsMixin.__contains__  s[    D 	S				LL)Z1BC 	 	 	55	ts   ' AAc                    t          j        t          |                                                    }t	                                          ||          S rE   )rk   asarrayr(   to_numpysuper_convert_tolerance)r:   	tolerancetarget	__class__s      r;   r   z(DatetimeIndexOpsMixin._convert_toleranceG  s@    J|I66??AABB	ww)))V<<<r<   r   N)date_formatheader	list[str]na_repr   
str | Nonec               P    |t          |                     ||                    z   S )N)r   r   )list_get_values_for_csv)r:   r   r   r   s       r;   _format_with_headerz)DatetimeIndexOpsMixin._format_with_headerO  s3    
 $$F$LL
 
 
 	
r<   c                4    | j                                         S rE   )r2   
_formatterrB   s    r;   _formatter_funcz%DatetimeIndexOpsMixin._formatter_funcX  s    z$$&&&r<   c                    t                                                      }| j        D ]7}|dk    r/| j        }|t	          |          }|                    d|f           8|S )zH
        Return a list of tuples of the (attr,formatted_value).
        rA   )r~   _format_attrs_attributesrO   reprappend)r:   attrsattribrA   r   s       r;   r   z#DatetimeIndexOpsMixin._format_attrs\  sk     %%''& 	- 	-F|#::Dfd^,,,r<   c                t    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: )r~   _summaryrA   rO   )r:   r   resultr   s      r;   r   zDatetimeIndexOpsMixin._summaryj  sC     !!t!,,9 	0////Fr<   resoc                    || j         k    S rE   )rT   )r:   r   s     r;   _can_partial_date_slicez-DatetimeIndexOpsMixin._can_partial_date_slice  s     d***r<   c                    t           rE   NotImplementedError)r:   r   parseds      r;   _parsed_string_to_boundsz.DatetimeIndexOpsMixin._parsed_string_to_bounds  s    !!r<   labeltuple[datetime, Resolution]c           
        	 | j         t          | j         d          r| j         }n0# t          $ r# t          | dt          | dd                     }Y nw xY w|t	          |t
                    s|j        }n|}t	          |t          j                  rt          |          }t          j
        ||          \  }}t          j        |          }||fS )N	rule_coderO   inferred_freq)rA   hasattrr   getattrrP   rK   r   rk   str_r   parse_datetime_string_with_resor   from_attrname)r:   r   rA   rO   r   reso_strr   s          r;   _parse_with_resoz&DatetimeIndexOpsMixin._parse_with_reso  s    	Ry GDI{$C$C y" 	R 	R 	R4GD/4,P,PQQDDD	R JtS$9$9nGGGeRW%% 	JJE"B5'RR'11t|s   #& *AAslice | npt.NDArray[np.intp]c                    |                      |          \  }}	 |                     ||          S # t          $ r}t          |          |d }~ww xY wrE   )r   _partial_date_slicery   )r:   ru   r   r   errs        r;   _get_string_slicez'DatetimeIndexOpsMixin._get_string_slice  sa    ,,S11	)++D&999 	) 	) 	)3--S(	)s   0 
AA

Ar   r*   c                L   |                      |          st          |                     ||          \  }}| j        j        }| j        j        }| j        rt          |           r7|| d         k     r|| d         k     s|| d         k    r|| d         k    rt          |	                     ||          d          }|	                     ||          d          }t          ||          S | ||          k    }	| ||          k    }
|	|
z                                  d         S )z
        Parameters
        ----------
        reso : Resolution
        parsed : datetime

        Returns
        -------
        slice or ndarray[intp]
        r   rr   siders   )r   rh   r   r2   _ndarray_unboxis_monotonic_increasinglenry   searchsortedslicenonzero)r:   r   r   t1t2valsunboxrr   rs   lhs_maskrhs_masks              r;   r   z)DatetimeIndexOpsMixin._partial_date_slice  s5     ++D11 	..tV<<Bz"
!' 	64yy d1g"tAw,,BbMMb4PR8mm 
 $$UU2YYV$<<D%%eeBiig%>>Eu%%% uuRyy(HuuRyy(H x'0022155r<   r   c                f   t          |t                    rk	 |                     |          \  }}n.# t          $ r!}|                     d||           Y d}~nd}~ww xY w|                     ||          \  }}|dk    r|n|S t          || j        j                  s|                     d|           |S )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   Nrr   )rP   rK   r   rh   _raise_invalid_indexerr   r2   _recognized_scalars)r:   r   r   r   r   r   loweruppers           r;   _maybe_cast_slice_boundz-DatetimeIndexOpsMixin._maybe_cast_slice_bound  s    " eS!! 	8A#44U;; A A A ++GUC@@@@@@@@	A  88vFFLE5 FNN555E4:#ABB 	8''777s   0 
AAA   periodsintr	   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   )r:   r   rA   s      r;   shiftzDatetimeIndexOpsMixin.shift  s
    6 "!r<   c                    	 | j                             |d          }nC# t          t          f$ r/ t	          |t
                    st          j        |          }n|}Y nw xY wt          ||j	                  S )zT
        Analogue to maybe_cast_indexer for get_indexer instead of get_loc.
        T)allow_objectra   )
r2   _validate_listlikerh   ri   rP   r"   comasarray_tuplesafer%   ra   )r:   keyarrress      r;   _maybe_cast_listlike_indexerz2DatetimeIndexOpsMixin._maybe_cast_listlike_indexer  s    	*//T/JJCCI& 	 	 	fn55 +F33 	 S	****s    =AA)r4   r6   r5   r7   )r=   r>   )r=   rC   )r=   rG   )r=   rK   )r=   r   r=   r6   )rZ   r   r=   r6   )ru   r   r=   r6   )r   r   r   rK   r   r   r=   r   rE   )r   r   r=   r6   )r   r   )r   rK   r=   r   )ru   rK   r=   r   )r   r   r   r*   r=   r   )r   rK   r   Nr   r   r=   r	   )#__name__
__module____qualname____doc___can_hold_strings__annotations__r9   propertyrA   setterrI   rO   r   r   rT   rV   rY   rt   rz   r   _default_na_repr   r   r   r   r   r   r   r   r   r   r   r   r   __classcell__r   s   @r;   r1   r1   X   s          7777%)a -9 -9 -9 -9 -9 -9^    X: 
[      [     X '& '& '& X'&R 000 ^ ^0% % % ^% ! ! ! ^!+ + + +Z' ' ' 'R= = = = = O LP
 
 
 
 
 
 ' ' X'          , + + + U+" " " "   ,) ) ) ) )6 )6 )6 U)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dBd            ZdCdZd ZedDd            ZdEdFdZedGd            ZedHd            ZdIdZdJdZdJdZdJdZdKdLd!Zd" ZdMd#ZdMd$ZdNdOd%Z fd&Z d' Z!dP fd.Z"dDd/Z#dQd1Z$dRdS fd5Z%dTd8Z&dUd9Z'dJ fd:Z(dU fd;Z)	 	 	 dVdWdAZ* xZ+S )XDatetimeTimedeltaMixinze
    Mixin class for methods shared by DatetimeIndex and TimedeltaIndex,
    but not PeriodIndex
    zDatetimeArray | TimedeltaArrayr2   r   rA   r=   r-   c                    | j         j        S rE   )r2   unitrB   s    r;   r   zDatetimeTimedeltaMixin.unit6  rJ   r<   r   r	   c                    | j                             |          }t          |                               || 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_unitrc   _simple_newr   )r:   r   arrs      r;   r   zDatetimeTimedeltaMixin.as_unit:  s;    X j  &&Dzz%%c	%:::r<   c                    | j                             |          }t          |                               || j                  S )Nr   )r2   
_with_freqrc   r   _name)r:   rA   r   s      r;   r   z!DatetimeTimedeltaMixin._with_freqi  s8    j##D))Dzz%%c
%;;;r<   
np.ndarrayc                ^    | j         j        }|                                }d|j        _        |S )NF)r2   r   ro   flags	writeable)r:   datas     r;   valueszDatetimeTimedeltaMixin.valuesm  s*     z"yy{{$
r<   r   Nr   r   c                   |9|| j         k    r.t          |t                    rt          |          }||z  }| |z   S |dk    st	          |           dk    r|                                 S | j         t          d          | d         || j         z  z   }| d         || j         z  z   }| j                            ||d| j         | j	                  }t          |                               || 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   rA   r   r   )rA   rP   rK   r   r   copyr   r2   _generate_ranger   rc   r   r   )r:   r   rA   offsetr   r   r   s          r;   r   zDatetimeTimedeltaMixin.shiftu  s    4 	 1 1$$$ ' t^F&= a<<3t99>>99;;9$%@AAAQ'DI--2h49,,
 ++S$TYTY , 
 
 Dzz%%f49%===r<   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   rB   s    r;   r   z$DatetimeTimedeltaMixin.inferred_freq  s    B z''r<   r'   c                    t          t          | j                  }t          |                              | j                  j        }t          | d         j        | d         j        |z   |          }t          |          S Nr   r   )	r
   r   rA   r   r   r   _valueranger'   )r:   rA   tickrngs       r;   _as_range_indexz&DatetimeTimedeltaMixin._as_range_index  sa     D$)$$&&ty118DGNDHOd$:DAA#r<   r6   c                j    t          | j        t                    ot          |j        t                    S rE   )rP   rA   r   r:   rZ   s     r;   _can_range_setopz'DatetimeTimedeltaMixin._can_range_setop  s%    $)T**Kz%*d/K/KKr<   c                   d }t          |          s| j        }nUt          |t                    r@t	          t          |j        | j                                      | j                            }|j	        
                    | j        j        j                  }t          | j                                      || j        |          }t!          d|                     ||                    S )N)r   )ra   rA   r	   )r   rA   rP   r'   r   r   stepr   r   r   ro   r2   r   ra   rc   r   r
   _wrap_setop_result)r:   rZ   res_i8new_freq
res_valuesr   s         r;   _wrap_range_setopz(DatetimeTimedeltaMixin._wrap_range_setop  s    6{{ 	yHH
++ 	 &+DI666>>tyII H ]''
(;(ABB
dj!!-- * . 
 
 FD33E6BBCCCr<   c                x    | j         }|j         }|                    ||          }|                     ||          S Nsort)r  intersectionr  r:   rZ   r  rr   rs   r  s         r;   _range_intersectz'DatetimeTimedeltaMixin._range_intersect  s@    #%""5t"44%%eV444r<   c                x    | j         }|j         }|                    ||          }|                     ||          S r  )r  unionr  r  s         r;   _range_unionz#DatetimeTimedeltaMixin._range_union  s=    #%E--%%eV444r<   FrZ   r%   r  c                z   t          d|          }|                     |          r|                     ||          S |                     |          sUt	          j        | ||          }|                     ||          }|                    d                              d          S |                     ||          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)r:   rZ   r  r   s       r;   r  z$DatetimeTimedeltaMixin._intersection  s     -u55  '' 	;((T(:::''.. 	5(u4@@@F ,,UF;;F$$T**55g>>> ''t444r<   c                    | d         |d         k    r| |}}n|| }}t          |d         |d                   }|d         }||k     r| d d         }n*t          |                    ||           }|j        |         }|S r   )minr   
slice_locs_values)	r:   rZ   r  rr   rs   r   r   r   lslices	            r;   r  z&DatetimeTimedeltaMixin._fast_intersect  s    7eAh%DD%D $r(E"I&&a;;"1"XFFDOOE3778F\&)Fr<   c                j    | j         dS |j         | j         k    rdS | j        sdS | j         j        dk    S )NFr   )rA   r   nr  s     r;   r  z*DatetimeTimedeltaMixin._can_fast_intersect,  sD    95Z49$$5- 	5 y{ar<   c                    | j         }|||j         k    rdS | j        sdS t          |           dk    st          |          dk    rdS | d         |d         k    r| |}}n|| }}|d         }|d         }|||z   k    p||v S )NFr   Tr   )rA   r   r   )r:   rZ   rA   rr   rs   right_startleft_ends          r;   _can_fast_unionz&DatetimeTimedeltaMixin._can_fast_union>  s     y<45:--5+ 	 5t99>>SZZ1__4 7eAh%DD%DAh8 x$.F;$3FFr<   c                   | d         |d         k    r| |}}n{|du rs| |}}|d         }|                     |d          }|j        d |         }t          |j        |f          }t          |                               || j                  }	|	S || }}|d         }
|d         }|
|k     r|                     |
d          }|j        |d          }t          |j        |g          }t          |t          | j                            sJ |j        | j	        k    sJ t          |                               |          }	|	S |S )Nr   Frr   r   r   r   rs   )
r   r"  r   rc   r   r   rP   r2   _freqrA   )r:   rZ   r  rr   rs   
left_startlocright_chunkdatesr   r(  	right_ends               r;   _fast_unionz"DatetimeTimedeltaMixin._fast_union\  s`    7eAh%DDU]] %DaJ$$Zf$==C--K!4<"=>>E$ZZ++E	+BBFM%D8"I	 i$$XG$<<C--K!4<"=>>E eT$*%5%566666 ;$)++++$ZZ++E22FMKr<   c                   t          |t          |                     sJ | j        |j        k    sJ |                     |          r|                     ||          S |                     |          r|                     ||          }|S t                                          ||          	                    d          S )Nr  r  )
rP   rc   ra   r  r  r)  r1  r~   _unionr   )r:   rZ   r  r   r   s       r;   r3  zDatetimeTimedeltaMixin._union  s    %d,,,,,zU[((((  '' 	7$$U$666&& 	C%%e$%77F M77>>%..99'BBBr<   c                B    d}|                      |          r| j        }|S )zK
        Get the freq to attach to the result of a join operation.
        N)r)  rA   )r:   rZ   rA   s      r;   _get_join_freqz%DatetimeTimedeltaMixin._get_join_freq  s+     && 	9Dr<   lidxnpt.NDArray[np.intp] | Noneridxhowr,   Etuple[Self, npt.NDArray[np.intp] | None, npt.NDArray[np.intp] | None]c                    |j         | j         k    sJ |j         | j         f            t                                          |||||          \  }}}|                     |          |j        _        |||fS rE   )ra   r~   _wrap_join_resultr5  r2   r+  )r:   joinedrZ   r6  r8  r9  
join_indexr   s          r;   r<  z(DatetimeTimedeltaMixin._wrap_join_result  s~     {dj(((5;
*C(((!&!:!:E4s"
 "

D$ "&!4!4U!;!;
4%%r<   c                @    | j         j                            d          S )Nr_   )r2   r   ro   rB   s    r;   _get_engine_targetz)DatetimeTimedeltaMixin._get_engine_target  s    z"''---r<   r   c                ~    |                     | j        j        j                  }| j                            |          S rE   )ro   r2   r   ra   _from_backing_data)r:   r   s     r;   _from_join_targetz(DatetimeTimedeltaMixin._from_join_target  s1    TZ0677z,,V444r<   rr   r   Literal['left', 'right']c                   | j         rt          |t          t          f          r}t	          |j                  t	          | j                  k    rS|dk    r|                    | j                  }n2|                    | j                                      | j                  }t                      	                    ||          S )Nrs   )
r   rP   r   r   r   r   r   ceilr~   _searchsorted_monotonic)r:   r   r   r   s      r;   rG  z.DatetimeTimedeltaMixin._searchsorted_monotonic  s    (	A59i"899	A #5:..1CDI1N1NNN wdi00 

49--55di@@ww..ud;;;r<   r-  int | slice | Sequence[int]c                   d}| j         t          |          r.|dt          |            dt          |           dz
  fv r| j         }nt          |          r@t	          j        t          j        |t          j                  t          |                     }t          |t                    r1|j        dv r(|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)rA   r   r   r   r   maybe_indices_to_slicerk   r|   intprP   r   r
  r   stop)r:   r-  rA   s      r;   _get_delete_freqz'DatetimeTimedeltaMixin._get_delete_freq  s     9 # )1s4yyj"c$ii!m<<<9D$$  4
3bg666D		 C c5)) )ch).C.CyI--c$ii=N1N1N#yr<   c                   | j                             |          }| j                             |          }d}| j        | j        ri|t
          u rn|dt          |            fv r|| j        z   | d         k    r| j        }nr|t          |           k    r|| j        z
  | d         k    r| j        }nCt          | j        t                    r| j        }n!| j        	                    |          r| j        }|S )z=
        Find the `freq` for self.insert(loc, item).
        Nr   r   )
r2   _validate_scalar	_box_funcrA   sizer   r   rP   r   is_on_offset)r:   r-  itemrF   rA   s        r;   _get_insert_freqz'DatetimeTimedeltaMixin._get_insert_freq  s     
++D11z##E**9 y !3;;QT
O++ty0@DG0K0K9DDSYY&&D49,<R,H,H9DDIt,, ! y''-- !yr<   c                    t                                          |          }|                     |          |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')
        )r~   deleterM  r2   r+  )r:   r-  r   r   s      r;   rV  zDatetimeTimedeltaMixin.delete  s7    8 $$!22377r<   c                    t                                          ||          }t          |t          |                     r |                     ||          |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')
        )r~   insertrP   rc   rT  r2   r+  )r:   r-  rS  r   r   s       r;   rX  zDatetimeTimedeltaMixin.insert  sT    8 T**fd4jj)) 	B!%!6!6sD!A!AFLr<   r   Tr5   r+   
allow_fillc                V   t          j        d|           t          j        |t          j                  }t          j        | ||||fi |}t          j        |t          |                     }t          |t                    r&| 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')
        rS   r   )nvvalidate_takerk   r|   rK  r&   taker   rJ  r   rP   r   r2   _get_getitem_freqr+  )	r:   indicesr5   rY  
fill_valuekwargsr   maybe_slicerA   s	            r;   r]  zDatetimeTimedeltaMixin.take>  s    b 	V$$$*WBG444,1'4Z
 
;A
 
 0#d))DDk5)) 	&://<<D!%FLr<   )r=   r-   )r   r-   r=   r	   )r=   r   r   r   )r=   r   )r=   r'   r   )r=   r	   )F)rZ   r%   r  r6   r=   r%   )rZ   r	   r=   r6   rE   )rZ   r	   r=   r	   )r6  r7  r8  r7  r9  r,   r=   r:  )r   r   )rr   )r   rD  )r-  rH  )r-  r   )r   TN)r5   r+   rY  r6   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)  r1  r3  r5  r<  r@  rC  rG  rM  rT  rV  rX  r]  r   r   s   @r;   r   r   '  s         
 *)))F#L6"K  %<$<J   X-; -; -; -;^< < <    X0> 0> 0> 0> 0>d  (  (  ( ^ (J    ^L L L LD D D D45 5 5 55 5 5 55 5 5 5 5.  (       $G G G G<$ $ $ $ $LC C C C C&  & & & & & &. . . .5 5 5 5
< < < < < < <&   ,   4     @           P < < < < < < < < <r<   r   )Pr   
__future__r   abcr   r   typingr   r   r   r	   r
   r   numpyrk   pandas._libsr   r   pandas._libs.tslibsr   r   r   r   r   r   r   pandas._libs.tslibs.dtypesr   pandas.compat.numpyr   r[  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.   rN   r/   dict_index_doc_kwargsr1   r   rS   r<   r;   <module>r     s    # " " " " "                                                   : 9 9 9 9 9 . . . . . .                        4 3 3 3 3 3       
            !                 ( ( ( ( ( ( ( ( ( ( ( (      F E E E E E 0 0 0 0 0 0 5 5 5 5 5 5 (((((((!!!!!!            ('''''D011 L+ L+ L+ L+ L+7 L+ L+ L+^S	 S	 S	 S	 S	2C S	 S	 S	 S	 S	r<   