Skip to content

Commit

Permalink
fix: `rolling_*_by was throwing incorrect error when dataframe was so…
Browse files Browse the repository at this point in the history
…rted by contained multiple chunks (pola-rs#16247)
  • Loading branch information
MarcoGorelli authored and Wouittone committed Jun 22, 2024
1 parent 04be1dc commit 5b401e4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ where
return Ok(Series::new_empty(ca.name(), ca.dtype()));
}
let ca = ca.rechunk();
let by = by.rechunk();
ensure_duration_matches_data_type(options.window_size, by.dtype(), "window_size")?;
polars_ensure!(!options.window_size.is_zero() && !options.window_size.negative, InvalidOperation: "`window_size` must be strictly positive");
if by.is_sorted_flag() != IsSorted::Ascending && options.warn_if_unsorted {
Expand Down
13 changes: 13 additions & 0 deletions py-polars/tests/unit/operations/rolling/test_rolling.py
Original file line number Diff line number Diff line change
Expand Up @@ -1021,6 +1021,19 @@ def test_temporal_windows_size_without_by_15977() -> None:
df.select(pl.col("a").rolling_mean("3d"))


def test_incorrect_nulls_16246() -> None:
df = pl.concat(
[
pl.DataFrame({"a": [datetime(2020, 1, 1)], "b": [1]}),
pl.DataFrame({"a": [datetime(2021, 1, 1)], "b": [1]}),
],
rechunk=False,
)
result = df.select(pl.col("b").rolling_max_by("a", "1d"))
expected = pl.DataFrame({"b": [1, 1]})
assert_frame_equal(result, expected)


def interval_defs() -> SearchStrategy[ClosedInterval]:
closed: list[ClosedInterval] = ["left", "right", "both", "none"]
return st.sampled_from(closed)
Expand Down

0 comments on commit 5b401e4

Please sign in to comment.