@classmethod<EOL><INDENT>def _from_inferred_categories(cls, inferred_categories, inferred_codes,<EOL>dtype, true_values=None):<DEDENT>
from pandas import Index, to_numeric, to_datetime, to_timedelta<EOL>cats = Index(inferred_categories)<EOL>known_categories = (isinstance(dtype, CategoricalDtype) and<EOL>dtype.categories is not None)<EOL>if known_categories:<EOL><INDENT>if dtype.categories.is_numeric():<EOL><INDENT>cats = to_numeric(inferred_categories, errors="<STR_LIT>")<EOL><DEDENT>elif is_datetime64_dtype(dtype.categories):<EOL><INDENT>cats = to_datetime(inferred_categories, errors="<STR_LIT>")<EOL><DEDENT>elif is_timedelta64_dtype(dtype.categories):<EOL><INDENT>cats = to_timedelta(inferred_categories, errors="<STR_LIT>")<EOL><DEDENT>elif dtype.categories.is_boolean():<EOL><INDENT>if true_values is None:<EOL><INDENT>true_values = ["<STR_LIT:True>", "<STR_LIT>", "<STR_LIT:true>"]<EOL><DEDENT>cats = cats.isin(true_values)<EOL><DEDENT><DEDENT>if known_categories:<EOL><INDENT>categories = dtype.categories<EOL>codes = _recode_for_categories(inferred_codes, cats, categories)<EOL><DEDENT>elif not cats.is_monotonic_increasing:<EOL><INDENT>unsorted = cats.copy()<EOL>categories = cats.sort_values()<EOL>codes = _recode_for_categories(inferred_codes, unsorted,<EOL>categories)<EOL>dtype = CategoricalDtype(categories, ordered=False)<EOL><DEDENT>else:<EOL><INDENT>dtype = CategoricalDtype(cats, ordered=False)<EOL>codes = inferred_codes<EOL><DEDENT>return cls(codes, dtype=dtype, fastpath=True)<EOL>
Construct a Categorical from inferred values.

For inferred categories (`dtype` is None) the categories are sorted.
For explicit `dtype`, the `inferred_categories` are cast to the
appropriate type.

Parameters
----------
inferred_categories : Index
inferred_codes : Index
dtype : CategoricalDtype or 'category'
true_values : list, optional
    If none are provided, the default ones are
    "True", "TRUE", and "true."

Returns
-------
Categorical