Skip to content

Commit

Permalink
fix oob in sorted groupby (#3681)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Jun 13, 2022
1 parent 1bb528b commit 0b6cdf5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions polars/polars-core/src/frame/groupby/into_groups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ where
eprintln!("groupby keys are sorted; running sorted key fast path");
}
let arr = self.downcast_iter().next().unwrap();
if arr.is_empty() {
return GroupsSlice::default();
}
let mut values = arr.values().as_slice();
let null_count = arr.null_count();

Expand Down
17 changes: 17 additions & 0 deletions py-polars/tests/test_groupby.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import polars as pl


def test_groupby_sorted_empty_dataframe_3680() -> None:
assert (
pl.DataFrame(
[
pl.Series("key", [], dtype=pl.Categorical),
pl.Series("val", [], dtype=pl.Float64),
]
)
.lazy()
.sort("key")
.groupby("key")
.tail(1)
.collect()
).shape == (0, 2)

0 comments on commit 0b6cdf5

Please sign in to comment.