Skip to content

Commit

Permalink
fix[rust]: ewm_mean leading nulls function (#4465)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Aug 17, 2022
1 parent 90f2f51 commit 828a69a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions polars/polars-core/src/series/ops/ewm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ fn prepare_primitive_array<T: NativeType>(
let leading = std::cmp::max(min_periods, leading_nulls);
if leading > 1 {
let mut validity = MutableBitmap::with_capacity(vals.len());
validity.extend_constant(min_periods, false);
validity.extend_constant(vals.len() - min_periods, true);
validity.extend_constant(min_periods - 1, false);
validity.extend_constant(vals.len() - (min_periods - 1), true);

PrimitiveArray::from_data_default(vals.into(), Some(validity.into()))
} else {
Expand Down
8 changes: 8 additions & 0 deletions py-polars/tests/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -1619,6 +1619,14 @@ 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()
== min_periods - 1
)


def test_ewm_std_var() -> None:
a = pl.Series("a", [2, 5, 3])

Expand Down

0 comments on commit 828a69a

Please sign in to comment.