Repository navigation
BUG: return NaN from move_std and move_var when ddof >= count - #613
Open
raashish1601 wants to merge 1 commit into
Open
raashish1601 wants to merge 1 commit into
raashish1601 wants to merge 1 commit into
Conversation
Author
|
The pre-commit.ci failure is zizmor flagging |
When the number of values in the window was not larger than ddof, the moving variance divided by zero or a negative number, giving inf, -0.0 or negative variances. Return NaN instead, like nanvar and the slow reference implementation.
neutrinoceros
force-pushed
the
fix/move-var-ddof
branch
from
October 19, 2026 17:02
5296324 to
38fb06d
Compare
Collaborator
|
Thanks for finding and fixing this. |
neutrinoceros
force-pushed
the
fix/move-var-ddof
branch
from
October 19, 2026 17:15
38fb06d to
bd21fe8
Compare
neutrinoceros
self-requested a review
October 19, 2026 17:42
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
move_stdandmove_vardon't check that the number of values in the window is larger thanddof. When it isn't, they divide by zero or by a negative number, so you getinf,-0.0, or a negative variance:nanvar/nanstdalready return NaN whencount <= ddof, and so does the slow reference (np.nanvar). This adds the same check to both the float and the integer code paths of the moving functions.Added
test_move_std_var_ddof_ge_count, which compares againstbn.slowfor float32/float64/int32/int64 andddoffrom 0 up towindow + 1. For integer input it compares against the float result, becausenp.vargivesinfthere whilebn.nanvargives NaN. The test fails on master and passes with this change. I ran the full test suite (216 passed, 1 xfailed) after building in apython:3.12Docker image, plusruff format --checkandruff check.