Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(python): change ignore_nulls default to False #13004

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion py-polars/polars/expr/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -8404,7 +8404,7 @@ def ewm_mean(
*,
adjust: bool = True,
min_periods: int = 1,
ignore_nulls: bool = True,
ignore_nulls: bool = False,
) -> Self:
r"""
Exponentially-weighted moving average.
Expand Down
2 changes: 1 addition & 1 deletion py-polars/polars/series/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -6365,7 +6365,7 @@ def ewm_mean(
*,
adjust: bool = True,
min_periods: int = 1,
ignore_nulls: bool = True,
ignore_nulls: bool = False,
) -> Series:
r"""
Exponentially-weighted moving average.
Expand Down
14 changes: 7 additions & 7 deletions py-polars/tests/unit/series/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -2275,29 +2275,29 @@ def test_ewm_mean_leading_nulls() -> None:
for min_periods in [1, 2, 3]:
assert (
pl.Series([1, 2, 3, 4])
.ewm_mean(com=3, min_periods=min_periods)
.ewm_mean(com=3, min_periods=min_periods, ignore_nulls=True)
.null_count()
== min_periods - 1
)
assert pl.Series([None, 1.0, 1.0, 1.0]).ewm_mean(
alpha=0.5, min_periods=1
alpha=0.5, min_periods=1, ignore_nulls=True
).to_list() == [None, 1.0, 1.0, 1.0]
assert pl.Series([None, 1.0, 1.0, 1.0]).ewm_mean(
alpha=0.5, min_periods=2
alpha=0.5, min_periods=2, ignore_nulls=True
).to_list() == [None, None, 1.0, 1.0]


def test_ewm_mean_min_periods() -> None:
series = pl.Series([1.0, None, None, None])

ewm_mean = series.ewm_mean(alpha=0.5, min_periods=1)
ewm_mean = series.ewm_mean(alpha=0.5, min_periods=1, ignore_nulls=True)
assert ewm_mean.to_list() == [1.0, 1.0, 1.0, 1.0]
ewm_mean = series.ewm_mean(alpha=0.5, min_periods=2)
ewm_mean = series.ewm_mean(alpha=0.5, min_periods=2, ignore_nulls=True)
assert ewm_mean.to_list() == [None, None, None, None]

series = pl.Series([1.0, None, 2.0, None, 3.0])

ewm_mean = series.ewm_mean(alpha=0.5, min_periods=1)
ewm_mean = series.ewm_mean(alpha=0.5, min_periods=1, ignore_nulls=True)
assert_series_equal(
ewm_mean,
pl.Series(
Expand All @@ -2310,7 +2310,7 @@ def test_ewm_mean_min_periods() -> None:
]
),
)
ewm_mean = series.ewm_mean(alpha=0.5, min_periods=2)
ewm_mean = series.ewm_mean(alpha=0.5, min_periods=2, ignore_nulls=True)
assert_series_equal(
ewm_mean,
pl.Series(
Expand Down