I see
In[2]: pandas.tslib.Timedelta.total_seconds(pandas.NaT)
Out[2]: -9223372036.854776
Expected Output
Out[2]: nan
Output of pd.show_versions()
:
Comment From: jreback
pls check with 0.19.1
Comment From: jondo
Sorry, I don' have 0.19.1 around yet. Can somebody else please test?
Possible workarounds are pandas.NaT / numpy.timedelta64(1, 's')
, or pandas.Series.dt.total_seconds for timedelta series.
Comment From: jorisvandenbossche
It's the same on 0.19.1 / master
@jondo The more canonical way is rather:
In [10]: pd.Timedelta(pd.NaT)
Out[10]: NaT
In [11]: pd.Timedelta(pd.NaT).total_seconds()
Out[11]: nan
(and this one is correct), or indeed if you have a series of such values, by using s.dt.total_seconds()
Comment From: jreback
odd that total_sexonds can take an argument (or even be called as a class method)
Comment From: jorisvandenbossche
Yep, this is like that in the datetime.timedelta
class (although I personally don't see the value in using it like that), but I would have expected that we override that method in the pandas Timedelta class
Comment From: jorisvandenbossche
The total_seconds
is defined as
class Timedelta(..):
....
def total_seconds(self):
"""
Total duration of timedelta in seconds (to ns precision)
"""
return 1e-9 *self.value
so if you do pd.Timedelta.total_seconds(pd.NaT)
, it will just check pd.NaT.value
, and hence the output. This could be easily solved by checking for NaT in this method. But as it is not really the intended usage (self can in principle never be NaT), I would personally close this as a "won't fix"
Comment From: jondo
I'd also be OK with "won't fix". @jorisvandenbossche, thank you for showing the canonical way.