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 incorrect top-k by sorted column, fix head() returning extra rows #20722

Merged
merged 6 commits into from
Jan 15, 2025

Conversation

nameexhaustion
Copy link
Collaborator

@nameexhaustion nameexhaustion commented Jan 15, 2025

Fixes #20719

Fixes #20712

Fixes #20715

Changelog
  • Removes a descending parameter from SortOptions.limit - it is duplicated with the top-level descending config
  • Fixes an issue where top_k on sorted data containing duplicates returned incorrect values (the duplicated rows were ignored):
pl.DataFrame({"a": [1, 2, 2]}).sort("a", descending=True).top_k(2, by="a")
# Before
shape: (2, 1)
┌─────┐
│ a   │
│ --- │
│ i64 │
╞═════╡
│ 2   │
│ 1   │
└─────┘
# After
shape: (2, 1)
┌─────┐
│ a   │
│ --- │
│ i64 │
╞═════╡
│ 2   │
│ 2   │
└─────┘

@github-actions github-actions bot added fix Bug fix python Related to Python Polars rust Related to Rust Polars labels Jan 15, 2025
@nameexhaustion nameexhaustion changed the title fix: Fix incorrect top-k for sorted column fix: Fix incorrect top-k for sorted column, and/or columns with duplicates Jan 15, 2025
@nameexhaustion nameexhaustion changed the title fix: Fix incorrect top-k for sorted column, and/or columns with duplicates fix: Fix incorrect top-k by sorted column, and/or columns with duplicates Jan 15, 2025
Copy link

codecov bot commented Jan 15, 2025

Codecov Report

Attention: Patch coverage is 66.66667% with 2 lines in your changes missing coverage. Please review.

Project coverage is 79.84%. Comparing base (1cd72ff) to head (acebf96).
Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
...polars-core/src/chunked_array/ops/sort/arg_sort.rs 75.00% 1 Missing ⚠️
crates/polars-core/src/frame/column/mod.rs 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #20722      +/-   ##
==========================================
- Coverage   79.92%   79.84%   -0.08%     
==========================================
  Files        1559     1560       +1     
  Lines      221181   221396     +215     
  Branches     2530     2530              
==========================================
+ Hits       176774   176779       +5     
- Misses      43825    44035     +210     
  Partials      582      582              

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

if let Some((0, k)) = slice {
if k < self.len() {
let desc = if sort_options.descending.len() == 1 {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Issue was this desc parameter, I've removed it

@nameexhaustion nameexhaustion changed the title fix: Fix incorrect top-k by sorted column, and/or columns with duplicates fix: Fix incorrect top-k by sorted column, fix head() returning extra rows Jan 15, 2025
@nameexhaustion nameexhaustion marked this pull request as ready for review January 15, 2025 09:59
@ritchie46 ritchie46 merged commit 417dd44 into pola-rs:main Jan 15, 2025
33 checks passed
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
2 participants