From 6ba29f8870b66042cc2e40fda49161e775dadd47 Mon Sep 17 00:00:00 2001 From: ijmbarr Date: Sat, 10 Mar 2018 15:34:11 +0100 Subject: [PATCH 1/4] DOC: Improved the docstring of pandas.Series.dt.total_seconds --- pandas/core/indexes/timedeltas.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/pandas/core/indexes/timedeltas.py b/pandas/core/indexes/timedeltas.py index a14de18b1012f..306a93cd8e2eb 100644 --- a/pandas/core/indexes/timedeltas.py +++ b/pandas/core/indexes/timedeltas.py @@ -501,7 +501,33 @@ def f(x): def total_seconds(self): """ - Total duration of each element expressed in seconds. + Return total duration of each element expressed in seconds. + + Return a series with the same length and index as the original, + containing the length of each element expressed in seconds. + + Returns + ------- + s : pandas.Series + a series of type `float64`. + + 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.total_seconds() + 0 0.0 + 1 86400.0 + 2 172800.0 + 3 259200.0 + 4 345600.0 + dtype: float64 """ return Index(self._maybe_mask_results(1e-9 * self.asi8), name=self.name) From 9d8d43bccf0329b03dbcf6be40da8a6e1d22079a Mon Sep 17 00:00:00 2001 From: ijmbarr Date: Sat, 10 Mar 2018 16:26:31 +0100 Subject: [PATCH 2/4] DOC: update the pandas.Series.dt.total_seconds docstring --- pandas/core/indexes/timedeltas.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pandas/core/indexes/timedeltas.py b/pandas/core/indexes/timedeltas.py index cd09b5e526bb6..ddda4c5fc6152 100644 --- a/pandas/core/indexes/timedeltas.py +++ b/pandas/core/indexes/timedeltas.py @@ -527,6 +527,10 @@ def total_seconds(self): 3 259200.0 4 345600.0 dtype: float64 + + See Also + -------- + datetime.timedelta.total_seconds """ return Index(self._maybe_mask_results(1e-9 * self.asi8), name=self.name) From 78801cb2d7cce940ff18c6ffdea7f43da0e1b1a8 Mon Sep 17 00:00:00 2001 From: ijmbarr Date: Tue, 13 Mar 2018 07:45:33 +0100 Subject: [PATCH 3/4] update the pandas.Series.dt.total_seconds docstring --- pandas/core/indexes/timedeltas.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/indexes/timedeltas.py b/pandas/core/indexes/timedeltas.py index ddda4c5fc6152..68872f612233a 100644 --- a/pandas/core/indexes/timedeltas.py +++ b/pandas/core/indexes/timedeltas.py @@ -508,7 +508,7 @@ def total_seconds(self): Returns ------- s : pandas.Series - a series of type `float64`. + Series of type `float64`. Examples -------- From 41bfa9d9ffed0189909fac33da6f7ef7cd3cbb77 Mon Sep 17 00:00:00 2001 From: Tom Augspurger Date: Tue, 13 Mar 2018 08:58:41 -0500 Subject: [PATCH 4/4] DatetimeIndex too --- pandas/core/indexes/timedeltas.py | 34 ++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/pandas/core/indexes/timedeltas.py b/pandas/core/indexes/timedeltas.py index 68872f612233a..b5a08fc0168e4 100644 --- a/pandas/core/indexes/timedeltas.py +++ b/pandas/core/indexes/timedeltas.py @@ -502,16 +502,28 @@ def total_seconds(self): """ Return total duration of each element expressed in seconds. - Return a series with the same length and index as the original, - containing the length of each element expressed in seconds. + This method is available directly on TimedeltaIndex and on Series + containing timedelta values under the ``.dt`` namespace. Returns ------- - s : pandas.Series - Series of type `float64`. + seconds : Float64Index or Series + When the calling object is a TimedeltaIndex, the return type is a + Float64Index. When the calling object is a Series, the return type + is Series of type `float64` whose index is the same as the + original. + + See Also + -------- + datetime.timedelta.total_seconds : Standard library version + of this method. + TimedeltaIndex.components : Return a DataFrame with components of + each Timedelta. Examples -------- + **Series** + >>> s = pd.Series(pd.to_timedelta(np.arange(5), unit='d')) >>> s 0 0 days @@ -520,6 +532,7 @@ def total_seconds(self): 3 3 days 4 4 days dtype: timedelta64[ns] + >>> s.dt.total_seconds() 0 0.0 1 86400.0 @@ -528,9 +541,16 @@ def total_seconds(self): 4 345600.0 dtype: float64 - See Also - -------- - datetime.timedelta.total_seconds + **TimedeltaIndex** + + >>> idx = pd.to_timedelta(np.arange(5), unit='d') + >>> idx + TimedeltaIndex(['0 days', '1 days', '2 days', '3 days', '4 days'], + dtype='timedelta64[ns]', freq=None) + + >>> idx.total_seconds() + Float64Index([0.0, 86400.0, 172800.0, 259200.00000000003, 345600.0], + dtype='float64') """ return Index(self._maybe_mask_results(1e-9 * self.asi8), name=self.name)