def _maybe_to_categorical(array):
    '\n    Coerce to a categorical if a series is given.\n\n    Internal use ONLY.\n    '
    if isinstance(array, (ABCSeries, ABCCategoricalIndex)):
        return array._values
    elif isinstance(array, np.ndarray):
        return Categorical(array)
    return array
Coerce to a categorical if a series is given.

Internal use ONLY.
def _maybe_to_categorical(array):
    '\n    Coerce to a categorical if a series is given.\n\n    Internal use ONLY.\n    '
    if isinstance(array, (ABCSeries, ABCCategoricalIndex)):
        return array._values
    elif isinstance(array, np.ndarray):
        return Categorical(array)
    return array