def update_dtype(self, dtype):
if isinstance(dtype, str) and dtype == '<STR_LIT>':<EOL><INDENT>return self<EOL><DEDENT>elif not self.is_dtype(dtype):<EOL><INDENT>msg = ('<STR_LIT>'<EOL>'<STR_LIT>').format(dtype=dtype)<EOL>raise ValueError(msg)<EOL><DEDENT>elif dtype.categories is not None and dtype.ordered is self.ordered:<EOL><INDENT>return dtype<EOL><DEDENT>new_categories = dtype.categories<EOL>if new_categories is None:<EOL><INDENT>new_categories = self.categories<EOL><DEDENT>new_ordered = dtype.ordered<EOL>if new_ordered is None:<EOL><INDENT>new_ordered = self.ordered<EOL><DEDENT>return CategoricalDtype(new_categories, new_ordered)<EOL>
Returns a CategoricalDtype with categories and ordered taken from dtype
if specified, otherwise falling back to self if unspecified

Parameters
----------
dtype : CategoricalDtype

Returns
-------
new_dtype : CategoricalDtype