Skip to content

Commit

Permalink
depr(python): Deprecate non-keyword args for ewm methods (#11804)
Browse files Browse the repository at this point in the history
  • Loading branch information
stinodego authored Oct 17, 2023
1 parent f63014e commit d85c452
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
4 changes: 3 additions & 1 deletion py-polars/polars/expr/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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]})
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
15 changes: 15 additions & 0 deletions py-polars/polars/series/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -6567,6 +6581,7 @@ def ewm_std(
"""

@deprecate_nonkeyword_arguments(version="0.19.10")
def ewm_var(
self,
com: float | None = None,
Expand Down
4 changes: 3 additions & 1 deletion py-polars/tests/unit/series/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit d85c452

Please sign in to comment.