Skip to content

Commit

Permalink
fix: Fix rolling on empty DataFrame panicking
Browse files Browse the repository at this point in the history
  • Loading branch information
lukemanley committed Feb 1, 2025
1 parent 98ccb09 commit 471f1db
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions crates/polars-time/src/windows/group_by.rs
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,10 @@ pub fn group_by_values(
tu: TimeUnit,
tz: Option<Tz>,
) -> PolarsResult<GroupsSlice> {
if time.is_empty() {
return Ok(GroupsSlice::from(vec![]));
}

let mut thread_offsets = _split_offsets(time.len(), POOL.current_num_threads());
// there are duplicates in the splits, so we opt for a single partition
prune_splits_on_duplicates(time, &mut thread_offsets);
Expand Down
14 changes: 14 additions & 0 deletions py-polars/tests/unit/operations/rolling/test_rolling.py
Original file line number Diff line number Diff line change
Expand Up @@ -1260,3 +1260,17 @@ def test_window_size_validation() -> None:

with pytest.raises(OverflowError, match=r"can't convert negative int to unsigned"):
df.with_columns(trailing_min=pl.col("x").rolling_min(window_size=-3))


def test_rolling_empty_21032() -> None:
df = pl.DataFrame(schema={"a": pl.Datetime("ms"), "b": pl.Int64()})

result = df.rolling(index_column="a", period=timedelta(days=2)).agg(
pl.col("b").sum()
)
assert_frame_equal(result, df)

result = df.rolling(
index_column="a", period=timedelta(days=2), offset=timedelta(days=3)
).agg(pl.col("b").sum())
assert_frame_equal(result, df)

0 comments on commit 471f1db

Please sign in to comment.