ENH: Adding pipe
operations to pandas.api.typing.Rolling
instances · Issue #57076 · pandas-dev/pandas (original) (raw)
Feature Type
- Adding new functionality to pandas
- Changing existing functionality in pandas
- Removing existing functionality in pandas
Problem Description
I wish I could use a pipe
method on a rolling
object for speeding up operations that require multiple vectorized (terminology?) operations on a rolling
object.
Feature Description
import pandas as pd import numpy as np n_samples = 60602 # 2 hours start_ts = pd.Timestamp("2022-01-01") end_ts = start_ts + pd.Timedelta(f"{n_samples}s") s = pd.Series( np.random.normal(0, 1, size=n_samples), index=pd.date_range(start_ts, end_ts, freq="1s", inclusive="left") ).rolling("1T").pipe(lambda r: r.std()/r.mean())
Alternative Solutions
I'm not aware of any.
Additional Context
Maybe a bit silly, but I've seen recommendation to used chained operations when possible. I tend to like the style, but I haven't figured out an easy way to do this particular operation without a performance hit.
I could be misinterpreting how pipe
actually works, but I think it might be equivalent to calc(r)
performance wise?
Thank you for taking a look!