Skip to content

ENH: Adding pipe operations to pandas.api.typing.Rolling instances #57076

@brianjburrow

Description

@brianjburrow

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 = 60*60*2 # 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.

image

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!

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions