Skip to content

BUG: Fix rolling median and quantile with closed='left' and closed='neither' (#26005) #26910

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 6 commits into from
Jun 21, 2019

Conversation

ihsansecer
Copy link
Contributor

@ihsansecer ihsansecer commented Jun 17, 2019

Here is my understanding of how it should work:

*Same as test cases, there is one day between each element and window size is 3 days.

For closed='both' (() denotes Nth window and - is just to state window is out of ):

N=0 | (-, -, - [0), 1, 2, 3, 4, 5, 6, 7, 8, 9]
N=1 | -, (-, - [0, 1), 2, 3, 4, 5, 6, 7, 8, 9]
N=2 | -, -, (- [0, 1, 2), 3, 4, 5, 6, 7, 8, 9]
N=3 | -, -, - [(0, 1, 2, 3), 4, 5, 6, 7, 8, 9]
...

For closed='right':

N=0 | -, (-, - [0), 1, 2, 3, 4, 5, 6, 7, 8, 9]
N=1 | -, -, (- [0, 1), 2, 3, 4, 5, 6, 7, 8, 9]
N=2 | -, -, - [(0, 1, 2), 3, 4, 5, 6, 7, 8, 9]
N=3 | -, -, - [0, (1, 2, 3), 4, 5, 6, 7, 8, 9]
...

For closed='left':

N=0 | (-, -, -) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
N=1 | -, (-, - [0), 1, 2, 3, 4, 5, 6, 7, 8, 9]
N=2 | -, -, (- [0, 1), 2, 3, 4, 5, 6, 7, 8, 9]
N=3 | -, -, - [(0, 1, 2), 3, 4, 5, 6, 7, 8, 9]
...

For closed='neither':

N=0 | -, (-, -) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
N=1 | -, -, (- [0), 1, 2, 3, 4, 5, 6, 7, 8, 9]
N=2 | -, -, - [(0, 1), 2, 3, 4, 5, 6, 7, 8, 9]
N=3 | -, -, - [0, (1, 2), 3, 4, 5, 6, 7, 8, 9]
...

Adding the first element at setup produce incorrect results when closed option is left or neither. Instead iterating from first start to end at setup is a proper option same as in roll_mean
When a window is empty actual element in the order of window is removed from skiplist. But since it is added after removing it is never removed and remains in the skiplist. Instead removing after adding is a proper option
@TomAugspurger
Copy link
Contributor

Thank @ihsansecer. It looks like #26005 reported multiple issues. Do your changes fix the memory skiplist issues? If so, can you add tests / release note? Otherwise, edit the original post to remove the "closes", so that it remains open.

cc @WillAyd

@codecov
Copy link

codecov bot commented Jun 17, 2019

Codecov Report

Merging #26910 into master will decrease coverage by <.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #26910      +/-   ##
==========================================
- Coverage   91.97%   91.97%   -0.01%     
==========================================
  Files         180      180              
  Lines       50756    50760       +4     
==========================================
  Hits        46685    46685              
- Misses       4071     4075       +4
Flag Coverage Δ
#multiple 90.56% <ø> (ø) ⬆️
#single 41.82% <ø> (-0.09%) ⬇️
Impacted Files Coverage Δ
pandas/io/gbq.py 88.88% <0%> (-11.12%) ⬇️
pandas/core/frame.py 96.89% <0%> (-0.12%) ⬇️
pandas/core/internals/construction.py 95.95% <0%> (+0.02%) ⬆️
pandas/core/dtypes/cast.py 90.56% <0%> (+0.03%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b9b081d...51e89c4. Read the comment docs.

@ihsansecer
Copy link
Contributor Author

@TomAugspurger not yet checked issues with memory skiplist and max function but I am planning to have a look and open another PR. Thanks

@jreback jreback added the Reshaping Concat, Merge/Join, Stack/Unstack, Explode label Jun 19, 2019
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.

comments

@ihsansecer
Copy link
Contributor Author

It seems quantile is also producing unexpected results same as stated in the issue. If there is no problem with this fix I will apply the same to quantile function.

@jreback
Copy link
Contributor

jreback commented Jun 21, 2019

yep, can you merge master and push again here.

@jreback jreback added this to the 0.25.0 milestone Jun 21, 2019
@ihsansecer
Copy link
Contributor Author

@jreback Merged and changed roll_quantile as mentioned

@ihsansecer ihsansecer changed the title BUG: Fix rolling median with closed='left' and closed='neither' (#26005) BUG: Fix rolling median and quantile with closed='left' and closed='neither' (#26005) Jun 21, 2019
@jreback jreback merged commit 9088f5e into pandas-dev:master Jun 21, 2019
@jreback
Copy link
Contributor

jreback commented Jun 21, 2019

thanks @ihsansecer nice patch!

@ihsansecer ihsansecer deleted the fix-roll-median-closed branch July 11, 2019 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants