BUG: asfreq / pct_change strange behavior · Issue #7292 · pandas-dev/pandas (original) (raw)

In the first case, is it a bug (those NaNs at the end) or a feature? I just don't get the reason behind this behavior:

In[5]: s = Series(range(10), date_range('2014', periods=10, freq='H'))
In[6]: s
Out[6]: 
2014-05-31 00:00:00    0
2014-05-31 01:00:00    1
2014-05-31 02:00:00    2
2014-05-31 03:00:00    3
2014-05-31 04:00:00    4
2014-05-31 05:00:00    5
2014-05-31 06:00:00    6
2014-05-31 07:00:00    7
2014-05-31 08:00:00    8
2014-05-31 09:00:00    9
Freq: H, dtype: int64
In[7]: s.pct_change(periods=1, freq='5H')
Out[7]: 
2014-05-31 00:00:00         NaN
2014-05-31 01:00:00         NaN
2014-05-31 02:00:00         NaN
2014-05-31 03:00:00         NaN
2014-05-31 04:00:00         NaN
2014-05-31 05:00:00         inf
2014-05-31 06:00:00    5.000000
2014-05-31 07:00:00    2.500000
2014-05-31 08:00:00    1.666667
2014-05-31 09:00:00    1.250000
2014-05-31 10:00:00         NaN
2014-05-31 11:00:00         NaN
2014-05-31 12:00:00         NaN
2014-05-31 13:00:00         NaN
2014-05-31 14:00:00         NaN
dtype: float64

but this seems ok:

In[8]: s.pct_change(periods=5)
Out[8]: 
2014-05-31 00:00:00         NaN
2014-05-31 01:00:00         NaN
2014-05-31 02:00:00         NaN
2014-05-31 03:00:00         NaN
2014-05-31 04:00:00         NaN
2014-05-31 05:00:00         inf
2014-05-31 06:00:00    5.000000
2014-05-31 07:00:00    2.500000
2014-05-31 08:00:00    1.666667
2014-05-31 09:00:00    1.250000
Freq: H, dtype: float64