
    Pi3              	         d Z ddlmZ ddlmZmZ ddlmZm	Z	 ddl
mZmZmZ ddlmZ ddlmZ ddlmZmZ dd	lmZ dd
lmZ ddlmZ ddlmc mZ ddlm Z m!Z! ddl"m#Z# ddl$m%Z% erddlm&Z& ddl
m'Z'm(Z( ddl)m*Z*m+Z+  e%dddddddgej,        ed           e%g de           ed           G d de#                                              Z- ed          	 	 	 	 	 	 d'dd d(d&            Z.dS ))zimplement the TimedeltaIndex    )annotations)TYPE_CHECKINGcast)indexlib)
Resolution	Timedelta	to_offset)abbrev_to_npy_unit)
set_module)	is_scalarpandas_dtype)
ArrowDtype)	ABCSeries)TimedeltaArrayN)Indexmaybe_extract_name)DatetimeTimedeltaMixin)inherit_names)NaTType)DayTick)DtypeObjTimeUnit__neg____pos____abs__total_secondsroundfloorceilT)wrap)
componentsto_pytimedeltasumstdmedianpandasc                      e Zd ZU dZdZeZedd            Zde	d<   e
j        Zedd	            Zd
ej        d
d
d
fddZd dZd Zd!dZd"dZed#d            Zd
S )$TimedeltaIndexa 	  
    Immutable Index of timedelta64 data.

    Represented internally as int64, and scalars returned Timedelta objects.

    Parameters
    ----------
    data : array-like (1-dimensional), optional
        Optional timedelta-like data to construct index with.
    freq : str or pandas offset object, optional
        One of pandas date offset strings or corresponding objects. The string
        ``'infer'`` can be passed in order to set the frequency of the index as
        the inferred frequency upon creation.
    dtype : numpy.dtype or str, default None
        Valid ``numpy`` dtypes are ``timedelta64[ns]``, ``timedelta64[us]``,
        ``timedelta64[ms]``, and ``timedelta64[s]``.
    copy : bool, default None
        Whether to copy input data, only relevant for array, Series, and Index
        inputs (for other input, e.g. a list, a new array is created anyway).
        Defaults to True for array input and False for Index/Series.
        Set to False to avoid copying array input at your own risk (if you
        know the input data won't be modified elsewhere).
        Set to True to force copying Series/Index input up front.
    name : object
        Name to be stored in the index.

    Attributes
    ----------
    days
    seconds
    microseconds
    nanoseconds
    components
    inferred_freq

    Methods
    -------
    to_pytimedelta
    to_series
    round
    floor
    ceil
    to_frame
    mean

    See Also
    --------
    Index : The base pandas Index type.
    Timedelta : Represents a duration between two dates or times.
    DatetimeIndex : Index of datetime64 data.
    PeriodIndex : Index of Period data.
    timedelta_range : Create a fixed-frequency TimedeltaIndex.

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

    Examples
    --------
    >>> pd.TimedeltaIndex(["0 days", "1 days", "2 days", "3 days", "4 days"])
    TimedeltaIndex(['0 days', '1 days', '2 days', '3 days', '4 days'],
                   dtype='timedelta64[us]', freq=None)

    We can also let pandas infer the frequency when possible.

    >>> pd.TimedeltaIndex(np.arange(5) * 24 * 3600 * 1e9, freq="infer")
    TimedeltaIndex(['0 days', '1 days', '2 days', '3 days', '4 days'],
                   dtype='timedelta64[ns]', freq='D')
    timedeltaindexreturntype[libindex.TimedeltaEngine]c                    t           j        S N)libindexTimedeltaEngineselfs    r/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/pandas/core/indexes/timedeltas.py_engine_typezTimedeltaIndex._engine_type   s    ''    r   _dataResolution | Nonec                    | j         j        S r/   )r7   _resolution_objr2   s    r4   r:   zTimedeltaIndex._resolution_obj   s    z))r6   Ncopybool | Nonec                   t          |||           }|                     |||          \  }}t          |          r|                     |           |t	          |          }t          |t                    rH|t          j        u r:|||j	        k    r-|r|
                                }|                     ||          S t          |t                    rG|t          j        u r9|7|||j	        k    r*|r|
                                S |                                S t          j        ||d ||          }d }|s#t          |t          t           f          r|j        }|                     |||          S )Nname)frequnitdtyper;   )r?   refs)r   _maybe_copy_array_inputr   _raise_scalar_data_errorr   
