Skip to content

Commit

Permalink
throw error on empty keyed groupby (#3049)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Apr 3, 2022
1 parent 31e8b30 commit a5a5570
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions polars/polars-core/src/frame/groupby/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ impl DataFrame {
multithreaded: bool,
sorted: bool,
) -> Result<GroupBy> {
if by.is_empty() {
return Err(PolarsError::ComputeError(
"expected keys in groupby operation, got nothing".into(),
));
}

macro_rules! finish_packed_bit_path {
($ca0:expr, $ca1:expr, $pack_fn:expr) => {{
let n_partitions = set_partition_size();
Expand Down
10 changes: 10 additions & 0 deletions py-polars/tests/test_errors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import pytest

import polars as pl


def test_error_on_empty_groupby() -> None:
with pytest.raises(
pl.ComputeError, match="expected keys in groupby operation, got nothing"
):
pl.DataFrame(dict(x=[0, 0, 1, 1])).groupby([]).agg(pl.count())

0 comments on commit a5a5570

Please sign in to comment.