Skip to content

Commit

Permalink
fix: group_by multiple null columns produce phantom row (#15659)
Browse files Browse the repository at this point in the history
  • Loading branch information
reswqa authored Apr 15, 2024
1 parent b5b64c1 commit f992a7a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
7 changes: 6 additions & 1 deletion crates/polars-core/src/frame/group_by/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,13 @@ impl DataFrame {
.cloned()
.collect::<Vec<_>>();
if by.is_empty() {
let groups = if self.height() == 0 {
vec![]
} else {
vec![[0, self.height() as IdxSize]]
};
Ok(GroupsProxy::Slice {
groups: vec![[0, self.height() as IdxSize]],
groups,
rolling: false,
})
} else {
Expand Down
5 changes: 5 additions & 0 deletions py-polars/tests/unit/operations/test_group_by.py
Original file line number Diff line number Diff line change
Expand Up @@ -985,3 +985,8 @@ def test_aggregated_scalar_elementwise_15602() -> None:
)
expected = pl.DataFrame({"group": [1, 2], "foo": [[True, True], [True]]})
assert_frame_equal(out, expected)


def test_group_by_multiple_null_cols_15623() -> None:
df = pl.DataFrame(schema={"a": pl.Null, "b": pl.Null}).group_by(pl.all()).len()
assert df.is_empty()

0 comments on commit f992a7a

Please sign in to comment.