8000 fix: Do not allow inferring (`-1`) the dimension on any `Expr.reshape` dimension except the first by dsprenkels · Pull Request #24591 · pola-rs/polars · GitHub
[go: up one dir, main page]

Skip to content

Conversation

@dsprenk
8000
els
Copy link
Collaborator
@dsprenkels dsprenkels commented Sep 24, 2025

Related issue: #24536
Sibling PR: #24590

Cc @coastalwhite

Copy link
Collaborator
@coastalwhite coastalwhite left a comment

Choose a reason for hiding this comment

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

small nit.

}

let num_infers = dims.iter().filter(|d| matches!(d, ReshapeDimension::Infer)).count();
let infers = dims.iter().enumerate().filter(|(_, d)| matches!(d, ReshapeDimension::Infer)).collect::<Vec<_>>();
Copy link
Collaborator

Choose a reason for hiding this comment

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

By definition, if you cannot infer anything beyond the first dimension, you cannot infer more than 1 dimension. I think you can do an .any() on dims[1..].

@dsprenkels
Copy link
Collaborator Author

Addressed the nit, and also updated the docstring for Expr.reshape.

}

polars_ensure!(num_infers <= 1, InvalidOperation: "can only specify one inferred dimension");
let num_infers = dims
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this can now be usize::from(matches!(dims[0], ReshapeDimension::Infer)). But, in general, if we can just have a boolean here now saying infers_dimension as there is now only 1 dimension to infer.

@codecov
Copy link
codecov bot commented Sep 24, 2025

Codecov Report

❌ Patch coverage is 82.60870% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.81%. Comparing base (19d9b6d) to head (9c764bd).
⚠️ Report is 8 commits behind head on main.

Files with missing lines Patch % Lines
...olars-plan/src/plans/aexpr/function_expr/schema.rs 82.60% 12 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #24591      +/-   ##
==========================================
+ Coverage   81.79%   81.81%   +0.01%     
==========================================
  Files        1686     1686              
  Lines      229972   229985      +13     
  Branches     2974     2974              
==========================================
+ Hits       188107   188155      +48     
+ Misses      41112    41077      -35     
  Partials      753      753              

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@coastalwhite coastalwhite merged commit 23af416 into pola-rs:main Sep 24, 2025
29 checks passed
@dsprenkels dsprenkels deleted the reshape branch September 24, 2025 15:12
@eitsupi
Copy link
Contributor
eitsupi commented Sep 27, 2025

It still seems possible to create an expr with -1 in a dimension other than the first, so I'm wondering if it's worth checking the dimension in the reshape function.

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.

3 participants

0