def _set_categories(self, categories, fastpath=False):
if fastpath:<EOL><INDENT>new_dtype = CategoricalDtype._from_fastpath(categories,<EOL>self.ordered)<EOL><DEDENT>else:<EOL><INDENT>new_dtype = CategoricalDtype(categories, ordered=self.ordered)<EOL><DEDENT>if (not fastpath and self.dtype.categories is not None and<EOL>len(new_dtype.categories) != len(self.dtype.categories)):<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>self._dtype = new_dtype<EOL>
Sets new categories inplace

Parameters
----------
fastpath : bool, default False
   Don't perform validation of the categories for uniqueness or nulls

Examples
--------
>>> c = pd.Categorical(['a', 'b'])
>>> c
[a, b]
Categories (2, object): [a, b]

>>> c._set_categories(pd.Index(['a', 'c']))
>>> c
[a, c]
Categories (2, object): [a, c]