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

perf: Optimize is_sorted for numeric data #16333

Merged
merged 5 commits into from
May 20, 2024
Merged

perf: Optimize is_sorted for numeric data #16333

merged 5 commits into from
May 20, 2024

Conversation

ritchie46
Copy link
Member

Should be much faster and failing fast in case of non-sorted data.

@github-actions github-actions bot added performance Performance issues or improvements python Related to Python Polars rust Related to Rust Polars labels May 20, 2024
Copy link
Member Author

@ritchie46 ritchie46 left a comment

Choose a reason for hiding this comment

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

@MarcoGorelli check comments FYI.

@@ -82,8 +82,9 @@ where
if ca.is_empty() {
return Ok(Series::new_empty(ca.name(), ca.dtype()));
}
let ca = ca.rechunk();
let by = by.rechunk();
if by.null_count() > 0 {
Copy link
Member Author

Choose a reason for hiding this comment

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

This could be factored out of branch and be checked before any compute (rechunking).

Comment on lines 85 to 87
if by.null_count() > 0 {
polars_bail!(InvalidOperation: "'Expr.rolling_*_by(...)' not yet supported for series with null values, consider using 'DataFrame.rolling' or 'Expr.rolling'")
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

this needs checking for ca too? looks like it's being removed from L107 but not replaced

Copy link
Collaborator

Choose a reason for hiding this comment

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

also, L114 can probably now just become

        let by_values = by.cont_slice().expect("`by` has already been rechunked and checked for null values");

?

likewise L137

Copy link
Member Author

Choose a reason for hiding this comment

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

It isn't I believe, but we should check that higher up indeed. 👍

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, it is. NVM.

Copy link

codecov bot commented May 20, 2024

Codecov Report

Attention: Patch coverage is 82.22222% with 16 lines in your changes are missing coverage. Please review.

Project coverage is 81.38%. Comparing base (b359a23) to head (f9d962b).

Current head f9d962b differs from pull request most recent head 284b456

Please upload reports for the commit 284b456 to get more accurate results.

Files Patch % Lines
crates/polars-ops/src/series/ops/various.rs 80.26% 15 Missing ⚠️
...s-time/src/chunkedarray/rolling_window/dispatch.rs 90.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #16333      +/-   ##
==========================================
+ Coverage   81.37%   81.38%   +0.01%     
==========================================
  Files        1403     1403              
  Lines      183691   183751      +60     
  Branches     2954     2954              
==========================================
+ Hits       149471   149548      +77     
+ Misses      33709    33692      -17     
  Partials      511      511              

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

@ritchie46 ritchie46 merged commit 49e116c into main May 20, 2024
26 checks passed
@ritchie46 ritchie46 deleted the sort branch May 20, 2024 10:49
@c-peters c-peters added the accepted Ready for implementation label May 21, 2024
Wouittone pushed a commit to Wouittone/polars that referenced this pull request Jun 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted Ready for implementation performance Performance issues or improvements python Related to Python Polars rust Related to Rust Polars
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

3 participants