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

fix: Fix Expr.over with order_by did not take effect if group keys were sorted #18947

Merged
merged 5 commits into from
Sep 27, 2024

Conversation

nameexhaustion
Copy link
Collaborator

@nameexhaustion nameexhaustion commented Sep 26, 2024

Fixes #18943

@github-actions github-actions bot added fix Bug fix python Related to Python Polars rust Related to Rust Polars labels Sep 26, 2024
.over([col("cars")])
.explode()
Copy link
Collaborator Author

@nameexhaustion nameexhaustion Sep 27, 2024

Choose a reason for hiding this comment

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

This query internally created a DataFrame of height 5 containing a list[_] type column of length 2 (the imploded aggregation result), which it then exploded 🤯 out to the correct height, where the correctness of the result was guaranteed because the DataFrame was sorted beforehand 😂

@@ -334,13 +333,8 @@ impl WindowExpr {
// no explicit aggregations, map over the groups
//`(col("x").sum() * col("y")).over("groups")`
(WindowMapping::GroupsToRows, AggState::AggregatedList(_)) => {
if sorted_keys {
if let GroupsProxy::Idx(g) = gb.get_groups() {
debug_assert!(g.is_sorted_flag())
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

GroupsProxy::Idx must be explicitly mapped back to the row positions regardless of whether it was sorted

Copy link

codecov bot commented Sep 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 79.87%. Comparing base (71a8b05) to head (ccc9580).
Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #18947      +/-   ##
==========================================
- Coverage   79.88%   79.87%   -0.02%     
==========================================
  Files        1522     1522              
  Lines      206958   206954       -4     
  Branches     2906     2906              
==========================================
- Hits       165322   165297      -25     
- Misses      41088    41109      +21     
  Partials      548      548              

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

@ritchie46 ritchie46 merged commit e2c7150 into pola-rs:main Sep 27, 2024
27 checks passed
@nameexhaustion nameexhaustion deleted the over-order-by branch September 27, 2024 08:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix Bug fix python Related to Python Polars rust Related to Rust Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

order_by in over is incorrect when grouping column is marked as sorted
2 participants