def maybe_to_categorical(array):
 if isinstance(array, (ABCSeries, ABCCategoricalIndex)):
  return array._values
 return array

def maybe_to_categorical ( array ) : if isinstance ( array , ( ABCSeries , ABCCategoricalIndex ) ) : return array . _values return array
coerce to a categorical if a series is given .