Path: blob/main/py-polars/tests/unit/functions/test_cumulative_eval.py
6939 views
import pytest12import polars as pl3from polars.testing import assert_frame_equal456def test_cumulative_eval_sum() -> None:7assert_frame_equal(8pl.DataFrame({"a": [1, 2, 3]}).with_columns(9b=pl.col.a.cumulative_eval(pl.element().sum())10),11pl.DataFrame({"a": [1, 2, 3], "b": [1, 3, 6]}),12)131415def test_cumulative_eval_group_by() -> None:16assert_frame_equal(17pl.DataFrame({"a": [1, 2, 3, 2, 3, 4, 3], "g": [1, 1, 1, 2, 2, 2, 3]})18.group_by("g")19.agg(b=pl.col.a.cumulative_eval(pl.element().sum())),20pl.DataFrame({"g": [1, 2, 3], "b": [[1, 3, 6], [2, 5, 9], [3]]}),21check_row_order=False,22)232425def test_cumulative_eval_deny_non_scalar() -> None:26with pytest.raises(pl.exceptions.InvalidOperationError, match="scalar"):27(28pl.DataFrame({"a": [1, 2, 3]}).with_columns(29b=pl.col.a.cumulative_eval(pl.element() + 1)30),31)323334