diff --git a/pandas/core/indexes/multi.py b/pandas/core/indexes/multi.py index f94d012b3aa03..ea4d95f848ce8 100644 --- a/pandas/core/indexes/multi.py +++ b/pandas/core/indexes/multi.py @@ -1266,10 +1266,10 @@ def _get_grouper_for_level(self, mapper, level): # Remove unobserved levels from level_index level_index = level_index.take(uniques) - if len(level_index): - grouper = level_index.take(codes) - else: + if level_index._can_hold_na: grouper = level_index.take(codes, fill_value=True) + else: + grouper = level_index.take(codes) return grouper, codes, level_index