Skip to content

Commit

Permalink
DOC: Improved the docstring of pandas.Series.dt.to_pytimedelta (#20142)
Browse files Browse the repository at this point in the history
  • Loading branch information
ijmbarr authored and jorisvandenbossche committed Mar 17, 2018
1 parent e902764 commit 9dc49d3
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions pandas/core/indexes/accessors.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,39 @@ class TimedeltaProperties(Properties):
"""

def to_pytimedelta(self):
"""
Return an array of native `datetime.timedelta` objects.
Python's standard `datetime` library uses a different representation
timedelta's. This method converts a Series of pandas Timedeltas
to `datetime.timedelta` format with the same length as the original
Series.
Returns
-------
a : numpy.ndarray
1D array containing data with `datetime.timedelta` type.
Examples
--------
>>> s = pd.Series(pd.to_timedelta(np.arange(5), unit='d'))
>>> s
0 0 days
1 1 days
2 2 days
3 3 days
4 4 days
dtype: timedelta64[ns]
>>> s.dt.to_pytimedelta()
array([datetime.timedelta(0), datetime.timedelta(1),
datetime.timedelta(2), datetime.timedelta(3),
datetime.timedelta(4)], dtype=object)
See Also
--------
datetime.timedelta
"""
return self._get_values().to_pytimedelta()

@property
Expand Down

0 comments on commit 9dc49d3

Please sign in to comment.