Skip to content

ENH: Rolling Calculations Ignore Extended Window Specification #34556

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
daskol opened this issue Jun 3, 2020 · 0 comments · Fixed by #37204
Closed

ENH: Rolling Calculations Ignore Extended Window Specification #34556

daskol opened this issue Jun 3, 2020 · 0 comments · Fixed by #37204
Labels
Enhancement Window rolling, ewma, expanding
Milestone

Comments

@daskol
Copy link

daskol commented Jun 3, 2020

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())
@daskol daskol added Enhancement Needs Triage Issue that has not been reviewed by a pandas team member labels Jun 3, 2020
@jbrockmendel jbrockmendel added Window rolling, ewma, expanding and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Sep 3, 2020
@jreback jreback added this to the 1.2 milestone Oct 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Window rolling, ewma, expanding
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants