Skip to content

Commit cf4271d

Browse files
committed
fix docstrings -TimedeltIndex.to_pytimedelta
1 parent 42fc0a3 commit cf4271d

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

ci/code_checks.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
103103
-i "pandas.Timedelta.max PR02" \
104104
-i "pandas.Timedelta.min PR02" \
105105
-i "pandas.Timedelta.resolution PR02" \
106-
-i "pandas.TimedeltaIndex.to_pytimedelta RT03,SA01" \
107106
-i "pandas.Timestamp.max PR02" \
108107
-i "pandas.Timestamp.min PR02" \
109108
-i "pandas.Timestamp.nanosecond GL08" \

pandas/core/arrays/timedeltas.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,20 @@ def to_pytimedelta(self) -> npt.NDArray[np.object_]:
789789
790790
Returns
791791
-------
792-
numpy.ndarray
792+
**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,7 +813,16 @@ 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
"""
825+
804826
return ints_to_pytimedelta(self._ndarray)
805827

806828
days_docstring = textwrap.dedent(

0 commit comments

Comments
 (0)