def set_categories(self, new_categories, ordered=None, rename=False,<EOL>inplace=False):
inplace = validate_bool_kwarg(inplace, '<STR_LIT>')<EOL>if ordered is None:<EOL><INDENT>ordered = self.dtype.ordered<EOL><DEDENT>new_dtype = CategoricalDtype(new_categories, ordered=ordered)<EOL>cat = self if inplace else self.copy()<EOL>if rename:<EOL><INDENT>if (cat.dtype.categories is not None and<EOL>len(new_dtype.categories) < len(cat.dtype.categories)):<EOL><INDENT>cat._codes[cat._codes >= len(new_dtype.categories)] = -<NUM_LIT:1><EOL><DEDENT><DEDENT>else:<EOL><INDENT>codes = _recode_for_categories(cat.codes, cat.categories,<EOL>new_dtype.categories)<EOL>cat._codes = codes<EOL><DEDENT>cat._dtype = new_dtype<EOL>if not inplace:<EOL><INDENT>return cat<EOL><DEDENT>
Set the categories to the specified new_categories.

`new_categories` can include new categories (which will result in
unused categories) or remove old categories (which results in values
set to NaN). If `rename==True`, the categories will simple be renamed
(less or more items than in old categories will result in values set to
NaN or in unused categories respectively).

This method can be used to perform more than one action of adding,
removing, and reordering simultaneously and is therefore faster than
performing the individual steps via the more specialised methods.

On the other hand this methods does not do checks (e.g., whether the
old categories are included in the new categories on a reorder), which
can result in surprising changes, for example when using special string
dtypes on python3, which does not considers a S1 string equal to a
single char python string.

Parameters
----------
new_categories : Index-like
   The categories in new order.
ordered : bool, default False
   Whether or not the categorical is treated as a ordered categorical.
   If not given, do not change the ordered information.
rename : bool, default False
   Whether or not the new_categories should be considered as a rename
   of the old categories or as reordered categories.
inplace : bool, default False
   Whether or not to reorder the categories in-place or return a copy
   of this categorical with reordered categories.

Returns
-------
Categorical with reordered categories or None if inplace.

Raises
------
ValueError
    If new_categories does not validate as categories

See Also
--------
rename_categories
reorder_categories
add_categories
remove_categories
remove_unused_categories