diff --git a/pandas/core/groupby.py b/pandas/core/groupby.py index 442f2132847ee..377f758926899 100644 --- a/pandas/core/groupby.py +++ b/pandas/core/groupby.py @@ -2790,6 +2790,10 @@ def true_and_notnull(x, *args, **kwargs): def nunique(self, dropna=True): """ Returns number of unique elements in the group """ ids, _, _ = self.grouper.group_info + + if len(ids) == 0: # bugfix for 12553 + return Series([]) + val = self.obj.get_values() try: