
    Owg*                    h   d Z ddlmZ ddlmZ ddl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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%  e#g dejL                  z   ed       e#g de       G d de!                    Z'	 	 	 	 	 	 ddd	 	 	 	 	 ddZ(y)z implement the TimedeltaIndex     )annotations)TYPE_CHECKINGN)indexlib)
Resolution	Timedelta	to_offset)disallow_ambiguous_unit)find_stack_level)	is_scalarpandas_dtype)	ABCSeries)TimedeltaArray)Indexmaybe_extract_name)DatetimeTimedeltaMixin)inherit_names)DtypeObj)__neg____pos____abs__total_secondsroundfloorceilT)wrap)
componentsto_pytimedeltasumstdmedianc                      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                  ej                  ej                  dddf	 dd	Zdd
Zd ZddZddZedd       Zy)TimedeltaIndexal  
    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.
    unit : {'D', 'h', 'm', 's', 'ms', 'us', 'ns'}, optional
        The unit of ``data``.

        .. deprecated:: 2.2.0
         Use ``pd.to_timedelta`` instead.

    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
        Make a copy of input array.
    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 `this link
    <https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#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[ns]', 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')
    timedeltaindexc                "    t         j                  S N)libindexTimedeltaEngineselfs    U/var/www/horilla/myenv/lib/python3.12/site-packages/pandas/core/indexes/timedeltas.py_engine_typezTimedeltaIndex._engine_type   s    '''    r   _datac                .    | j                   j                  S r&   )r.   _resolution_objr)   s    r+   r0   zTimedeltaIndex._resolution_obj   s    zz)))r-   NFc                   |t         j                  ur2t        j                  d| j                   dt
        t                      |t         j                  ur3t        j                  d| j                   dt
        t                      nd }t        |||       }t        |      r| j                  |       t        |       |t        |      }t        |t              rH|t         j                  u r6|||j                  k(  r%|r|j                         }| j!                  ||      S t        |t"              rG|t         j                  u r5|3|||j                  k(  r"|r|j                         S |j%                         S t        j&                  |||||      }d }	|s"t        |t(        t*        f      r|j,                  }	| j!                  |||	      S )	NzThe 'closed' keyword in zD construction is deprecated and will be removed in a future version.)
stacklevelzThe 'unit' keyword in za construction is deprecated and will be removed in a future version. Use pd.to_timedelta instead.name)frequnitdtypecopy)r4   refs)r   
no_defaultwarningswarn__name__FutureWarningr   r   r   _raise_scalar_data_errorr
   r   
isinstancer   r7   r8   _simple_newr#   _view_from_sequence_not_strictr   r   _references)
clsdatar6   r5   closedr7   r8   r4   tdarrr9   s
             r+   __new__zTimedeltaIndex.__new__   s    'MM*3<<. 9F F+-	 s~~%MM( 7/ / +- D!$c2T?((.% 'E t^,&%4::"5yy{??4d?33 t^,&%4::"5yy{"zz|# 88t$e$
 
4)U);<##Du4d;;r-   c                .    t        j                  |d      S )zF
        Can we compare values of the given dtype to our own?
        m)r   is_np_dtype)r*   r7   s     r+   _is_comparable_dtypez#TimedeltaIndex._is_comparable_dtype   s     uc**r-   c                    | j                  |       	 | j                  j                  |d      }t        j                  | |      S # t        $ r}t	        |      |d}~ww xY w)z
        Get integer location for requested label

        Returns
        -------
        loc : int, slice, or ndarray[int]
        F)unboxN)_check_indexing_errorr.   _validate_scalar	TypeErrorKeyErrorr   get_loc)r*   keyerrs      r+   rT   zTimedeltaIndex.get_loc   sa     	""3'	)**--c-?C }}T3''  	)3-S(	)s   A 	A AA c                     t        |      }|d fS r&   )r   )r*   labelparseds      r+   _parse_with_resozTimedeltaIndex._parse_with_reso   s    5!t|r-   c                    |j                  |j                        }|t        |j                        z   t        dd      z
  }||fS )N   ns)r   resolution_stringr	   r   )r*   resorY   lboundrbounds        r+   _parsed_string_to_boundsz'TimedeltaIndex._parsed_string_to_bounds   sA    f667)F$<$<==	!T@RRv~r-   c                     y)Ntimedelta64 r)   s    r+   inferred_typezTimedeltaIndex.inferred_type  s    r-   )returnztype[libindex.TimedeltaEngine])rg   zResolution | None)r8   bool)r7   r   rg   rh   )rX   str)rY   r   )rg   ri   )r=   
__module____qualname____doc___typr   	_data_clspropertyr,   __annotations__r   _get_string_slicer0   r   r:   rI   rM   rT   rZ   rb   rf   re   r-   r+   r#   r#   &   s    "FP DI( (  // * * ^^^^~~E< E<R+("
  r-   r#   )r6   c                   |t        j                  || |      rd}t        |      }t        j                  | |||||      }t
        j                  ||      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 : str, 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 : str, default None
        Specify the desired resolution of the result.

        .. versionadded:: 2.0.0

    Returns
    -------
    TimedeltaIndex

    Notes
    -----
    Of the four parameters ``start``, ``end``, ``periods``, and ``freq``,
    exactly three must be specified. If ``freq`` is omitted, the resulting
    ``TimedeltaIndex`` will have ``periods`` linearly spaced elements between
    ``start`` and ``end`` (closed on both sides).

    To learn more about the frequency strings, please see `this link
    <https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#offset-aliases>`__.

    Examples
    --------
    >>> pd.timedelta_range(start='1 day', periods=4)
    TimedeltaIndex(['1 days', '2 days', '3 days', '4 days'],
                   dtype='timedelta64[ns]', 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[ns]', 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[ns]', 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[ns]', 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')
    D)rG   r6   r3   )comany_noner	   r   _generate_ranger#   rA   )startendperiodsr5   r4   rG   r6   rH   s           r+   timedelta_rangerz   
  s\    f |WeS9T?D**sGT&tE %%e$%77r-   )NNNNNN)ry   z
int | Noner6   z
str | Nonerg   r#   ))rl   
__future__r   typingr   r;   pandas._libsr   r'   r   pandas._libs.tslibsr   r   r	   pandas._libs.tslibs.timedeltasr
   pandas.util._exceptionsr   pandas.core.dtypes.commonr   r   pandas.core.dtypes.genericr   pandas.core.arrays.timedeltasr   pandas.core.commoncorecommonrt   pandas.core.indexes.baser   r    pandas.core.indexes.datetimeliker   pandas.core.indexes.extensionr   pandas._typingr   
_field_opsr#   rz   re   r-   r+   <module>r      s    $ "    
 C 4 1 8     D 7' P 		  	Q+ Q	 Qj 		Z8 Z8 Z8 Z8 Z8r-   