From 344fb861d659c73184a6604e31f6897d83636d52 Mon Sep 17 00:00:00 2001 From: Edward Date: Sat, 6 Dec 2014 15:23:31 -0800 Subject: [PATCH 1/3] Calling qcut with too many duplicates now gives an informative error message. Closes #7751 --- pandas/tools/tile.py | 4 ++++ 1 file changed, 4 insertions(+) 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) From b176ac965dae1881f5a4cb456f4d1e23c0dc2375 Mon Sep 17 00:00:00 2001 From: Edward Date: Sat, 6 Dec 2014 16:38:02 -0800 Subject: [PATCH 2/3] updated tests and docs --- doc/source/whatsnew/v0.15.2.txt | 2 +- pandas/tools/tests/test_tile.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/source/whatsnew/v0.15.2.txt b/doc/source/whatsnew/v0.15.2.txt index 58dc1da214c05..cd7c466434742 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) From 0e177896e438344a0b628fa893a36122a6f0846b Mon Sep 17 00:00:00 2001 From: Edward Date: Sat, 6 Dec 2014 16:41:51 -0800 Subject: [PATCH 3/3] fixed small formatting mistake --- doc/source/whatsnew/v0.15.2.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.15.2.txt b/doc/source/whatsnew/v0.15.2.txt index cd7c466434742..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 +- Fixed an unclear error message in ``qcut`` when repeated values result in duplicate bin edges.