def _maybe_to_categorical(array):
if isinstance(array, (ABCSeries, ABCCategoricalIndex)):<EOL><INDENT>return array._values<EOL><DEDENT>elif isinstance(array, np.ndarray):<EOL><INDENT>return Categorical(array)<EOL><DEDENT>return array<EOL>
Coerce to a categorical if a series is given.

Internal use ONLY.