@@ -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,17 +394,19 @@ 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
+ if self .labels is None :
398
+ dummy , _ = self ._cut (np .array ([0 ]).astype (group .dtype ))
399
+ full_index = dummy .categories
400
+ else :
401
+ full_index = pd .CategoricalIndex (self .labels )
402
+
399
403
if not by_is_chunked :
400
404
uniques = np .sort (pd .unique (codes .data .ravel ()))
401
405
unique_values = full_index [uniques [uniques != - 1 ]]
402
406
else :
403
407
unique_values = full_index
404
408
405
- unique_coord = Variable (
406
- dims = new_dim_name , data = unique_values , attrs = group .attrs
407
- )
409
+ unique_coord = Variable (dims = self .name , data = unique_values , attrs = group .attrs )
408
410
return EncodedGroups (
409
411
codes = codes ,
410
412
full_index = full_index ,
0 commit comments