Skip to content

Commit 791f8f8

Browse files
ryankarlosPingviinituutti
authored andcommitted
DOC: Updating to_timedelta docstring (pandas-dev#23259)
1 parent a19480a commit 791f8f8

File tree

1 file changed

+34
-22
lines changed

1 file changed

+34
-22
lines changed

pandas/core/tools/timedeltas.py

+34-22
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,43 @@
1717

1818
def to_timedelta(arg, unit='ns', box=True, errors='raise'):
1919
"""
20-
Convert argument to timedelta
20+
Convert argument to timedelta.
21+
22+
Timedeltas are absolute differences in times, expressed in difference
23+
units (e.g. days, hours, minutes, seconds). This method converts
24+
an argument from a recognized timedelta format / value into
25+
a Timedelta type.
2126
2227
Parameters
2328
----------
24-
arg : string, timedelta, list, tuple, 1-d array, or Series
25-
unit : str, optional
26-
Denote the unit of the input, if input is an integer. Default 'ns'.
27-
Possible values:
28-
{'Y', 'M', 'W', 'D', 'days', 'day', 'hours', hour', 'hr', 'h',
29-
'm', 'minute', 'min', 'minutes', 'T', 'S', 'seconds', 'sec', 'second',
30-
'ms', 'milliseconds', 'millisecond', 'milli', 'millis', 'L',
31-
'us', 'microseconds', 'microsecond', 'micro', 'micros', 'U',
32-
'ns', 'nanoseconds', 'nano', 'nanos', 'nanosecond', 'N'}
33-
box : boolean, default True
34-
- If True returns a Timedelta/TimedeltaIndex of the results
35-
- if False returns a np.timedelta64 or ndarray of values of dtype
36-
timedelta64[ns]
29+
arg : str, timedelta, list-like or Series
30+
The data to be converted to timedelta.
31+
unit : str, default 'ns'
32+
Denotes the unit of the arg. Possible values:
33+
('Y', 'M', 'W', 'D', 'days', 'day', 'hours', hour', 'hr',
34+
'h', 'm', 'minute', 'min', 'minutes', 'T', 'S', 'seconds',
35+
'sec', 'second', 'ms', 'milliseconds', 'millisecond',
36+
'milli', 'millis', 'L', 'us', 'microseconds', 'microsecond',
37+
'micro', 'micros', 'U', 'ns', 'nanoseconds', 'nano', 'nanos',
38+
'nanosecond', 'N').
39+
box : bool, default True
40+
- If True returns a Timedelta/TimedeltaIndex of the results.
41+
- If False returns a numpy.timedelta64 or numpy.darray of
42+
values of dtype timedelta64[ns].
3743
errors : {'ignore', 'raise', 'coerce'}, default 'raise'
38-
- If 'raise', then invalid parsing will raise an exception
39-
- If 'coerce', then invalid parsing will be set as NaT
40-
- If 'ignore', then invalid parsing will return the input
44+
- If 'raise', then invalid parsing will raise an exception.
45+
- If 'coerce', then invalid parsing will be set as NaT.
46+
- If 'ignore', then invalid parsing will return the input.
4147
4248
Returns
4349
-------
44-
ret : timedelta64/arrays of timedelta64 if parsing succeeded
50+
timedelta64 or numpy.array of timedelta64
51+
Output type returned if parsing succeeded.
52+
53+
See also
54+
--------
55+
DataFrame.astype : Cast argument to a specified dtype.
56+
to_datetime : Convert argument to datetime.
4557
4658
Examples
4759
--------
@@ -69,10 +81,10 @@ def to_timedelta(arg, unit='ns', box=True, errors='raise'):
6981
TimedeltaIndex(['0 days', '1 days', '2 days', '3 days', '4 days'],
7082
dtype='timedelta64[ns]', freq=None)
7183
72-
See Also
73-
--------
74-
pandas.DataFrame.astype : Cast argument to a specified dtype.
75-
pandas.to_datetime : Convert argument to datetime.
84+
Returning an ndarray by using the 'box' keyword argument:
85+
86+
>>> pd.to_timedelta(np.arange(5), box=False)
87+
array([0, 1, 2, 3, 4], dtype='timedelta64[ns]')
7688
"""
7789
unit = parse_timedelta_unit(unit)
7890

0 commit comments

Comments
 (0)