def _recode_for_categories(codes, old_categories, new_categories):
    "\n    Convert a set of codes for to a new set of categories\n\n    Parameters\n    ----------\n    codes : array\n    old_categories, new_categories : Index\n\n    Returns\n    -------\n    new_codes : array\n\n    Examples\n    --------\n    >>> old_cat = pd.Index(['b', 'a', 'c'])\n    >>> new_cat = pd.Index(['a', 'b'])\n    >>> codes = np.array([0, 1, 1, 2])\n    >>> _recode_for_categories(codes, old_cat, new_cat)\n    array([ 1,  0,  0, -1])\n    "
    from pandas.core.algorithms import take_1d
    if (len(old_categories) == 0):
        return codes.copy()
    indexer = coerce_indexer_dtype(new_categories.get_indexer(old_categories), new_categories)
    new_codes = take_1d(indexer, codes.copy(), fill_value=(- 1))
    return new_codes
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])
def _recode_for_categories(codes, old_categories, new_categories):
    "\n    Convert a set of codes for to a new set of categories\n\n    Parameters\n    ----------\n    codes : array\n    old_categories, new_categories : Index\n\n    Returns\n    -------\n    new_codes : array\n\n    Examples\n    --------\n    >>> old_cat = pd.Index(['b', 'a', 'c'])\n    >>> new_cat = pd.Index(['a', 'b'])\n    >>> codes = np.array([0, 1, 1, 2])\n    >>> _recode_for_categories(codes, old_cat, new_cat)\n    array([ 1,  0,  0, -1])\n    "
    from pandas.core.algorithms import take_1d
    if (len(old_categories) == 0):
        return codes.copy()
    indexer = coerce_indexer_dtype(new_categories.get_indexer(old_categories), new_categories)
    new_codes = take_1d(indexer, codes.copy(), fill_value=(- 1))
    return new_codes