-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Fix rolling functions with variable windows on decreasing index #32386
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
BUG: Fix rolling functions with variable windows on decreasing index #32386
Conversation
expected = DataFrame( | ||
{"column": [3.0, 3.0, 3.0, 2.0, 1.0]}, index=reversed(index) | ||
{"column": [3.0, 3.0, 4.0, 4.0, 6.0]}, index=index |
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.
The original expected value was wrong: #28297 (comment).
… index and update tests CLN: black reformatting
cc @mroeschke are you familiar with this code? I can confirm that indeed the current output (and tested behaviour) is wrong |
Only familiar from a refactor standpoint. I didn't write the original window bounds calculations. |
pandas/_libs/window/indexers.pyx
Outdated
@@ -44,6 +44,7 @@ def calculate_variable_window_bounds( | |||
cdef: | |||
bint left_closed = False | |||
bint right_closed = False | |||
int index_growth_sign = +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.
+1
-> 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.
done
pandas/_libs/window/indexers.pyx
Outdated
@@ -58,6 +59,9 @@ def calculate_variable_window_bounds( | |||
if closed in ['left', 'both']: | |||
left_closed = True | |||
|
|||
if index[num_values-1] < index[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.
index[num_values-1]
-> index[num_values - 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.
done
] | ||
|
||
df = DataFrame({"column": [3, 4, 4, 2, 1]}, index=reversed(index)) |
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.
Wouldn't this have been working previously with a decreasing index?
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.
Not fully sure what the question is, but: on 0.25 we raised an error for decreasing index. For 1.0, rolling with a decreasing index was enabled, but gave wrong output (see eg #32385 for what the output of this should actually be)
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.
v1.0 would return [3,3,3,2,1] for this case. The rolling window covered the whole series.
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.
lgtm. a question.
@leftys can you respond to #32386 (review)? Trying to get 1.0.2 out soon. |
@TomAugspurger done |
thanks @leftys very nice! |
@meeseeksdev backport 1.0.x |
…e windows on decreasing index
…on decreasing index (#32606) Co-authored-by: Jan Škoda <[email protected]>
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff