@@ -319,7 +319,7 @@ class BinGrouper(Grouper):
319319 the resulting bins. If False, returns only integer indicators of the
320320 bins. This affects the type of the output container (see below).
321321 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.
323323 retbins : bool, default False
324324 Whether to return the bins or not. Useful when bins is provided
325325 as a scalar.
@@ -394,8 +394,13 @@ def factorize(self, group: T_Group) -> EncodedGroups:
394394
395395 # This seems silly, but it lets us have Pandas handle the complexity
396396 # 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+
399404 if not by_is_chunked :
400405 uniques = np .sort (pd .unique (codes .data .ravel ()))
401406 unique_values = full_index [uniques [uniques != - 1 ]]
0 commit comments