Skip to content

Commit

Permalink
fix(rust, python): fix panic dynamic_groupby on empty dataframe
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Jan 18, 2023
1 parent 2df617e commit 8d96dd2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 26 deletions.
4 changes: 4 additions & 0 deletions polars/polars-time/src/groupby/dynamic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,10 @@ impl Wrap<&DataFrame> {
tu: TimeUnit,
time_type: &DataType,
) -> PolarsResult<(Series, Vec<Series>, GroupsProxy)> {
if dt.is_empty() {
return dt.cast(time_type).map(|s| (s, by, GroupsProxy::default()));
}

let w = Window::new(options.every, options.period, options.offset);
let dt = dt.datetime().unwrap();
let tz = dt.time_zone();
Expand Down
28 changes: 2 additions & 26 deletions py-polars/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions py-polars/tests/unit/test_rolling.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,3 +514,12 @@ def test_groupby_dynamic_by_monday_and_offset_5444() -> None:
],
"value": [4, 10, 2, 12],
}

# test empty
result_empty = (
df.filter(pl.col("date") == "z")
.groupby_dynamic("date", every="1w", offset="1d", by="label", start_by="monday")
.agg(pl.col("value").sum())
)
print(result_empty, result)
assert result_empty.schema == result.schema

0 comments on commit 8d96dd2

Please sign in to comment.