pd.to_timedelta(single_string) returns a Series, which ruins broadcasting. · Issue #5410 · pandas-dev/pandas (original) (raw)
Currently
In [10]: pd.to_timedelta(Series(['00:03:37', '00:05:05'])) - pd.to_timedelta('00:03:00')
Out[10]:
0 00:00:37
1 NaT
dtype: timedelta64[ns]
because
In [13]: pd.to_timedelta('00:03:00')
Out[13]:
0 00:03:00
dtype: timedelta64[ns]
More expected and consistent behavior, in my opinion, would be
In [12]: pd.to_timedelta(Series(['00:03:37', '00:05:05'])) - pd.to_timedelta('00:03:00')
Out[12]:
0 00:00:37
1 00:02:05
dtype: timedelta64[ns]
If, instead, pd.to_timedelta('00:03:00')
gave numpy.timedelta64(180000000000,'ns')
, it would broadcast properly, as demonstrated by this work-around
In [12]: pd.to_timedelta(Series(['00:03:37', '00:05:05'])) - pd.to_timedelta('00:03:00')[0]
Out[12]:
0 00:00:37
1 00:02:05
dtype: timedelta64[ns]
I have not regularly used timedeltas until now. Am I misjudging the expected usage?
Update, OK, one can also get the expected result by setting box=False
. But box=False
should be default for a scalar, no?