Skip to content

BUG: fix groupby.quantile inconsistency when interpolation='nearest' #56926

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 4 commits into from
Jan 18, 2024

Conversation

yuanx749
Copy link
Contributor

@yuanx749 yuanx749 commented Jan 17, 2024

I removed the xfail mark in previous tests. Do we need to add more tests?
Under the hood, np.quantile uses np.round for nearest interpolation, which rounds to the even idx when exactly halfway.

@yuanx749 yuanx749 requested a review from WillAyd as a code owner January 17, 2024 11:48
@@ -1286,7 +1286,7 @@ def group_quantile(
elif interp == INTERPOLATION_MIDPOINT:
out[i, k] = (val + next_val) / 2.0
elif interp == INTERPOLATION_NEAREST:
if frac > .5 or (frac == .5 and q_val > .5): # Always OK?
if frac > .5 or (frac == .5 and idx % 2 == 1): # Always OK?
Copy link
Member

Choose a reason for hiding this comment

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

Could you replace # Always OK? with a short comment above what idx % 2 == 1 is for?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a comment.

@mroeschke mroeschke added Groupby quantile quantile method labels Jan 17, 2024
@mroeschke mroeschke added this to the 3.0 milestone Jan 18, 2024
@mroeschke mroeschke merged commit dd29be7 into pandas-dev:main Jan 18, 2024
@mroeschke
Copy link
Member

Thanks @yuanx749

@yuanx749 yuanx749 deleted the groupby.quantile branch January 19, 2024 04:18
pmhatre1 pushed a commit to pmhatre1/pandas-pmhatre1 that referenced this pull request May 7, 2024
pandas-dev#56926)

* BUG: fix groupby.quantile inconsistency when interpolation='nearest'

* add whatsnew

* Add comment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Groupby quantile quantile method
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: Resampler.quantile produce inconsistent results when interpolation='nearest' and q=0.5
2 participants