File tree 1 file changed +8
-6
lines changed
1 file changed +8
-6
lines changed Original file line number Diff line number Diff line change @@ -383,6 +383,10 @@ def _bins_to_cuts(
383
383
):
384
384
if not ordered and not labels :
385
385
raise ValueError ("'labels' must be provided if 'ordered = False'" )
386
+ if ordered and len (set (labels )) != len (labels ):
387
+ raise ValueError (
388
+ "labels must be unique if ordered=True; pass ordered=False for duplicate labels" # noqa
389
+ )
386
390
387
391
if duplicates not in ["raise" , "drop" ]:
388
392
raise ValueError (
@@ -431,13 +435,11 @@ def _bins_to_cuts(
431
435
raise ValueError (
432
436
"Bin labels must be one fewer than the number of bin edges"
433
437
)
434
-
435
438
if not is_categorical_dtype (labels ):
436
- if len (set (labels )) == len (labels ):
437
- labels = Categorical (labels , categories = labels , ordered = ordered )
438
- else :
439
- labels = Categorical (labels , ordered = ordered )
440
-
439
+ labels = Categorical (
440
+ labels , categories = labels if ordered else None , ordered = ordered
441
+ )
442
+ # TODO: handle mismach between categorical label order and pandas.cut order.
441
443
np .putmask (ids , na_mask , 0 )
442
444
result = algos .take_nd (labels , ids - 1 )
443
445
You can’t perform that action at this time.
0 commit comments