Description
Is your feature request related to a problem?
Rolling windows API is not coherent to scipy.signal
API.
Describe the solution you'd like
Support for weighted rolling window functions in pandas
is based on scipy.signal
. Precisely, pandas
uses scipy.signal.get_window
in order to get weights for a specific window specification. The issue is that scipy
allows more accurate window specification. Namely, one can use non-symetric exponential window as following.
scipy.signal.windows.exponential(window_size, sym=False)
Moreover, pandas
API specification requires paramter tau
what is not necesaray in fact. So, API could be even simpler.
A possible solution to use win_type
in order togetattrib
of scipy.signal.windows
module. If there is a function named as win_type
then pandas
should invoke the function with all passed paramters to aggregation function over rolling window. In the snippet below, .sum()
implies invocation of scipy.signal.windows.exponential(2, sym=False)
.
df = pd.DataFrame({'B': [0, 1, 2, np.nan, 4]})
df.rolling(2, win_type='exponential').sum(sym=True)
API breaking implications
API won't be broken. However, I would like to relax some contraints. Namely, aggregations over rolling window should be calculated without explicit window parameter specification.
Describe alternatives you've considered
Alternative solution looks like the following. It is simple and a bit verbose.
window = sp.signal.windows.exponential(2, sym=False)
df.rolling(2, min_periods=2) \
.apply(lambda x: (x * window).sum())