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