Skip to content

Commit d79b767

Browse files
committed
Improved solution: using same approach as pd.cut
1 parent e24c53f commit d79b767

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

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)