Skip to content

BUG: Fixed DataFrame.describe percentiles are ndarray w/ no median #14914

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

Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.20.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ Bug Fixes

- Bug in ``TimedeltaIndex`` addition where overflow was being allowed without error (:issue:`14816`)
- Bug in ``astype()`` where ``inf`` values were incorrectly converted to integers. Now raises error now with ``astype()`` for Series and DataFrames (:issue:`14265`)

- Bug in ``describe()`` when passing a numpy array which does not contain the median to the ``percentiles`` keyword argument (:issue:`14908`)



Expand Down
3 changes: 3 additions & 0 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -5262,6 +5262,9 @@ def describe(self, percentiles=None, include=None, exclude=None):
raise ValueError("Cannot describe a DataFrame without columns")

if percentiles is not None:
# explicit conversion of `percentiles` to list
percentiles = list(percentiles)

# get them all to be in [0, 1]
self._check_percentile(percentiles)

Expand Down
9 changes: 9 additions & 0 deletions pandas/tests/test_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,15 @@ def test_describe_percentiles_insert_median(self):
self.assertTrue('0%' in d1.index)
self.assertTrue('100%' in d2.index)

def test_describe_percentiles_insert_median_ndarray(self):
df = tm.makeDataFrame()
Copy link
Contributor

Choose a reason for hiding this comment

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

add the issue number here as a comment

try:
Copy link
Contributor

Choose a reason for hiding this comment

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

you don't need the try/except at all; nose will simply fail the test if this raises.

rename d1 -> result, d2 -> expected

d1 = df.describe(percentiles=np.array([.25, .75]))
except AttributeError:
self.fail
d2 = df.describe(percentiles=[.25, .75])
assert_frame_equal(d1, d2)

def test_describe_percentiles_unique(self):
# GH13104
df = tm.makeDataFrame()
Expand Down