a
    DBìjš"  ã                   @  sz  d Z ddlmZ ddlmZmZ ddlZddlZddl	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 ddlmZmZ ddlmZ erìddlmZ ddlm Z  ddlm!Z! ddl"m#Z#m$Z$ ddl%m&Z&m'Z'm(Z( ed+dddddœdd„ƒZ)ed,dddddœdd„ƒZ)ed-dddddœdd„ƒZ)d.d ddd!dœd"d„Z)d/ddd$œd%d&„Z*d0ddd'd(œd)d*„Z+dS )1z
timedelta support tools
é    )Úannotations)ÚTYPE_CHECKINGÚoverloadN)Úlib)ÚNaTÚNaTType)Ú	TimedeltaÚdisallow_ambiguous_unitÚparse_timedelta_unit)Úfind_stack_level)Úis_list_like)Ú
ArrowDtype)ÚABCIndexÚ	ABCSeries)Úsequence_to_td64ns)ÚHashable)Ú	timedelta)ÚUnitChoices)Ú	ArrayLikeÚDateTimeErrorChoices)ÚIndexÚSeriesÚTimedeltaIndex.zstr | float | timedeltazUnitChoices | Noner   r   )ÚargÚunitÚerrorsÚreturnc                 C  s   d S ©N© ©r   r   r   r   r   ú[/mnt/bigstor/www/usecases/.venv/lib/python3.9/site-packages/pandas/core/tools/timedeltas.pyÚto_timedelta4   s    r!   r   c                 C  s   d S r   r   r   r   r   r    r!   =   s    z(list | tuple | range | ArrayLike | Indexr   c                 C  s   d S r   r   r   r   r   r    r!   F   s    ÚraisezQstr | int | float | timedelta | list | tuple | range | ArrayLike | Index | Seriesz#Timedelta | TimedeltaIndex | Seriesc                 C  s&  |durt |ƒ}t|ƒ |dvr(tdƒ‚|dkrBtjdttƒ d� | du rN| S t| tƒr|t	| j
||d�}| j|| j| jd�S t| tƒr˜t	| ||| jd	�S t| tjƒrº| jd
krºt | ¡} n@t| ƒràt| ddƒdkràt	| ||d�S t| ddƒdk� rútdƒ‚t| tƒ�r|du�rtdƒ‚t| ||d�S )a�  
    Convert argument to timedelta.

    Timedeltas are absolute differences in times, expressed in difference
    units (e.g. days, hours, minutes, seconds). This method converts
    an argument from a recognized timedelta format / value into
    a Timedelta type.

    Parameters
    ----------
    arg : str, timedelta, list-like or Series
        The data to be converted to timedelta.

        .. versionchanged:: 2.0
            Strings with units 'M', 'Y' and 'y' do not represent
            unambiguous timedelta values and will raise an exception.

    unit : str, optional
        Denotes the unit of the arg for numeric `arg`. Defaults to ``"ns"``.

        Possible values:

        * 'W'
        * 'D' / 'days' / 'day'
        * 'hours' / 'hour' / 'hr' / 'h' / 'H'
        * 'm' / 'minute' / 'min' / 'minutes' / 'T'
        * 's' / 'seconds' / 'sec' / 'second' / 'S'
        * 'ms' / 'milliseconds' / 'millisecond' / 'milli' / 'millis' / 'L'
        * 'us' / 'microseconds' / 'microsecond' / 'micro' / 'micros' / 'U'
        * 'ns' / 'nanoseconds' / 'nano' / 'nanos' / 'nanosecond' / 'N'

        Must not be specified when `arg` contains strings and ``errors="raise"``.

        .. deprecated:: 2.2.0
            Units 'H', 'T', 'S', 'L', 'U' and 'N' are deprecated and will be removed
            in a future version. Please use 'h', 'min', 's', 'ms', 'us', and 'ns'
            instead of 'H', 'T', 'S', 'L', 'U' and 'N'.

    errors : {'ignore', 'raise', 'coerce'}, default 'raise'
        - If 'raise', then invalid parsing will raise an exception.
        - If 'coerce', then invalid parsing will be set as NaT.
        - If 'ignore', then invalid parsing will return the input.

    Returns
    -------
    timedelta
        If parsing succeeded.
        Return type depends on input:

        - list-like: TimedeltaIndex of timedelta64 dtype
        - Series: Series of timedelta64 dtype
        - scalar: Timedelta

    See Also
    --------
    DataFrame.astype : Cast argument to a specified dtype.
    to_datetime : Convert argument to datetime.
    convert_dtypes : Convert dtypes.

    Notes
    -----
    If the precision is higher than nanoseconds, the precision of the duration is
    truncated to nanoseconds for string inputs.

    Examples
    --------
    Parsing a single string to a Timedelta:

    >>> pd.to_timedelta('1 days 06:05:01.00003')
    Timedelta('1 days 06:05:01.000030')
    >>> pd.to_timedelta('15.5us')
    Timedelta('0 days 00:00:00.000015500')

    Parsing a list or array of strings:

    >>> pd.to_timedelta(['1 days 06:05:01.00003', '15.5us', 'nan'])
    TimedeltaIndex(['1 days 06:05:01.000030', '0 days 00:00:00.000015500', NaT],
                   dtype='timedelta64[ns]', freq=None)

    Converting numbers by specifying the `unit` keyword argument:

    >>> pd.to_timedelta(np.arange(5), unit='s')
    TimedeltaIndex(['0 days 00:00:00', '0 days 00:00:01', '0 days 00:00:02',
                    '0 days 00:00:03', '0 days 00:00:04'],
                   dtype='timedelta64[ns]', freq=None)
    >>> pd.to_timedelta(np.arange(5), unit='d')
    TimedeltaIndex(['0 days', '1 days', '2 days', '3 days', '4 days'],
                   dtype='timedelta64[ns]', freq=None)
    N)Úignorer"   Zcoercez5errors must be one of 'ignore', 'raise', or 'coerce'.r#   z“errors='ignore' is deprecated and will raise in a future version. Use to_timedelta without passing `errors` and catch exceptions explicitly instead)Ú
