diff --git a/doc/source/whatsnew/v0.20.0.txt b/doc/source/whatsnew/v0.20.0.txt index 76ba4a5f723fa..e84c8beeadcc7 100644 --- a/doc/source/whatsnew/v0.20.0.txt +++ b/doc/source/whatsnew/v0.20.0.txt @@ -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`) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 48d799811aa94..3678168890444 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -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) diff --git a/pandas/tests/test_generic.py b/pandas/tests/test_generic.py index 84df82db69f77..3500ce913462a 100644 --- a/pandas/tests/test_generic.py +++ b/pandas/tests/test_generic.py @@ -996,6 +996,13 @@ 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): + # GH14908 + df = tm.makeDataFrame() + result = df.describe(percentiles=np.array([.25, .75])) + expected = df.describe(percentiles=[.25, .75]) + assert_frame_equal(result, expected) + def test_describe_percentiles_unique(self): # GH13104 df = tm.makeDataFrame()