Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(rust, python): fix panic dynamic_groupby on empty dataframe #6294

Merged
merged 1 commit into from
Jan 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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