def recode_from_groupby(c, sort, ci):
<EOL>if sort:<EOL><INDENT>return ci.set_categories(c.categories)<EOL><DEDENT>return ci.add_categories(<EOL>c.categories[~c.categories.isin(ci.categories)])<EOL>
Reverse the codes_to_groupby to account for sort / observed.

Parameters
----------
c : Categorical
sort : boolean
    The value of the sort parameter groupby was called with.
ci : CategoricalIndex
    The codes / categories to recode

Returns
-------
CategoricalIndex