zmc
2023-08-08 e792e9a60d958b93aef96050644f369feb25d61b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
U
¬ý°d¸ ã@sFdZddlmZddlmZddlmZmZddlZ    ddl
m Z ddl m Z mZddlmZmZdd    lmZdd
lmZmZdd lmZer¼dd lmZdd lmZmZddlmZmZm Z ed'dddddœdd„ƒZ!ed(dddddœdd„ƒZ!ed)dddddœdd„ƒZ!d*dddddœdd„Z!d+ddd!œd"d#„Z"d,dd$œd%d&„Z#dS)-z
timedelta support tools
é)Ú annotations)Ú    timedelta)Ú TYPE_CHECKINGÚoverloadN)Úlib)ÚNaTÚNaTType)Ú    TimedeltaÚparse_timedelta_unit)Ú is_list_like)ÚABCIndexÚ    ABCSeries)Úsequence_to_td64ns)Ú UnitChoices)Ú    ArrayLikeÚDateTimeErrorChoices)ÚIndexÚSeriesÚTimedeltaIndex.zstr | float | timedeltazUnitChoices | Nonerr    )ÚargÚunitÚerrorsÚreturncCsdS©N©©rrrrrúSd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\pandas/core/tools/timedeltas.pyÚ to_timedelta.srrcCsdSrrrrrrr7sz(list | tuple | range | ArrayLike | IndexrcCsdSrrrrrrr@sÚraisezQstr | int | float | timedelta | list | tuple | range | ArrayLike | Index | Seriesz#Timedelta | TimedeltaIndex | SeriescCs|dk    rt|ƒ}|dkr tdƒ‚|dkr0tdƒ‚|dkr<|St|tƒrjt|j||d}|j||j|jdSt|t    ƒr†t||||jdSt|t
j ƒr¨|j d    kr¨t  |¡}n>t|ƒrÎt|d
d ƒd krÎt|||dSt|d
d ƒd krætd ƒ‚t|tƒr|dk    rtd ƒ‚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'
        * 'm' / 'minute' / 'min' / 'minutes' / 'T'
        * 'S' / 'seconds' / 'sec' / 'second'
        * 'ms' / 'milliseconds' / 'millisecond' / 'milli' / 'millis' / 'L'
        * 'us' / 'microseconds' / 'microsecond' / 'micro' / 'micros' / 'U'
        * 'ns' / 'nanoseconds' / 'nano' / 'nanos' / 'nanosecond' / 'N'
 
        .. versionchanged:: 1.1.0
 
           Must not be specified when `arg` context strings and
           ``errors="raise"``.
 
    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)ÚignorerZcoercez5errors must be one of 'ignore', 'raise', or 'coerce'.>ÚMÚYÚyzqUnits 'M', 'Y', and 'y' are no longer supported, as they do not represent unambiguous timedelta values durations.©rr)ÚindexÚname)rrr%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
Ú
ValueErrorÚ
isinstancer Ú_convert_listlikeZ_valuesZ _constructorr$r%r ÚnpZndarrayr&rZitem_from_zerodimr ÚgetattrÚ    TypeErrorÚstrÚ _coerce_scalar_to_timedelta_type)rrrÚvaluesrrrrIs4eÿ
 
 ÿÚnsr#cCsFzt||ƒ}Wn2tk
r@|dkr(‚|dkr8|YSt}YnX|S)z)Convert string 'r' to a timedelta object.rr)r    r(r)ÚrrrÚresultrrrr/Ös
r/)rcCs–t|ttfƒst|dƒs8t|dƒs*t|ƒ}tj|td}zt|||ddd}Wn&tk
rv|dkrp|YS‚YnXddl    m
}||d    |d
}|S) z6Convert a list of objects to a timedelta index object.ÚdtypeZ    __array__)r4F)rrÚcopyrr)rr1)rr%) r)ÚlistÚtupleÚhasattrr+ÚarrayÚobjectrr(Úpandasr)rrrr%Ztd64arrrÚvaluerrrr*ês
     r*)..)..)..)Nr)r1r)NrN)$Ú__doc__Ú
__future__rÚdatetimerÚtypingrrÚnumpyr+Z pandas._libsrZpandas._libs.tslibsrrZpandas._libs.tslibs.timedeltasr    r
Zpandas.core.dtypes.commonr Zpandas.core.dtypes.genericr r Zpandas.core.arrays.timedeltasrrZpandas._typingrrr;rrrrr/r*rrrrÚ<module>sJ      ýýýôÿÿ