Skip to content

Commit eec9fee

Browse files
committed
1 parent c2da73c commit eec9fee

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

flox/core.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -429,15 +429,16 @@ def factorize_(
429429
elif isinstance(expect, pd.IntervalIndex):
430430
# when binning we change expected groups to integers marking the interval
431431
# 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
437434
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]]])
439439
# 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)
441442
else:
442443
if expect is not None and reindex:
443444
sorter = np.argsort(expect)

0 commit comments

Comments
 (0)