@@ -523,31 +523,19 @@ def factorize_(
523
523
idx [idx > expect [- 1 ]] = - 1
524
524
525
525
elif isinstance (expect , pd .IntervalIndex ):
526
- # when binning we change expected groups to integers marking the interval
527
- # this makes the reindexing logic simpler.
528
- # workaround for https://github.com/pandas-dev/pandas/issues/47614
529
- # we create breaks and pass that to pd.cut, disallow closed="both" for now.
530
526
if expect .closed == "both" :
531
527
raise NotImplementedError
532
- if groupvar .dtype .kind == "M" :
533
- # pd.cut with bins = IntervalIndex[datetime64] doesn't work...
534
- bins = np .concatenate ([expect .left .to_numpy (), [expect .right [- 1 ].to_numpy ()]])
535
- else :
536
- bins = np .concatenate ([expect .left .to_numpy (), [expect .right [- 1 ]]])
537
-
538
- # code is -1 for values outside the bounds of all intervals
539
- # idx = pd.cut(flat, bins=bins, right=expect.closed_right).codes.copy()
528
+ bins = np .concatenate ([expect .left .to_numpy (), expect .right .to_numpy ()[[- 1 ]]])
540
529
541
530
# digitize is 0 or idx.max() for values outside the bounds of all intervals
542
- # make it behave like pd.cut:
531
+ # make it behave like pd.cut which uses -1 :
543
532
if len (bins ) > 1 :
544
533
right = expect .closed_right
545
534
idx = np .digitize (
546
535
flat ,
547
536
bins = bins .view (np .intp ) if bins .dtype .kind == "M" else bins ,
548
537
right = right ,
549
538
)
550
- # idx = pd.to_numeric(idx, downcast="integer")
551
539
idx -= 1
552
540
within_bins = flat <= bins .max () if right else flat < bins .max ()
553
541
idx [~ within_bins ] = - 1
0 commit comments