def _factorize_from_iterable(values):
from pandas.core.indexes.category import CategoricalIndex<EOL>if not is_list_like(values):<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>if is_categorical(values):<EOL><INDENT>if isinstance(values, (ABCCategoricalIndex, ABCSeries)):<EOL><INDENT>values = values._values<EOL><DEDENT>categories = CategoricalIndex(values.categories, dtype=values.dtype)<EOL>codes = values.codes<EOL><DEDENT>else:<EOL><INDENT>cat = Categorical(values, ordered=False)<EOL>categories = cat.categories<EOL>codes = cat.codes<EOL><DEDENT>return codes, categories<EOL>
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`.