o
    ŀg"                     @  s\  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rvd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Z)e		d-d/ddZ)e		d-d0d!dZ)		"d1d2d%dZ)	"d3d4d'd(Z*		"	d5d6d+d,Z+dS )7z
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.argstr | float | timedeltaunitUnitChoices | Noneerrorsr   returnr   c                 C     d S N r   r   r   r!   r!   P/var/www/html/myenv/lib/python3.10/site-packages/pandas/core/tools/timedeltas.pyto_timedelta4      r$   r   c                 C  r   r    r!   r"   r!   r!   r#   r$   =   r%   (list | tuple | range | ArrayLike | Indexr   c                 C  r   r    r!   r"   r!   r!   r#   r$   F   r%   raiseQstr | int | float | timedelta | list | tuple | range | ArrayLike | Index | Series#Timedelta | TimedeltaIndex | Seriesc                 C  s   |durt |}t| |dvrtd|dkr!tjdtt d | du r'| S t| tr>t	| j
||d}| j|| j| jdS t| trLt	| ||| jd	S t| tjr]| jd
kr]t| } nt| rpt| dddkrpt	| ||dS t| dddkr|tdt| tr|durt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'   coercez5errors must be one of 'ignore', 'raise', or 'coerce'.r*   zerrors='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_listlike_values_constructorr-   r.   r   npndarrayr/   r   item_from_zerodimr   getattr	TypeErrorstr _coerce_scalar_to_timedelta_type)r   r   r   valuesr!   r!   r#   r$   O   s:   g

nsc                 C  sD   zt | |}W |S  ty!   |dkr |dkr|  Y S t}Y |S w )z)Convert string 'r' to a timedelta object.r'   r*   )r   r1   r   )rr   r   resultr!   r!   r#   r?      s   
r?   r.   Hashable | Nonec                 C  s   t | dd}t| ttfs|du r"t| dst| } tj| td} nt|tr.|j	dkr.| S zt
| ||ddd }W n tyJ   |d	krI|  Y S  w dd
lm} |||d}|S )z6Convert a list of objects to a timedelta index object.dtypeN	__array__)rE   mF)r   r   copyr   r*   )r   )r.   )r<   r5   listtuplehasattrr9   arrayobjectr   kindr   r1   pandasr   )r   r   r   r.   	arg_dtypetd64arrr   valuer!   r!   r#   r6      s"   
	r6   )..)r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   )r   r&   r   r   r   r   r   r   )Nr'   )r   r(   r   r   r   r   r   r)   )rA   r'   )r   r   r   r   )Nr'   N)r   r   r   r   r.   rD   ),__doc__
__future__r   typingr   r   r2   numpyr9   pandas._libsr   pandas._libs.tslibsr   r   pandas._libs.tslibs.timedeltasr   r	   r
   pandas.util._exceptionsr   pandas.core.dtypes.commonr   pandas.core.dtypes.dtypesr   pandas.core.dtypes.genericr   r   pandas.core.arrays.timedeltasr   collections.abcr   datetimer   r   pandas._typingr   r   rO   r   r   r   r$   r?   r6   r!   r!   r!   r#   <module>   sR     