Skip to content

Commit 8e630b6

Browse files
pbreachjreback
authored andcommitted
BUG: Fixed DataFrame.describe percentiles are ndarray w/ no median
Explicit conversion to list for `percentiles`. Fixes the case where `percentiles` is passed as a numpy with no median (0.5) present. Closes pandas-dev#14908. Author: pbreach <[email protected]> Closes pandas-dev#14914 from pbreach/df-describe-percentile-ndarray-no-median and squashes the following commits: 5c8199b [pbreach] Minor test fix b5d09a6 [pbreach] Added test for median insertion with ndarray 72fe0cb [pbreach] Added what's new entry f954392 [pbreach] Moved conversion to if percentiles is not None d192ac7 [pbreach] Fixed whitespace issue a06794d [pbreach] BUG: Fixed bug in DataFrame.describe when percentiles are passed as array with no median
1 parent f11501a commit 8e630b6

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

doc/source/whatsnew/v0.20.0.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ Bug Fixes
245245
- Bug in ``TimedeltaIndex`` addition where overflow was being allowed without error (:issue:`14816`)
246246
- Bug in ``DataFrame`` construction in which unsigned 64-bit integer elements were being converted to objects (:issue:`14881`)
247247
- Bug in ``astype()`` where ``inf`` values were incorrectly converted to integers. Now raises error now with ``astype()`` for Series and DataFrames (:issue:`14265`)
248-
248+
- Bug in ``describe()`` when passing a numpy array which does not contain the median to the ``percentiles`` keyword argument (:issue:`14908`)
249249

250250

251251

pandas/core/generic.py

+3
Original file line numberDiff line numberDiff line change
@@ -5262,6 +5262,9 @@ def describe(self, percentiles=None, include=None, exclude=None):
52625262
raise ValueError("Cannot describe a DataFrame without columns")
52635263

52645264
if percentiles is not None:
5265+
# explicit conversion of `percentiles` to list
5266+
percentiles = list(percentiles)
5267+
52655268
# get them all to be in [0, 1]
52665269
self._check_percentile(percentiles)
52675270

pandas/tests/test_generic.py

+7
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,13 @@ def test_describe_percentiles_insert_median(self):
996996
self.assertTrue('0%' in d1.index)
997997
self.assertTrue('100%' in d2.index)
998998

999+
def test_describe_percentiles_insert_median_ndarray(self):
1000+
# GH14908
1001+
df = tm.makeDataFrame()
1002+
result = df.describe(percentiles=np.array([.25, .75]))
1003+
expected = df.describe(percentiles=[.25, .75])
1004+
assert_frame_equal(result, expected)
1005+
9991006
def test_describe_percentiles_unique(self):
10001007
# GH13104
10011008
df = tm.makeDataFrame()

0 commit comments

Comments
 (0)