@classmethod<EOL><INDENT>def _from_values_or_dtype(cls, values=None, categories=None, ordered=None,<EOL>dtype=None):<DEDENT>
from pandas.core.dtypes.common import is_categorical<EOL>if dtype is not None:<EOL><INDENT>if isinstance(dtype, str):<EOL><INDENT>if dtype == '<STR_LIT>':<EOL><INDENT>dtype = CategoricalDtype(categories, ordered)<EOL><DEDENT>else:<EOL><INDENT>msg = "<STR_LIT>"<EOL>raise ValueError(msg.format(dtype=dtype))<EOL><DEDENT><DEDENT>elif categories is not None or ordered is not None:<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT><DEDENT>elif is_categorical(values):<EOL><INDENT>dtype = values.dtype._from_categorical_dtype(values.dtype,<EOL>categories, ordered)<EOL><DEDENT>else:<EOL><INDENT>dtype = CategoricalDtype(categories, ordered)<EOL><DEDENT>return dtype<EOL>
Construct dtype from the input parameters used in :class:`Categorical`.

This constructor method specifically does not do the factorization
step, if that is needed to find the categories. This constructor may
therefore return ``CategoricalDtype(categories=None, ordered=None)``,
which may not be useful. Additional steps may therefore have to be
taken to create the final dtype.

The return dtype is specified from the inputs in this prioritized
order:
1. if dtype is a CategoricalDtype, return dtype
2. if dtype is the string 'category', create a CategoricalDtype from
   the supplied categories and ordered parameters, and return that.
3. if values is a categorical, use value.dtype, but override it with
   categories and ordered if either/both of those are not None.
4. if dtype is None and values is not a categorical, construct the
   dtype from categories and ordered, even if either of those is None.

Parameters
----------
values : list-like, optional
    The list-like must be 1-dimensional.
categories : list-like, optional
    Categories for the CategoricalDtype.
ordered : bool, optional
    Designating if the categories are ordered.
dtype : CategoricalDtype or the string "category", optional
    If ``CategoricalDtype``, cannot be used together with
    `categories` or `ordered`.

Returns
-------
CategoricalDtype

Examples
--------
>>> CategoricalDtype._from_values_or_dtype()
CategoricalDtype(categories=None, ordered=None)
>>> CategoricalDtype._from_values_or_dtype(categories=['a', 'b'],
...                                        ordered=True)
CategoricalDtype(categories=['a', 'b'], ordered=True)
>>> dtype1 = CategoricalDtype(['a', 'b'], ordered=True)
>>> dtype2 = CategoricalDtype(['x', 'y'], ordered=False)
>>> c = Categorical([0, 1], dtype=dtype1, fastpath=True)
>>> CategoricalDtype._from_values_or_dtype(c, ['x', 'y'], ordered=True,
...                                        dtype=dtype2)
ValueError: Cannot specify `categories` or `ordered` together with
`dtype`.

The supplied dtype takes precedence over values' dtype:

>>> CategoricalDtype._from_values_or_dtype(c, dtype=dtype2)
CategoricalDtype(['x', 'y'], ordered=False)