API: Series/DTIndex arithmetic with timedeltas and offsets should work the same · Issue #4134 · pandas-dev/pandas (original) (raw)
from stack: http://stackoverflow.com/questions/17491446/wrong-result-from-timedelta-operation/17492653#17492653
In [101]: rng = pd.date_range('2013', '2014')
In [102]: rng
Out[102]:
<class 'pandas.tseries.index.DatetimeIndex'>
[2013-07-05 00:00:00, ..., 2014-07-05 00:00:00]
Length: 366, Freq: D, Timezone: None
In [103]: s = pd.Series(rng)
These work
In [105]: rng - pd.offsets.Hour(1)
Out[105]:
<class 'pandas.tseries.index.DatetimeIndex'>
[2013-07-04 23:00:00, ..., 2014-07-04 23:00:00]
Length: 366, Freq: D, Timezone: None
In [106]: s - np.timedelta64(100000000)
but the other way around doesn't.
In [107]: rng - np.timedelta64(100000000)
NotImplementedError:
In [108]: s - pd.offsets.Hour(1)
ValueError: cannot operate on a series with out a rhs of a series/ndarray of type datetime64[ns] or a timedelta
cc #3009.