Skip to content

Commit 1d69334

Browse files
committed
BUG: make construction of labels can handle empty periods(pandas-dev#28479)
1 parent 3f0e816 commit 1d69334

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

pandas/core/groupby/generic.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import copy
1010
import functools
1111
from functools import partial
12+
import itertools
1213
from textwrap import dedent
1314
import typing
1415
from typing import Any, Callable, FrozenSet, Iterator, Sequence, Type, Union
@@ -1264,9 +1265,12 @@ def value_counts(
12641265

12651266
# num. of times each group should be repeated
12661267
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)]
1268+
1269+
#multi-index components
1270+
try:
1271+
labels = list(map(rep, self.grouper.recons_labels )) + [llab(lab, inc)]
1272+
except ValueError:
1273+
labels = list(map(rep, [[k for k, _ in itertools.groupby(ids)]])) + [llab(lab, inc)]
12701274
levels = [ping.group_index for ping in self.grouper.groupings] + [lev]
12711275
names = self.grouper.names + [self._selection_name]
12721276

0 commit comments

Comments
 (0)