Skip to content

Commit

Permalink
fix div by zero (#3031)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Apr 1, 2022
1 parent b12a2e8 commit 524f8a5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion polars/polars-core/src/frame/groupby/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ impl DataFrame {

// arbitrarily chosen bound, if avg no of bytes to encode is larger than this
// value we fall back to default groupby
if (lhs.get_values_size() + rhs.get_values_size()) / lhs.len() < 128 {
if (lhs.get_values_size() + rhs.get_values_size()) / (lhs.len() + 1) < 128 {
pack_utf8_columns(lhs, rhs, n_partitions, sorted)
} else {
groupby_threaded_multiple_keys_flat(keys_df, n_partitions, sorted)
Expand Down
18 changes: 18 additions & 0 deletions polars/tests/it/lazy/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,21 @@ fn test_special_groupby_schemas() -> Result<()> {

Ok(())
}

#[test]
fn max_on_empty_df_3027() -> Result<()> {
let df = df! {
"id" => ["1"],
"name" => ["one"],
"numb" => [1]
}?
.head(Some(0));

let out = df
.lazy()
.groupby(&[col("id"), col("name")])
.agg(&[col("numb").max()])
.collect()?;
assert_eq!(out.shape(), (0, 3));
Ok(())
}

0 comments on commit 524f8a5

Please sign in to comment.