def _recode_for_categories(codes, old_categories, new_categories):
from pandas.core.algorithms import take_1d<EOL>if len(old_categories) == <NUM_LIT:0>:<EOL><INDENT>return codes.copy()<EOL><DEDENT>elif new_categories.equals(old_categories):<EOL><INDENT>return codes.copy()<EOL><DEDENT>indexer = coerce_indexer_dtype(new_categories.get_indexer(old_categories),<EOL>new_categories)<EOL>new_codes = take_1d(indexer, codes.copy(), fill_value=-<NUM_LIT:1>)<EOL>return new_codes<EOL>
Convert a set of codes for to a new set of categories

Parameters
----------
codes : array
old_categories, new_categories : Index

Returns
-------
new_codes : array

Examples
--------
>>> old_cat = pd.Index(['b', 'a', 'c'])
>>> new_cat = pd.Index(['a', 'b'])
>>> codes = np.array([0, 1, 1, 2])
>>> _recode_for_categories(codes, old_cat, new_cat)
array([ 1,  0,  0, -1])