Skip to content
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

feat: Allow for rolling_*_by to use index count as window #19071

Merged
merged 1 commit into from
Oct 3, 2024

Conversation

MarcoGorelli
Copy link
Collaborator

@MarcoGorelli MarcoGorelli commented Oct 2, 2024

example:

In [1]: import polars as pl
   ...: 
   ...: df = pl.DataFrame({"a": [1, 4, 2, 5]}).with_row_index()
   ...: print(df.with_columns(pl.col("a").rolling_sum_by("index", "2i")))
   ...: 
shape: (4, 2)
┌───────┬─────┐
│ indexa   │
│ ------ │
│ u32i64 │
╞═══════╪═════╡
│ 01   │
│ 15   │
│ 26   │
│ 37   │
└───────┴─────┘

which DataFrame.rolling already supports

It should be possible for both Expr.rolling_*_by and DataFrame.rolling to support Duration and Time too, but i'll keep that separate

@MarcoGorelli MarcoGorelli changed the title feat: allow for rolling_*_by to use index count as window feat: Allow for rolling_*_by to use index count as window Oct 2, 2024
@github-actions github-actions bot added enhancement New feature or an improvement of an existing feature python Related to Python Polars rust Related to Rust Polars and removed title needs formatting labels Oct 2, 2024
@MarcoGorelli MarcoGorelli marked this pull request as ready for review October 2, 2024 17:15
@ritchie46 ritchie46 merged commit a796300 into pola-rs:main Oct 3, 2024
27 checks passed
Copy link

codecov bot commented Oct 3, 2024

Codecov Report

Attention: Patch coverage is 50.00000% with 3 lines in your changes missing coverage. Please review.

Project coverage is 79.77%. Comparing base (eb615e0) to head (a0ed213).
Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
...s-time/src/chunkedarray/rolling_window/dispatch.rs 50.00% 3 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main   #19071   +/-   ##
=======================================
  Coverage   79.77%   79.77%           
=======================================
  Files        1531     1531           
  Lines      208500   208505    +5     
  Branches     2913     2913           
=======================================
+ Hits       166322   166326    +4     
- Misses      41627    41628    +1     
  Partials      551      551           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines +824 to +825
def test_rolling_by_integer(dtype: PolarsDataType) -> None:
df = pl.DataFrame({"val": [1, 2, 3]}).with_row_index()
Copy link
Contributor

@HansBambel HansBambel Oct 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am I missing something or is the parameterized dtype never used?

Shouldn't it be something like this:

df = pl.DataFrame({"val": [1, 2, 3]}, schema={"val": dtype}).with_row_index()

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @HansBambel , the intention was probably

df = pl.DataFrame({"val": [1, 2, 3]}).with_row_index().with_columns(pl.col('index').cast(dtype))

fancy making a pr to address this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MarcoGorelli I'll do that on the weekend at the latest!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Managed to do it now already: #19555

Local tests were failing because connectorx was missing even after running make requirements-all. Not sure why

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or an improvement of an existing feature python Related to Python Polars rust Related to Rust Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants