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: 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

Merged
merged 1 commit into from
Dec 2, 2024

Conversation

MarcoGorelli
Copy link
Collaborator

closes #20076

@github-actions github-actions bot added fix Bug fix python Related to Python Polars rust Related to Rust Polars labels Nov 30, 2024
Comment on lines -181 to +184
if count == T::zero() {
if denom <= T::zero() {
None
} else if count == T::one() {
NumCast::from(0)
Some(T::zero())
Copy link
Collaborator Author

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

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
Comment on lines -176 to +173
assert_eq!(out, &[0.0, 0.0, 2.0, 12.5]);
assert_eq!(out, &[None, None, Some(2.0), Some(12.5)]);
Copy link
Collaborator Author

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

Copy link

codecov bot commented Nov 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 79.53%. Comparing base (954000c) to head (1afd302).
Report is 10 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

@ritchie46 ritchie46 merged commit 58f763a into pola-rs:main Dec 2, 2024
25 checks passed
nimit pushed a commit to nimit/polars that referenced this pull request Dec 2, 2024
… single element and ddof=1 and there are nulls elsewhere in the Series (pola-rs#20077)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix Bug fix python Related to Python Polars rust Related to Rust Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug: rolling_std with nulls shows 0 for single-element (instead of null)
2 participants