def contains(cat, key, container):
    '\n    Helper for membership check for ``key`` in ``cat``.\n\n    This is a helper method for :method:`__contains__`\n    and :class:`CategoricalIndex.__contains__`.\n\n    Returns True if ``key`` is in ``cat.categories`` and the\n    location of ``key`` in ``categories`` is in ``container``.\n\n    Parameters\n    ----------\n    cat : :class:`Categorical`or :class:`categoricalIndex`\n    key : a hashable object\n        The key to check membership for.\n    container : Container (e.g. list-like or mapping)\n        The container to check for membership in.\n\n    Returns\n    -------\n    is_in : bool\n        True if ``key`` is in ``self.categories`` and location of\n        ``key`` in ``categories`` is in ``container``, else False.\n\n    Notes\n    -----\n    This method does not check for NaN values. Do that separately\n    before calling this method.\n    '
    hash(key)
    try:
        loc = cat.categories.get_loc(key)
    except KeyError:
        return False
    if is_scalar(loc):
        return (loc in container)
    else:
        return any(((loc_ in container) for loc_ in loc))
Helper for membership check for ``key`` in ``cat``.

This is a helper method for :method:`__contains__`
and :class:`CategoricalIndex.__contains__`.

Returns True if ``key`` is in ``cat.categories`` and the
location of ``key`` in ``categories`` is in ``container``.

Parameters
----------
cat : :class:`Categorical`or :class:`categoricalIndex`
key : a hashable object
    The key to check membership for.
container : Container (e.g. list-like or mapping)
    The container to check for membership in.

Returns
-------
is_in : bool
    True if ``key`` is in ``self.categories`` and location of
    ``key`` in ``categories`` is in ``container``, else False.

Notes
-----
This method does not check for NaN values. Do that separately
before calling this method.
def contains(cat, key, container):
    '\n    Helper for membership check for ``key`` in ``cat``.\n\n    This is a helper method for :method:`__contains__`\n    and :class:`CategoricalIndex.__contains__`.\n\n    Returns True if ``key`` is in ``cat.categories`` and the\n    location of ``key`` in ``categories`` is in ``container``.\n\n    Parameters\n    ----------\n    cat : :class:`Categorical`or :class:`categoricalIndex`\n    key : a hashable object\n        The key to check membership for.\n    container : Container (e.g. list-like or mapping)\n        The container to check for membership in.\n\n    Returns\n    -------\n    is_in : bool\n        True if ``key`` is in ``self.categories`` and location of\n        ``key`` in ``categories`` is in ``container``, else False.\n\n    Notes\n    -----\n    This method does not check for NaN values. Do that separately\n    before calling this method.\n    '
    hash(key)
    try:
        loc = cat.categories.get_loc(key)
    except KeyError:
        return False
    if is_scalar(loc):
        return (loc in container)
    else:
        return any(((loc_ in container) for loc_ in loc))