Skip to content

Commit

Permalink
fix: use use pytest.approx to compare float in rolling_skew test (#4300)
Browse files Browse the repository at this point in the history
  • Loading branch information
gaoxinge committed Aug 8, 2022
1 parent 6d08df0 commit 9fcf4ac
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 20 deletions.
2 changes: 1 addition & 1 deletion polars/polars-arrow/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub fn combine_validities(opt_l: Option<&Bitmap>, opt_r: Option<&Bitmap>) -> Opt
match (opt_l, opt_r) {
(Some(l), Some(r)) => Some(l.bitand(r)),
(None, Some(r)) => Some(r.clone()),
(Some(l), None) => (Some(l.clone())),
(Some(l), None) => Some(l.clone()),
(None, None) => None,
}
}
Expand Down
2 changes: 1 addition & 1 deletion polars/polars-core/src/series/ops/moment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl Series {

if !bias {
let n = self.len() as f64;
Ok(Some(((n - 1.0) * n).sqrt() / (n - 2.0) * m3 / m2.powf(1.5)))
Ok(Some(((n - 1.0) * n).sqrt() / (n - 2.0) * out))
} else {
Ok(Some(out))
}
Expand Down
42 changes: 24 additions & 18 deletions py-polars/tests/test_rolling.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from datetime import datetime
from typing import TYPE_CHECKING

import pytest

import polars as pl

if TYPE_CHECKING:
Expand Down Expand Up @@ -57,22 +59,26 @@ def test_rolling_kernels_and_groupby_rolling() -> None:

def test_rolling_skew() -> None:
s = pl.Series([1, 2, 3, 3, 2, 10, 8])
assert s.rolling_skew(window_size=4, bias=True).to_list() == [
None,
None,
None,
-0.49338220021815865,
0.0,
1.097025449363867,
0.09770939201338157,
]
assert s.rolling_skew(window_size=4, bias=True).to_list() == pytest.approx(
[
None,
None,
None,
-0.49338220021815865,
0.0,
1.097025449363867,
0.09770939201338157,
]
)

assert s.rolling_skew(window_size=4, bias=False).to_list() == [
None,
None,
None,
-0.8545630383279711,
0.0,
1.9001038154942962,
0.16923763134384154,
]
assert s.rolling_skew(window_size=4, bias=False).to_list() == pytest.approx(
[
None,
None,
None,
-0.8545630383279711,
0.0,
1.9001038154942962,
0.16923763134384154,
]
)

0 comments on commit 9fcf4ac

Please sign in to comment.