isinstancer   r   
no_defaultrB   r;   _simple_newr*   _view_from_sequence_not_strictr   r   _references)clsdatar@   rB   r;   r?   tdarrrC   s           r4   __new__zTimedeltaIndex.__new__   s    "$c22 00tUCC
dT?? 	/((... ''E t^,,	4&&%4:"5"5 #yy{{??4d?333 t^,,		$&&%4:"5"5 $yy{{"zz||# 8t$e$
 
 
  	$
4)U);<< 	$#Du4d;;;r6   rB   r   boolc                l    t          |t                    r|j        dk    S t          j        |d          S )zF
        Can we compare values of the given dtype to our own?
        m)rF   r   kindr   is_np_dtype)r3   rB   s     r4   _is_comparable_dtypez#TimedeltaIndex._is_comparable_dtype   s5     eZ(( 	%:$$uc***r6   c                    |                      |           	 | j                            |d          }n"# t          $ r}t	          |          |d}~ww xY wt          j        | |          S )z
        Get integer location for requested label

        Returns
        -------
        loc : int, slice, or ndarray[int]
        F)unboxN)_check_indexing_errorr7   _validate_scalar	TypeErrorKeyErrorr   get_loc)r3   keyerrs      r4   r\   zTimedeltaIndex.get_loc   sz     	""3'''	)*--c-??CC 	) 	) 	)3--S(	) }T3'''s   4 
AAAlabelstr&tuple[Timedelta | NaTType, Resolution]c                    t          |          }t          |t                     rt          j        |j                  }nt          j        d          }||fS )Ns)r	   rF   r   get_reso_from_freqstrrA   )r3   r_   parsedresos       r4   _parse_with_resozTimedeltaIndex._parse_with_reso   sQ    5!!fi(( 	93FK@@DD 3C88Dt|r6   rf   r   re   r	   c                    |                     |j                  }|t          |j                  z   t          d| j                                      | j                  z
  }||fS )N   rA   )r   resolution_stringr
   r	   rA   as_unit)r3   rf   re   lboundrbounds        r4   _parsed_string_to_boundsz'TimedeltaIndex._parsed_string_to_bounds  sd    f6770112	***2249==> 	
 v~r6   c                    dS )Ntimedelta64 r2   s    r4   inferred_typezTimedeltaIndex.inferred_type  s    }r6   )r,   r-   )r,   r8   )r;   r<   )rB   r   r,   rP   )r_   r`   r,   ra   )rf   r   re   r	   )r,   r`   )__name__
