def maybe_to_categorical(array):
    if isinstance(array, (ABCSeries, ABCCategoricalIndex)):
        return array._values
    return array
coerce to a categorical if a series is given
dataset/ETHPy150Open pydata/pandas/pandas/core/categorical.py/maybe_to_categorical