API: rolling.apply will pass Series to function by jreback · Pull Request #20584 · pandas-dev/pandas (original) (raw)
While trying this out, I also noticed that rolling apply only seems to work on numeric (int/float) data. Is this a known limitation/bug? (didn't directly find an issue about it):
In [69]: s = pd.Series(list('abcd'))
In [71]: s.rolling(2).apply(lambda x: x+1, raw=True)
Out[71]:
0 a #<-------- for string data, just returns the original series, whathever the function is
1 b
2 c
3 d
dtype: object
In [72]: s = pd.Series(pd.Categorical(list('abcd')))
In [73]: s.rolling(2).apply(lambda x: x+1, raw=True) Out[73]: [a, b, c, d] #<-------- for categorical data, just returns the original Categorical (not even series) Categories (4, object): [a, b, c, d]
In [74]: s = pd.Series(pd.timedelta_range("1 days", periods=4))
In [75]: s.rolling(2).apply(lambda x: x+1, raw=True) #<----- for timedelta/datetime, raises informative error ... NotImplementedError: ops for Rolling for this dtype timedelta64[ns] are not implemented
(this is a separate issue as this PR, it's already like this in released version)