@classmethod
def _from_inferred_categories(cls, inferred_categories, inferred_codes, dtype):
    "Construct a Categorical from inferred values\n\n        For inferred categories (`dtype` is None) the categories are sorted.\n        For explicit `dtype`, the `inferred_categories` are cast to the\n        appropriate type.\n\n        Parameters\n        ----------\n\n        inferred_categories : Index\n        inferred_codes : Index\n        dtype : CategoricalDtype or 'category'\n\n        Returns\n        -------\n        Categorical\n        "
    from pandas import Index, to_numeric, to_datetime, to_timedelta
    cats = Index(inferred_categories)
    known_categories = (isinstance(dtype, CategoricalDtype) and (dtype.categories is not None))
    if known_categories:
        if dtype.categories.is_numeric():
            cats = to_numeric(inferred_categories, errors='coerce')
        elif is_datetime64_dtype(dtype.categories):
            cats = to_datetime(inferred_categories, errors='coerce')
        elif is_timedelta64_dtype(dtype.categories):
            cats = to_timedelta(inferred_categories, errors='coerce')
    if known_categories:
        categories = dtype.categories
        codes = _recode_for_categories(inferred_codes, cats, categories)
    elif (not cats.is_monotonic_increasing):
        unsorted = cats.copy()
        categories = cats.sort_values()
        codes = _recode_for_categories(inferred_codes, unsorted, categories)
        dtype = CategoricalDtype(categories, ordered=False)
    else:
        dtype = CategoricalDtype(cats, ordered=False)
        codes = inferred_codes
    return cls(codes, dtype=dtype, fastpath=True)
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'

Returns
-------
Categorical
@classmethod
def _from_inferred_categories(cls, inferred_categories, inferred_codes, dtype):
    "Construct a Categorical from inferred values\n\n        For inferred categories (`dtype` is None) the categories are sorted.\n        For explicit `dtype`, the `inferred_categories` are cast to the\n        appropriate type.\n\n        Parameters\n        ----------\n\n        inferred_categories : Index\n        inferred_codes : Index\n        dtype : CategoricalDtype or 'category'\n\n        Returns\n        -------\n        Categorical\n        "
    from pandas import Index, to_numeric, to_datetime, to_timedelta
    cats = Index(inferred_categories)
    known_categories = (isinstance(dtype, CategoricalDtype) and (dtype.categories is not None))
    if known_categories:
        if dtype.categories.is_numeric():
            cats = to_numeric(inferred_categories, errors='coerce')
        elif is_datetime64_dtype(dtype.categories):
            cats = to_datetime(inferred_categories, errors='coerce')
        elif is_timedelta64_dtype(dtype.categories):
            cats = to_timedelta(inferred_categories, errors='coerce')
    if known_categories:
        categories = dtype.categories
        codes = _recode_for_categories(inferred_codes, cats, categories)
    elif (not cats.is_monotonic_increasing):
        unsorted = cats.copy()
        categories = cats.sort_values()
        codes = _recode_for_categories(inferred_codes, unsorted, categories)
        dtype = CategoricalDtype(categories, ordered=False)
    else:
        dtype = CategoricalDtype(cats, ordered=False)
        codes = inferred_codes
    return cls(codes, dtype=dtype, fastpath=True)