stacklevel©r   r   )ÚindexÚname©r   r   r'   r   Úndimé   zBarg must be a string, timedelta, list, tuple, 1-d array, or Seriesz9unit must not be specified if the input is/contains a str)r
   r	   Ú
ValueErrorÚwarningsÚwarnÚFutureWarningr   Ú
isinstancer   Ú_convert_listlikeZ_valuesZ_constructorr&   r'   r   ÚnpZndarrayr)   r   Zitem_from_zerodimr   ÚgetattrÚ	TypeErrorÚstrÚ _coerce_scalar_to_timedelta_type)r   r   r   Úvaluesr   r   r    r!   O   s:    gû

ÿÚnsr%   c                 C  sD   zt | |ƒ}W n0 ty>   |dkr&‚ |dkr6|  Y S t}Y n0 |S )z)Convert string 'r' to a timedelta object.r"   r#   )r   r+   r   )Úrr   r   Úresultr   r   r    r5   â   s    
r5   zHashable | Noner(   c                 C  s¶   t | ddƒ}t| ttfƒs"|du rDt| dƒs4t| ƒ} tj| td�} nt|tƒr\|j	dkr\| S zt
| ||dd�d }W n$ ty˜   |d	kr’|  Y S ‚ Y n0 dd
lm} |||d�}|S )z6Convert a list of objects to a timedelta index object.ÚdtypeNZ	__array__)r:   ÚmF)r   r   Úcopyr   r#   )r   )r'   )r2   r/   ÚlistÚtupleÚhasattrr1   ÚarrayÚobjectr   Úkindr   r+   Úpandasr   )r   r   r   r'   Z	arg_dtypeZtd64arrr   Úvaluer   r   r    r0   ö   s     
	r0   )..)..)..)Nr"   )r7   r"   )Nr"   N),Ú__doc__Ú
__future__r   Útypingr   r   r,   Únumpyr1   Zpandas._libsr   Zpandas._libs.tslibsr   r   Zpandas._libs.tslibs.timedeltasr   r	   r
   Zpandas.util._exceptionsr   Zpandas.core.dtypes.commonr   Zpandas.core.dtypes.dtypesr   Zpandas.core.dtypes.genericr   r   Zpandas.core.arrays.timedeltasr   Úcollections.abcr   Údatetimer   r   Zpandas._typingr   r   rC   r   r   r   r!   r5   r0   r   r   r   r    Ú<module>   sP     ý  ý  ý  ô  ÿ   ü