@@ -319,7 +319,7 @@ class BinGrouper(Grouper):
319
319
the resulting bins. If False, returns only integer indicators of the
320
320
bins. This affects the type of the output container (see below).
321
321
This argument is ignored when `bins` is an IntervalIndex. If True,
322
- raises an error. When `ordered=False`, labels must be provided.
322
+ raises an error.
323
323
retbins : bool, default False
324
324
Whether to return the bins or not. Useful when bins is provided
325
325
as a scalar.
@@ -394,8 +394,13 @@ def factorize(self, group: T_Group) -> EncodedGroups:
394
394
395
395
# This seems silly, but it lets us have Pandas handle the complexity
396
396
# of `labels`, `precision`, and `include_lowest`, even when group is a chunked array
397
- dummy , _ = self ._cut (np .array ([0 ]).astype (group .dtype ))
398
- full_index = dummy .categories
397
+ # Pandas ignores labels when IntervalIndex is passed
398
+ if not isinstance (self .bins , pd .IntervalIndex ):
399
+ dummy , _ = self ._cut (np .array ([0 ]).astype (group .dtype ))
400
+ full_index = dummy .categories
401
+ else :
402
+ full_index = pd .Index (self .labels )
403
+
399
404
if not by_is_chunked :
400
405
uniques = np .sort (pd .unique (codes .data .ravel ()))
401
406
unique_values = full_index [uniques [uniques != - 1 ]]
0 commit comments