From 97eabbd262ecb8df2e7b48d82c18251ecde98186 Mon Sep 17 00:00:00 2001 From: Shenyang Cai Date: Fri, 17 Oct 2025 23:50:05 +0000 Subject: [PATCH] feat: add median() for window rolling --- bigframes/core/window/rolling.py | 3 +++ tests/system/small/test_window.py | 2 ++ third_party/bigframes_vendored/pandas/core/window/rolling.py | 4 ++++ 3 files changed, 9 insertions(+) diff --git a/bigframes/core/window/rolling.py b/bigframes/core/window/rolling.py index 1f3466874f..8e7848e25f 100644 --- a/bigframes/core/window/rolling.py +++ b/bigframes/core/window/rolling.py @@ -59,6 +59,9 @@ def sum(self): def mean(self): return self._apply_aggregate(agg_ops.mean_op) + + def median(self): + return self._apply_aggregate(agg_ops.median_op) def var(self): return self._apply_aggregate(agg_ops.var_op) diff --git a/tests/system/small/test_window.py b/tests/system/small/test_window.py index b48bb8bc86..c8f1cf31e7 100644 --- a/tests/system/small/test_window.py +++ b/tests/system/small/test_window.py @@ -175,6 +175,7 @@ def test_series_groupby_rolling_closed_param(rows_rolling_series, closed): pytest.param(lambda x: x.min(), id="min"), pytest.param(lambda x: x.max(), id="max"), pytest.param(lambda x: x.mean(), id="mean"), + pytest.param(lambda x: x.median(), id="median"), pytest.param(lambda x: x.count(), id="count"), pytest.param(lambda x: x.std(), id="std"), pytest.param(lambda x: x.var(), id="var"), @@ -210,6 +211,7 @@ def test_series_window_agg_ops(rows_rolling_series, windowing, agg_op): pytest.param(lambda x: x.min(), id="min"), pytest.param(lambda x: x.max(), id="max"), pytest.param(lambda x: x.mean(), id="mean"), + pytest.param(lambda x: x.median(), id="median"), pytest.param(lambda x: x.count(), id="count"), pytest.param(lambda x: x.std(), id="std"), pytest.param(lambda x: x.var(), id="var"), diff --git a/third_party/bigframes_vendored/pandas/core/window/rolling.py b/third_party/bigframes_vendored/pandas/core/window/rolling.py index a869c86e72..781e3bed37 100644 --- a/third_party/bigframes_vendored/pandas/core/window/rolling.py +++ b/third_party/bigframes_vendored/pandas/core/window/rolling.py @@ -21,6 +21,10 @@ def sum(self): def mean(self): """Calculate the weighted window mean.""" raise NotImplementedError(constants.ABSTRACT_METHOD_ERROR_MESSAGE) + + def median(self): + """Calculate the rolling median.""" + raise NotImplementedError(constants.ABSTRACT_METHOD_ERROR_MESSAGE) def var(self): """Calculate the weighted window variance."""