Skip to content

Commit aff1f91

Browse files
committed
BUG: fixed wrong order of ordered labels in pd.cut()
1 parent a8a497f commit aff1f91

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

pandas/core/reshape/tile.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ def _bins_to_cuts(x, bins, right=True, labels=None,
252252
raise ValueError('Bin labels must be one fewer than '
253253
'the number of bin edges')
254254
if not is_categorical_dtype(labels):
255-
labels = Categorical(labels, ordered=True)
255+
labels = Categorical(labels, categories=labels, ordered=True)
256256

257257
np.putmask(ids, na_mask, 0)
258258
result = algos.take_nd(labels, ids - 1)

pandas/tests/reshape/test_tile.py

+1
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ def test_cut_pass_labels(self):
211211

212212
result = cut(arr, bins, labels=labels)
213213
exp = Categorical(['Medium'] + 4 * ['Small'] + ['Medium', 'Large'],
214+
categories=labels,
214215
ordered=True)
215216
tm.assert_categorical_equal(result, exp)
216217

0 commit comments

Comments
 (0)