File tree 1 file changed +8
-7
lines changed
1 file changed +8
-7
lines changed Original file line number Diff line number Diff line change @@ -429,15 +429,16 @@ def factorize_(
429
429
elif isinstance (expect , pd .IntervalIndex ):
430
430
# when binning we change expected groups to integers marking the interval
431
431
# this makes the reindexing logic simpler.
432
- if expect is None :
433
- raise ValueError ("Please pass bin edges in expected_groups." )
434
- # TODO: fix for binning
435
- found_groups .append (expect )
436
- # pd.cut with bins = IntervalIndex[datetime64] doesn't work...
432
+ if expect .closed == "both" :
433
+ raise NotImplementedError
437
434
if groupvar .dtype .kind == "M" :
438
- expect = np .concatenate ([expect .left .to_numpy (), [expect .right [- 1 ].to_numpy ()]])
435
+ # pd.cut with bins = IntervalIndex[datetime64] doesn't work...
436
+ bins = np .concatenate ([expect .left .to_numpy (), [expect .right [- 1 ].to_numpy ()]])
437
+ else :
438
+ bins = np .concatenate ([expect .left .to_numpy (), [expect .right [- 1 ]]])
439
439
# code is -1 for values outside the bounds of all intervals
440
- idx = pd .cut (flat , bins = expect ).codes .copy ()
440
+ idx = pd .cut (flat , bins = bins , right = expect .closed_right ).codes .copy ()
441
+ found_groups .append (expect )
441
442
else :
442
443
if expect is not None and reindex :
443
444
sorter = np .argsort (expect )
You can’t perform that action at this time.
0 commit comments