diff --git a/doc/source/whatsnew/v0.15.2.txt b/doc/source/whatsnew/v0.15.2.txt index 58dc1da214c05..5bd78ec6b439a 100644 --- a/doc/source/whatsnew/v0.15.2.txt +++ b/doc/source/whatsnew/v0.15.2.txt @@ -164,7 +164,7 @@ Bug Fixes - Bug in ``merge`` where ``how='left'`` and ``sort=False`` would not preserve left frame order (:issue:`7331`) - Fix: The font size was only set on x axis if vertical or the y axis if horizontal. (:issue:`8765`) - Fixed division by 0 when reading big csv files in python 3 (:issue:`8621`) - +- Fixed an unclear error message in ``qcut`` when repeated values result in duplicate bin edges. diff --git a/pandas/tools/tests/test_tile.py b/pandas/tools/tests/test_tile.py index 4a0218bef6001..c099ee787d2c9 100644 --- a/pandas/tools/tests/test_tile.py +++ b/pandas/tools/tests/test_tile.py @@ -153,7 +153,7 @@ def test_qcut_specify_quantiles(self): self.assertTrue(factor.equals(expected)) def test_qcut_all_bins_same(self): - assertRaisesRegexp(ValueError, "edges.*unique", qcut, [0,0,0,0,0,0,0,0,0,0], 3) + assertRaisesRegexp(ValueError, "quantiles.*repeated", qcut, [0,0,0,0,0,0,0,0,0,0], 3) def test_cut_out_of_bounds(self): arr = np.random.randn(100) diff --git a/pandas/tools/tile.py b/pandas/tools/tile.py index 6830919d9c09f..2f98f314c3afe 100644 --- a/pandas/tools/tile.py +++ b/pandas/tools/tile.py @@ -165,6 +165,10 @@ def qcut(x, q, labels=None, retbins=False, precision=3): else: quantiles = q bins = algos.quantile(x, quantiles) + if len(algos.unique(bins)) < len(bins): + bins_sorted = np.sort(bins, axis=None) + bins_dup = algos.unique(bins_sorted[bins_sorted[1:] == bins_sorted[:-1]]) + raise ValueError('One or more quantiles consists entirely of a repeated value: %s' % repr(bins_dup)) return _bins_to_cuts(x, bins, labels=labels, retbins=retbins,precision=precision, include_lowest=True)