In [21]: dtidx = pd.date_range('2012-01-01', periods=2)
In [22]: dtidx
Out[22]:
<class 'pandas.tseries.index.DatetimeIndex'>
[2012-01-01, 2012-01-02]
Length: 2, Freq: D, Timezone: None
In [23]: dtidx + pd.Series([pd.Timedelta('10 days'), pd.Timedelta('20 days')])
Out[23]:
2012-01-01 00:00:00 NaT
2012-01-02 00:00:00 NaT
0 NaT
1 NaT
dtype: datetime64[ns]
Comment From: jreback
this is correct, its just 'misuse'. The dt index is aligning with the index of the series (which in an integer index) while odd, it is allowed. Then the addition happens, but since nothing aligns you get all NaT.
you can do this
In [14]: Series(dtidx) + s
Out[14]:
0 2012-01-11
1 2012-01-22
dtype: datetime64[ns]
[13]: dtidx + s.values
Out[13]:
<class 'pandas.tseries.index.DatetimeIndex'>
[2012-01-11, 2012-01-22]
Length: 2, Freq: D, Timezone: None
Comment From: jorisvandenbossche
ah, yes, of course, stupid of me, I forgot the basic pandas feature, alignment, ..
I tried to use Series
because an array or list did not work:
dtidx + [pd.Timedelta('10 days'), pd.Timedelta('20 days')]
dtidx + np.array([pd.Timedelta('10 days'), pd.Timedelta('20 days')])
But indeed, the s.values
approach works.