Skip to content

Commit 13d1062

Browse files
authored
Small cleanup in factorize (#220)
1 parent b1687b7 commit 13d1062

File tree

1 file changed

+2
-14
lines changed

1 file changed

+2
-14
lines changed

flox/core.py

+2-14
Original file line numberDiff line numberDiff line change
@@ -523,31 +523,19 @@ def factorize_(
523523
idx[idx > expect[-1]] = -1
524524

525525
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.
530526
if expect.closed == "both":
531527
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]]])
540529

541530
# 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:
543532
if len(bins) > 1:
544533
right = expect.closed_right
545534
idx = np.digitize(
546535
flat,
547536
bins=bins.view(np.intp) if bins.dtype.kind == "M" else bins,
548537
right=right,
549538
)
550-
# idx = pd.to_numeric(idx, downcast="integer")
551539
idx -= 1
552540
within_bins = flat <= bins.max() if right else flat < bins.max()
553541
idx[~within_bins] = -1

0 commit comments

Comments
 (0)