@@ -1112,7 +1112,17 @@ cdef class _Timedelta(timedelta):
11121112 return self ._ms * 1000 + self ._us
11131113
11141114 def total_seconds (self ) -> float:
1115- """Total seconds in the duration."""
1115+ """
1116+ Total seconds in the duration.
1117+
1118+ Examples
1119+ --------
1120+ >>> td = pd.Timedelta(' 1min' )
1121+ >>> td
1122+ Timedelta('0 days 00:01:00')
1123+ >>> td.total_seconds()
1124+ 60.0
1125+ """
11161126 # We need to override bc we overrode days/seconds/microseconds
11171127 # TODO: add nanos/1e9?
11181128 return self.days * 24 * 3600 + self.seconds + self.microseconds / 1_000_000
@@ -1274,6 +1284,14 @@ cdef class _Timedelta(timedelta):
12741284 Notes
12751285 -----
12761286 Any nanosecond resolution will be lost.
1287+
1288+ Examples
1289+ --------
1290+ >>> td = pd.Timedelta('3D')
1291+ >>> td
1292+ Timedelta('3 days 00:00:00')
1293+ >>> td.to_pytimedelta()
1294+ datetime.timedelta(days=3)
12771295 """
12781296 if self ._creso == NPY_FR_ns:
12791297 return timedelta(microseconds = int (self ._value) / 1000 )
@@ -1287,6 +1305,14 @@ cdef class _Timedelta(timedelta):
12871305 def to_timedelta64 (self ) -> np.timedelta64:
12881306 """
12891307 Return a numpy.timedelta64 object with 'ns' precision.
1308+
1309+ Examples
1310+ --------
1311+ >>> td = pd.Timedelta(' 3D' )
1312+ >>> td
1313+ Timedelta('3 days 00:00:00')
1314+ >>> td.to_timedelta64()
1315+ numpy.timedelta64(259200000000000,'ns')
12901316 """
12911317 cdef:
12921318 str abbrev = npy_unit_to_abbrev(self ._creso)
@@ -1309,6 +1335,14 @@ cdef class _Timedelta(timedelta):
13091335 See Also
13101336 --------
13111337 Series.to_numpy : Similar method for Series.
1338+
1339+ Examples
1340+ --------
1341+ >>> td = pd.Timedelta(' 3D' )
1342+ >>> td
1343+ Timedelta('3 days 00:00:00')
1344+ >>> td.to_numpy()
1345+ numpy.timedelta64(259200000000000,'ns')
13121346 """
13131347 if dtype is not None or copy is not False:
13141348 raise ValueError(
@@ -1324,6 +1358,14 @@ cdef class _Timedelta(timedelta):
13241358 ----------
13251359 dtype : str or dtype
13261360 The dtype to view the underlying data as.
1361+
1362+ Examples
1363+ --------
1364+ >>> td = pd.Timedelta('3D')
1365+ >>> td
1366+ Timedelta('3 days 00:00:00')
1367+ >>> td.view(int)
1368+ 259200000000000
13271369 """
13281370 return np.timedelta64(self ._value).view(dtype)
13291371
@@ -1603,6 +1645,14 @@ cdef class _Timedelta(timedelta):
16031645 Returns
16041646 -------
16051647 Timedelta
1648+
1649+ Examples
1650+ --------
1651+ >>> td = pd.Timedelta('1001ms')
1652+ >>> td
1653+ Timedelta('0 days 00:00:01.001000')
1654+ >>> td.as_unit('s')
1655+ Timedelta('0 days 00:00:01')
16061656 """
16071657 dtype = np.dtype(f" m8[{unit}]" )
16081658 reso = get_unit_from_dtype(dtype)
@@ -1875,6 +1925,14 @@ class Timedelta(_Timedelta):
18751925 Raises
18761926 ------
18771927 ValueError if the freq cannot be converted
1928+
1929+ Examples
1930+ --------
1931+ >>> td = pd.Timedelta('1001ms')
1932+ >>> td
1933+ Timedelta('0 days 00:00:01.001000')
1934+ >>> td.round('s')
1935+ Timedelta('0 days 00:00:01')
18781936 """
18791937 return self ._round(freq, RoundTo.NEAREST_HALF_EVEN)
18801938
@@ -1886,6 +1944,14 @@ class Timedelta(_Timedelta):
18861944 ----------
18871945 freq : str
18881946 Frequency string indicating the flooring resolution.
1947+
1948+ Examples
1949+ --------
1950+ >>> td = pd.Timedelta('1001ms')
1951+ >>> td
1952+ Timedelta('0 days 00:00:01.001000')
1953+ >>> td.floor('s')
1954+ Timedelta('0 days 00:00:01')
18891955 """
18901956 return self ._round(freq, RoundTo.MINUS_INFTY)
18911957
@@ -1897,6 +1963,14 @@ class Timedelta(_Timedelta):
18971963 ----------
18981964 freq : str
18991965 Frequency string indicating the ceiling resolution.
1966+
1967+ Examples
1968+ --------
1969+ >>> td = pd.Timedelta('1001ms')
1970+ >>> td
1971+ Timedelta('0 days 00:00:01.001000')
1972+ >>> td.ceil('s')
1973+ Timedelta('0 days 00:00:02')
19001974 """
19011975 return self ._round(freq, RoundTo.PLUS_INFTY)
19021976
0 commit comments