Skip to content
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

Fixed describe.py #61024

Closed
wants to merge 14 commits into from
Closed

Conversation

Abhibhav2003
Copy link

Screenshot 2025-03-01 123317
Issue-60550-Fixed

Removed the condition that included 50th percentile. i.e.

if 0.5 not in percentiles :
percentiles.append(0.5)

Added the condition, that 50th percentile should only be appended if the list 'percentiles' is empty.

Issue-60550-Fixed
Copy link
Member

@rhshadrach rhshadrach left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! When changing the behavior of pandas, please always add tests.

Comment on lines 357 to 358
if percentiles == []:
percentiles.append(0.5) # By default, if percentiles is empty then append 50th percentile.
Copy link
Member

Choose a reason for hiding this comment

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

As mentioned in the linked issue, I think pandas should not be adding in 0.5 when the user specifies percentiles=[].

Copy link
Author

@Abhibhav2003 Abhibhav2003 Mar 1, 2025

Choose a reason for hiding this comment

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

As mentioned in the linked issue, I think pandas should not be adding in 0.5 when the user specifies percentiles=[].

I have removed the automatic addition of 0.5 when percentiles=[], as per the feedback.

Should percentiles=[] return an empty result, or should it raise an error?

Copy link
Member

Choose a reason for hiding this comment

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

percentiles=[] should produce a result without any percentiles in it. But the result itself will not be empty.

Copy link
Author

Choose a reason for hiding this comment

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

Done!
Added Tests as well!

import numpy as np

import pandas as pd

frame = pd.DataFrame(np.array([1, 2, 3, 4, 5, 100]))

print(frame.describe(percentiles=[]))

Here's the required Output :
image

print(frame.describe(percentiles=[0.25]))

Output :

image

removed the automatic addition of 0.5 when percentiles=[]
@Abhibhav2003 Abhibhav2003 requested a review from rhshadrach March 1, 2025 14:14
@Abhibhav2003 Abhibhav2003 reopened this Mar 2, 2025
@Abhibhav2003 Abhibhav2003 force-pushed the issue-60550-fix-v2 branch 2 times, most recently from bf704ac to ee5ff56 Compare March 9, 2025 01:24
@Abhibhav2003 Abhibhav2003 deleted the issue-60550-fix-v2 branch March 9, 2025 01:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants