-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
BUG: Mitigate division with zero in roll_var #42459
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
Conversation
benHeid
commented
Jul 9, 2021
- closes BUG: Grouped Rolling Var and Std does not work with closed="left" #42442
- tests added / passed
- Ensure all linting tests pass, see here for how to run them
- whatsnew entry
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.
pls add tests that replicate this (e.g. use your example), they should fail w/o the change and pass with it
if nobs[0]: | ||
mean_x[0] = mean_x[0] + delta / nobs[0] | ||
else: | ||
mean_x[0] = 0 |
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.
why is this zero? and not NaN
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.
I assume that if nobs is zero a new group starts, so I reset mean_x to zero. Analog to the initialization of mean_x in roll_var (compare with the initalization in line 349). However, I am not sure if this is correct.
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.
Off the top of my head, this would also need testing when min_periods
is 0
or len(array)
as well to check if this is correct
cc @mroeschke |
Take a look at as well as the tests in |
I added a parameterized test with different min_periods and windows. |
pandas/tests/window/test_groupby.py
Outdated
@@ -275,8 +273,8 @@ def test_groupby_rolling_center_on(self): | |||
) | |||
result = ( | |||
df.groupby("gb") | |||
.rolling(6, on="Date", center=True, min_periods=1) | |||
.value.mean() | |||
.rolling(6, on="Date", center=True, min_periods=1) |
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.
can you not change unrelated things
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.
pls don't apply your settings otherwise this will not pass pre-commit.
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.
Sorry. I removed the autoformatted changes..
there are still some precommit issues here |
@github-actions pre-commit |
can you add a release note in 1.4 bug fix section (under rolling) |
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.
Looks good thanks. Just needs a whatnew note.
thanks @benHeid |