Skip to content

Commit 692503a

Browse files
committed
Improved solution: using same approach as pd.cut
1 parent b7d92dc commit 692503a

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

doc/source/whatsnew/v0.20.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,7 @@ Bug Fixes
677677

678678

679679

680+
680681
- Bug in the display of ``.info()`` where a qualifier (+) would always be displayed with a ``MultiIndex`` that contains only non-strings (:issue:`15245`)
681682

682683
- Bug in ``.asfreq()``, where frequency was not set for empty ``Series` (:issue:`14320`)

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)