__module____qualname____doc___typr   	_data_clspropertyr5   __annotations__r   _get_string_slicer:   r   rG   rO   rU   r\   rg   ro   rs   rr   r6   r4   r*   r*   2   s        4E EN DI( ( ( X(  / * * * X* ^ 0< 0< 0< 0< 0<h+ + + +( ( (*          X  r6   r*   rj   periods
int | NonerA   TimeUnit | Noner,   c                  |t          j        || |          rd}t          |          }t          j        | |||          dk    rt	          d          |]| |t          |           } t          |          }t          t
          |           } t          t
          |          }t          | j                  t          |j                  k    rt          d| j                  }nt          d|j                  }nu| :t          |           } t          t
          |           } t          d| j                  }n9t          |          }t          t
          |          }t          d|j                  }|Dt          d|          }t          |          }|j	        |k    rt          d|j
        j                  }t          j        | |||||          }t                              ||          S )	a  
    Return a fixed frequency TimedeltaIndex with day as the default.

    Parameters
    ----------
    start : str or timedelta-like, default None
        Left bound for generating timedeltas.
    end : str or timedelta-like, default None
        Right bound for generating timedeltas.
    periods : int, default None
        Number of periods to generate.
    freq : str, Timedelta, datetime.timedelta, or DateOffset, default 'D'
        Frequency strings can have multiples, e.g. '5h'.
    name : Hashable, default None
        Name of the resulting TimedeltaIndex.
    closed : str, default None
        Make the interval closed with respect to the given frequency to
        the 'left', 'right', or both sides (None).
    unit : {'s', 'ms', 'us', 'ns', None}, default None
        Specify the desired resolution of the result.
        If not specified, this is inferred from the 'start', 'end', and 'freq'
        using the same inference as :class:`Timedelta` taking the highest
        resolution of the three that are provided.

        .. versionadded:: 2.0.0

    Returns
    -------
    TimedeltaIndex
        Fixed frequency, with day as the default.

    See Also
    --------
    date_range : Return a fixed frequency DatetimeIndex.
    period_range : Return a fixed frequency PeriodIndex.

    Notes
    -----
    Of the four parameters ``start``, ``end``, ``periods``, and ``freq``,
    a maximum of three can be specified at once. Of the three parameters
    ``start``, ``end``, and ``periods``, at least two must be specified.
    If ``freq`` is omitted, the resulting ``DatetimeIndex`` will have
    ``periods`` linearly spaced elements between ``start`` and ``end``
    (closed on both sides).

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

    Examples
    --------
    >>> pd.timedelta_range(start="1 day", periods=4)
    TimedeltaIndex(['1 days', '2 days', '3 days', '4 days'],
                   dtype='timedelta64[us]', freq='D')

    The ``closed`` parameter specifies which endpoint is included.  The default
    behavior is to include both endpoints.

    >>> pd.timedelta_range(start="1 day", periods=4, closed="right")
    TimedeltaIndex(['2 days', '3 days', '4 days'],
                   dtype='timedelta64[us]', freq='D')

    The ``freq`` parameter specifies the frequency of the TimedeltaIndex.
    Only fixed frequencies can be passed, non-fixed frequencies such as
    'M' (month end) will raise.

    >>> pd.timedelta_range(start="1 day", end="2 days", freq="6h")
    TimedeltaIndex(['1 days 00:00:00', '1 days 06:00:00', '1 days 12:00:00',
                    '1 days 18:00:00', '2 days 00:00:00'],
                   dtype='timedelta64[us]', freq='6h')

    Specify ``start``, ``end``, and ``periods``; the frequency is generated
    automatically (linearly spaced).

    >>> pd.timedelta_range(start="1 day", end="5 days", periods=4)
    TimedeltaIndex(['1 days 00:00:00', '2 days 08:00:00', '3 days 16:00:00',
                    '5 days 00:00:00'],
                   dtype='timedelta64[us]', freq=None)

    **Specify a unit**

    >>> pd.timedelta_range("1 Day", periods=3, freq="100000D", unit="s")
    TimedeltaIndex(['1 days', '100001 days', '200001 days'],
                   dtype='timedelta64[s]', freq='100000D')
    ND   zVOf the four parameters: start, end, periods, and freq, exactly three must be specifiedr   z
Tick | Day)closedrA   r>   )comany_noner
   count_not_none
ValueErrorr	   r   r   rA   _cresobasefreqstrr   _generate_ranger*   rH   )	startendr}   r@   r?   r   rA   cresorN   s	            r4   timedelta_ranger     s   ~ |WeS99|T??D
%gt44998
 
 	

 | e$$EC..CE**Ey#&&C!%*--0B380L0LLLJ
33J11e$$EE**E
EJ//DDC..Cy#&&C
CH--D d++D&t,,E{U""J	(9::*sGT&t  E %%e$%777r6   )NNNNNN)r}   r~   rA   r   r,   r*   )/rw   
__future__r   typingr   r   pandas._libsr   r0   r   pandas._libs.tslibsr   r	   r
   pandas._libs.tslibs.dtypesr   pandas.util._decoratorsr   pandas.core.dtypes.commonr   r   pandas.core.dtypes.dtypesr   pandas.core.dtypes.genericr   pandas.core.arrays.timedeltasr   pandas.core.commoncorecommonr   pandas.core.indexes.baser   r    pandas.core.indexes.datetimeliker   pandas.core.indexes.extensionr   r   r   r   pandas._typingr   r   
_field_opsr*   r   rr   r6   r4   <module>r      s&   " " " " " " " "       
                
 : 9 9 9 9 9 . . . . . .        1 0 0 0 0 0 0 0 0 0 0 0 8 8 8 8 8 8                          D C C C C C 7 7 7 7 7 7 	$$$$$$               	 
	"	 	      	 	 HI I I I I+ I I 	 	 2IX H
		I8 !I8 I8 I8 I8 I8 I8 I8 I8r6   