code: def _factorize_from_iterable(values):
      
      from pandas.core.indexes.category import CategoricalIndex
  
      if not is_list_like(values):
          raise TypeError("Input must be list-like")
  
      if is_categorical(values):
          if isinstance(values, (ABCCategoricalIndex, ABCSeries)):
              values = values._values
          categories = CategoricalIndex(values.categories, dtype=values.dtype)
          codes = values.codes
      else:
          # The value of ordered is irrelevant since we don't use cat as such,
          # but only the resulting categories, the order of which is independent
          # from ordered. Set ordered to False as default. See GH #15457
          cat = Categorical(values, ordered=False)
          categories = cat.categories
          codes = cat.codes
      return codes, categories
docs: Factorize an input `values` into `categories` and `codes`. Preserves
      categorical dtype in `categories`.
  
      *This is an internal function*
  
      Parameters
      ----------
      values : list-like
  
      Returns
      -------
      codes : ndarray
      categories : Index
          If `values` has a categorical dtype, then `categories` is
          a CategoricalIndex keeping the categories and order of `values`.