Skip to content

Commit b1b230a

Browse files
committed
Improved solution: using same approach as pd.cut
1 parent 6c0b220 commit b1b230a

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

doc/source/whatsnew/v0.20.0.txt

-1
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,6 @@ Bug Fixes
593593
- Bug in ``Rolling.quantile`` function that caused a segmentation fault when called with a quantile value outside of the range [0, 1] (:issue:`15463`)
594594
- Bug in ``pd.cut()`` single bin on all 0s array raises ``ValueError`` (:issue:`15428`)
595595
- Bug in ``pd.qcut()`` single quantile and array with identical values raises ``ValueError`` (:issue:`15431`)
596-
597596
- Bug in the display of ``.info()`` where a qualifier (+) would always be displayed with a ``MultiIndex`` that contains only non-strings (:issue:`15245`)
598597
- Bug in ``pd.read_msgpack()`` in which ``Series`` categoricals were being improperly processed (:issue:`14901`)
599598
- Bug in ``Series.ffill()`` with mixed dtypes containing tz-aware datetimes. (:issue:`14956`)

pandas/tools/tile.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -185,14 +185,17 @@ def qcut(x, q, labels=None, retbins=False, precision=3, duplicates='raise'):
185185
x, dtype = _coerce_to_type(x)
186186

187187
if is_integer(q):
188-
quantiles = np.linspace(0, 1, q + 1)
188+
if x.size == 0:
189+
raise ValueError('Cannot qcut empty array')
189190

190-
if q == 1:
191+
rng = (nanops.nanmin(x), nanops.nanmax(x))
192+
if rng[0] == rng[1] and q == 1:
191193
duplicates = 'allow'
194+
195+
quantiles = np.linspace(0, 1, q + 1)
192196
else:
193197
quantiles = q
194198
bins = algos.quantile(x, quantiles)
195-
196199
fac, bins = _bins_to_cuts(x, bins, labels=labels,
197200
precision=precision, include_lowest=True,
198201
dtype=dtype, duplicates=duplicates)

0 commit comments

Comments
 (0)