File tree 1 file changed +10
-3
lines changed
1 file changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -1264,9 +1264,16 @@ def value_counts(
1264
1264
1265
1265
# num. of times each group should be repeated
1266
1266
rep = partial (np .repeat , repeats = np .add .reduceat (inc , idx ))
1267
-
1268
- # multi-index components
1269
- labels = list (map (rep , self .grouper .recons_labels )) + [llab (lab , inc )]
1267
+
1268
+ #multi-index components
1269
+ try :
1270
+ labels = list (map (rep , self .grouper .recons_labels )) + [llab (lab , inc )]
1271
+ except ValueError :
1272
+ # If applying rep to recons_labels go fail, use ids which has no
1273
+ # consecutive duplicates instead.
1274
+ _ids_idx = np .ones (len (ids ), dtype = bool )
1275
+ _ids_idx [1 :] = ids [1 :] != ids [:- 1 ]
1276
+ labels = list (map (rep , [ids [_ids_idx ]])) + [llab (lab , inc )]
1270
1277
levels = [ping .group_index for ping in self .grouper .groupings ] + [lev ]
1271
1278
names = self .grouper .names + [self ._selection_name ]
1272
1279
You can’t perform that action at this time.
0 commit comments