-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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: Return null instead of 0. for rolling_std when window contains a single element and ddof=1 and there are nulls elsewhere in the Series #20077
Conversation
if count == T::zero() { | ||
if denom <= T::zero() { | ||
None | ||
} else if count == T::one() { | ||
NumCast::from(0) | ||
Some(T::zero()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
like this it matches what's done for the no_nulls/variance.rs
kernel
polars/crates/polars-arrow/src/legacy/kernels/rolling/no_nulls/variance.rs
Lines 121 to 125 in b618734
let denom = count - NumCast::from(self.ddof).unwrap(); | |
if denom <= T::zero() { | |
None | |
} else if end - start == 1 { | |
Some(T::zero()) |
… single element and ddof=1 and there are nulls elsewhere in the Series
2de6564
to
1afd302
Compare
assert_eq!(out, &[0.0, 0.0, 2.0, 12.5]); | ||
assert_eq!(out, &[None, None, Some(2.0), Some(12.5)]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here the original series is [1, null, -1, 4]
, and the operation is rolling variance with window of 3 and min_periods 1 and ddof=1
So the windows are:
- [1]
- [1, null]
- [1, null, -1]
- [null, -1, 4]
and so it's correct that the first two need to output None
, as they only have a single valid value and ddof=1:
In [50]: print(pl.Series([1]).std())
None
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #20077 +/- ##
=======================================
Coverage 79.52% 79.53%
=======================================
Files 1563 1563
Lines 217124 217115 -9
Branches 2464 2464
=======================================
+ Hits 172674 172677 +3
+ Misses 43890 43878 -12
Partials 560 560 ☔ View full report in Codecov by Sentry. |
… single element and ddof=1 and there are nulls elsewhere in the Series (pola-rs#20077)
closes #20076