From d85c452e50ec0c6b0c929a3392cb51bea575df04 Mon Sep 17 00:00:00 2001 From: Stijn de Gooijer Date: Tue, 17 Oct 2023 15:01:34 +0200 Subject: [PATCH] depr(python): Deprecate non-keyword args for `ewm` methods (#11804) --- py-polars/polars/expr/expr.py | 4 +++- py-polars/polars/series/series.py | 15 +++++++++++++++ py-polars/tests/unit/series/test_series.py | 4 +++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/py-polars/polars/expr/expr.py b/py-polars/polars/expr/expr.py index 6d365764afef..608cb0db4840 100644 --- a/py-polars/polars/expr/expr.py +++ b/py-polars/polars/expr/expr.py @@ -8300,6 +8300,7 @@ def sample( self._pyexpr.sample_n(n, with_replacement, shuffle, seed) ) + @deprecate_nonkeyword_arguments(version="0.19.10") def ewm_mean( self, com: float | None = None, @@ -8367,7 +8368,6 @@ def ewm_mean( :math:`1-\alpha` and :math:`1` if ``adjust=True``, and :math:`1-\alpha` and :math:`\alpha` if ``adjust=False``. - Examples -------- >>> df = pl.DataFrame({"a": [1, 2, 3]}) @@ -8389,6 +8389,7 @@ def ewm_mean( self._pyexpr.ewm_mean(alpha, adjust, min_periods, ignore_nulls) ) + @deprecate_nonkeyword_arguments(version="0.19.10") def ewm_std( self, com: float | None = None, @@ -8481,6 +8482,7 @@ def ewm_std( self._pyexpr.ewm_std(alpha, adjust, bias, min_periods, ignore_nulls) ) + @deprecate_nonkeyword_arguments(version="0.19.10") def ewm_var( self, com: float | None = None, diff --git a/py-polars/polars/series/series.py b/py-polars/polars/series/series.py index e23036041fe7..14572ca9480f 100644 --- a/py-polars/polars/series/series.py +++ b/py-polars/polars/series/series.py @@ -6413,6 +6413,7 @@ def shuffle(self, seed: int | None = None) -> Series: """ + @deprecate_nonkeyword_arguments(version="0.19.10") def ewm_mean( self, com: float | None = None, @@ -6480,8 +6481,21 @@ def ewm_mean( :math:`1-\alpha` and :math:`1` if ``adjust=True``, and :math:`1-\alpha` and :math:`\alpha` if ``adjust=False``. + Examples + -------- + >>> s = pl.Series([1, 2, 3]) + >>> s.ewm_mean(com=1) + shape: (3,) + Series: '' [f64] + [ + 1.0 + 1.666667 + 2.428571 + ] + """ + @deprecate_nonkeyword_arguments(version="0.19.10") def ewm_std( self, com: float | None = None, @@ -6567,6 +6581,7 @@ def ewm_std( """ + @deprecate_nonkeyword_arguments(version="0.19.10") def ewm_var( self, com: float | None = None, diff --git a/py-polars/tests/unit/series/test_series.py b/py-polars/tests/unit/series/test_series.py index 3fab208b1131..54ba6288e2fa 100644 --- a/py-polars/tests/unit/series/test_series.py +++ b/py-polars/tests/unit/series/test_series.py @@ -2136,7 +2136,9 @@ def test_ewm_mean() -> None: def test_ewm_mean_leading_nulls() -> None: for min_periods in [1, 2, 3]: assert ( - pl.Series([1, 2, 3, 4]).ewm_mean(3, min_periods=min_periods).null_count() + pl.Series([1, 2, 3, 4]) + .ewm_mean(com=3, min_periods=min_periods) + .null_count() == min_periods - 1 ) assert pl.Series([None, 1.0, 1.0, 1.0]).ewm_mean(