@@ -1112,7 +1112,17 @@ cdef class _Timedelta(timedelta):
1112
1112
return self ._ms * 1000 + self ._us
1113
1113
1114
1114
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
+ """
1116
1126
# We need to override bc we overrode days/seconds/microseconds
1117
1127
# TODO: add nanos/1e9?
1118
1128
return self.days * 24 * 3600 + self.seconds + self.microseconds / 1_000_000
@@ -1274,6 +1284,14 @@ cdef class _Timedelta(timedelta):
1274
1284
Notes
1275
1285
-----
1276
1286
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)
1277
1295
"""
1278
1296
if self ._creso == NPY_FR_ns:
1279
1297
return timedelta(microseconds = int (self ._value) / 1000 )
@@ -1287,6 +1305,14 @@ cdef class _Timedelta(timedelta):
1287
1305
def to_timedelta64 (self ) -> np.timedelta64:
1288
1306
"""
1289
1307
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')
1290
1316
"""
1291
1317
cdef:
1292
1318
str abbrev = npy_unit_to_abbrev(self ._creso)
@@ -1309,6 +1335,14 @@ cdef class _Timedelta(timedelta):
1309
1335
See Also
1310
1336
--------
1311
1337
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')
1312
1346
"""
1313
1347
if dtype is not None or copy is not False:
1314
1348
raise ValueError(
@@ -1324,6 +1358,14 @@ cdef class _Timedelta(timedelta):
1324
1358
----------
1325
1359
dtype : str or dtype
1326
1360
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
1327
1369
"""
1328
1370
return np.timedelta64(self ._value).view(dtype)
1329
1371
@@ -1603,6 +1645,14 @@ cdef class _Timedelta(timedelta):
1603
1645
Returns
1604
1646
-------
1605
1647
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')
1606
1656
"""
1607
1657
dtype = np.dtype(f" m8[{unit}]" )
1608
1658
reso = get_unit_from_dtype(dtype)
@@ -1875,6 +1925,14 @@ class Timedelta(_Timedelta):
1875
1925
Raises
1876
1926
------
1877
1927
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')
1878
1936
"""
1879
1937
return self ._round(freq, RoundTo.NEAREST_HALF_EVEN)
1880
1938
@@ -1886,6 +1944,14 @@ class Timedelta(_Timedelta):
1886
1944
----------
1887
1945
freq : str
1888
1946
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')
1889
1955
"""
1890
1956
return self ._round(freq, RoundTo.MINUS_INFTY)
1891
1957
@@ -1897,6 +1963,14 @@ class Timedelta(_Timedelta):
1897
1963
----------
1898
1964
freq : str
1899
1965
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')
1900
1974
"""
1901
1975
return self ._round(freq, RoundTo.PLUS_INFTY)
1902
1976
0 commit comments