def _reindex_output(self, result):
<EOL>groupings = self.grouper.groupings<EOL>if groupings is None:<EOL><INDENT>return result<EOL><DEDENT>elif len(groupings) == <NUM_LIT:1>:<EOL><INDENT>return result<EOL><DEDENT>elif self.observed:<EOL><INDENT>return result<EOL><DEDENT>elif not any(isinstance(ping.grouper, (Categorical, CategoricalIndex))<EOL>for ping in groupings):<EOL><INDENT>return result<EOL><DEDENT>levels_list = [ping.group_index for ping in groupings]<EOL>index, _ = MultiIndex.from_product(<EOL>levels_list, names=self.grouper.names).sortlevel()<EOL>if self.as_index:<EOL><INDENT>d = {self.obj._get_axis_name(self.axis): index, '<STR_LIT>': False}<EOL>return result.reindex(**d)<EOL><DEDENT>in_axis_grps = ((i, ping.name) for (i, ping)<EOL>in enumerate(groupings) if ping.in_axis)<EOL>g_nums, g_names = zip(*in_axis_grps)<EOL>result = result.drop(labels=list(g_names), axis=<NUM_LIT:1>)<EOL>result = result.set_index(self.grouper.result_index<EOL>).reindex(index, copy=False)<EOL>result = result.reset_index(level=g_nums)<EOL>return result.reset_index(drop=True)<EOL>
If we have categorical groupers, then we want to make sure that
we have a fully reindex-output to the levels. These may have not
participated in the groupings (e.g. may have all been
nan groups);

This can re-expand the output space