Skip to content

Commit d66d582

Browse files
saldanhadmroeschke
andauthored
DOC: fix pandas.TimedeltaIndex.to_pytimedelta RT03,SA01 (#59914)
* update docstrings * Update pandas/core/arrays/timedeltas.py Co-authored-by: Matthew Roeschke <[email protected]> --------- Co-authored-by: Matthew Roeschke <[email protected]>
1 parent 90c26ce commit d66d582

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

ci/code_checks.sh

-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
100100
-i "pandas.Timedelta.max PR02" \
101101
-i "pandas.Timedelta.min PR02" \
102102
-i "pandas.Timedelta.resolution PR02" \
103-
-i "pandas.TimedeltaIndex.to_pytimedelta RT03,SA01" \
104103
-i "pandas.Timestamp.max PR02" \
105104
-i "pandas.Timestamp.min PR02" \
106105
-i "pandas.Timestamp.nanosecond GL08" \

pandas/core/arrays/timedeltas.py

+21
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,19 @@ def to_pytimedelta(self) -> npt.NDArray[np.object_]:
790790
Returns
791791
-------
792792
numpy.ndarray
793+
A NumPy ``timedelta64`` object representing the same duration as the
794+
original pandas ``Timedelta`` object. The precision of the resulting
795+
object is in nanoseconds, which is the default
796+
time resolution used by pandas for ``Timedelta`` objects, ensuring
797+
high precision for time-based calculations.
798+
799+
See Also
800+
--------
801+
to_timedelta : Convert argument to timedelta format.
802+
Timedelta : Represents a duration between two dates or times.
803+
DatetimeIndex: Index of datetime64 data.
804+
Timedelta.components : Return a components namedtuple-like
805+
of a single timedelta.
793806
794807
Examples
795808
--------
@@ -800,6 +813,14 @@ def to_pytimedelta(self) -> npt.NDArray[np.object_]:
800813
>>> tdelta_idx.to_pytimedelta()
801814
array([datetime.timedelta(days=1), datetime.timedelta(days=2),
802815
datetime.timedelta(days=3)], dtype=object)
816+
817+
>>> tidx = pd.TimedeltaIndex(data=["1 days 02:30:45", "3 days 04:15:10"])
818+
>>> tidx
819+
TimedeltaIndex(['1 days 02:30:45', '3 days 04:15:10'],
820+
dtype='timedelta64[ns]', freq=None)
821+
>>> tidx.to_pytimedelta()
822+
array([datetime.timedelta(days=1, seconds=9045),
823+
datetime.timedelta(days=3, seconds=15310)], dtype=object)
803824
"""
804825
return ints_to_pytimedelta(self._ndarray)
805826

0 commit comments

Comments
 (0)