Skip to content

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

Merged
merged 5 commits into from
Mar 11, 2020
Merged

BUG: Fix rolling functions with variable windows on decreasing index #32386

merged 5 commits into from
Mar 11, 2020

Conversation

leftys
Copy link
Contributor

@leftys leftys commented Mar 1, 2020

@leftys leftys changed the title Fix rolling functions on decreasing variable index Fix rolling functions with variable windows on decreasing index Mar 1, 2020
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
Copy link
Contributor Author

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).

@leftys leftys changed the title Fix rolling functions with variable windows on decreasing index BUG: Fix rolling functions with variable windows on decreasing index Mar 1, 2020
@jorisvandenbossche
Copy link
Member

cc @mroeschke are you familiar with this code?

I can confirm that indeed the current output (and tested behaviour) is wrong

@mroeschke
Copy link
Member

Only familiar from a refactor standpoint. I didn't write the original window bounds calculations.

@@ -44,6 +44,7 @@ def calculate_variable_window_bounds(
cdef:
bint left_closed = False
bint right_closed = False
int index_growth_sign = +1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 -> 1

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -58,6 +59,9 @@ def calculate_variable_window_bounds(
if closed in ['left', 'both']:
left_closed = True

if index[num_values-1] < index[0]:
Copy link
Member

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]

Copy link
Contributor Author

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))
Copy link
Member

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?

Copy link
Member

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)

Copy link
Contributor Author

@leftys leftys Mar 3, 2020

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.

@jorisvandenbossche jorisvandenbossche added this to the 1.0.2 milestone Mar 3, 2020
@jorisvandenbossche jorisvandenbossche added Bug Window rolling, ewma, expanding labels Mar 3, 2020
Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm. a question.

@TomAugspurger
Copy link
Contributor

@leftys can you respond to #32386 (review)? Trying to get 1.0.2 out soon.

@leftys
Copy link
Contributor Author

leftys commented Mar 9, 2020

@leftys can you respond to #32386 (review)? Trying to get 1.0.2 out soon.

@TomAugspurger done

@leftys leftys requested a review from jreback March 9, 2020 18:43
@jreback jreback merged commit 8bc471a into pandas-dev:master Mar 11, 2020
@jreback
Copy link
Contributor

jreback commented Mar 11, 2020

thanks @leftys very nice!

@jreback
Copy link
Contributor

jreback commented Mar 11, 2020

@meeseeksdev backport 1.0.x

meeseeksmachine pushed a commit to meeseeksmachine/pandas that referenced this pull request Mar 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Window rolling, ewma, expanding
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: Rolling functions doesn't work on decreasing variable index
6 participants