def _astype(self, dtype, copy=False, errors='<STR_LIT>', values=None,<EOL>**kwargs):
errors_legal_values = ('<STR_LIT>', '<STR_LIT:ignore>')<EOL>if errors not in errors_legal_values:<EOL><INDENT>invalid_arg = ("<STR_LIT>"<EOL>"<STR_LIT>".format(<EOL>list(errors_legal_values), errors))<EOL>raise ValueError(invalid_arg)<EOL><DEDENT>if (inspect.isclass(dtype) and<EOL>issubclass(dtype, (PandasExtensionDtype, ExtensionDtype))):<EOL><INDENT>msg = ("<STR_LIT>"<EOL>"<STR_LIT>".format(dtype.__name__))<EOL>raise TypeError(msg)<EOL><DEDENT>if self.is_categorical_astype(dtype):<EOL><INDENT>if ('<STR_LIT>' in kwargs or '<STR_LIT>' in kwargs):<EOL><INDENT>if isinstance(dtype, CategoricalDtype):<EOL><INDENT>raise TypeError(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>warnings.warn("<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>",<EOL>FutureWarning, stacklevel=<NUM_LIT:7>)<EOL><DEDENT>categories = kwargs.get('<STR_LIT>', None)<EOL>ordered = kwargs.get('<STR_LIT>', None)<EOL>if com._any_not_none(categories, ordered):<EOL><INDENT>dtype = CategoricalDtype(categories, ordered)<EOL><DEDENT>if is_categorical_dtype(self.values):<EOL><INDENT>return self.make_block(self.values.astype(dtype, copy=copy))<EOL><DEDENT>return self.make_block(Categorical(self.values, dtype=dtype))<EOL><DEDENT>dtype = pandas_dtype(dtype)<EOL>if is_dtype_equal(self.dtype, dtype):<EOL><INDENT>if copy:<EOL><INDENT>return self.copy()<EOL><DEDENT>return self<EOL><DEDENT>try:<EOL><INDENT>if values is None:<EOL><INDENT>if self.is_extension:<EOL><INDENT>values = self.values.astype(dtype)<EOL><DEDENT>else:<EOL><INDENT>if issubclass(dtype.type, str):<EOL><INDENT>if self.is_datelike:<EOL><INDENT>values = self.to_native_types()<EOL><DEDENT>else:<EOL><INDENT>values = self.get_values()<EOL><DEDENT><DEDENT>else:<EOL><INDENT>values = self.get_values(dtype=dtype)<EOL><DEDENT>values = astype_nansafe(values.ravel(), dtype, copy=True)<EOL><DEDENT>try:<EOL><INDENT>values = values.reshape(self.shape)<EOL><DEDENT>except AttributeError:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>newb = make_block(values, placement=self.mgr_locs,<EOL>ndim=self.ndim)<EOL><DEDENT>except Exception:  <EOL><INDENT>if errors == '<STR_LIT>':<EOL><INDENT>raise<EOL><DEDENT>newb = self.copy() if copy else self<EOL><DEDENT>if newb.is_numeric and self.is_numeric:<EOL><INDENT>if newb.shape != self.shape:<EOL><INDENT>raise TypeError(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>".format(<EOL>copy=copy, dtype=self.dtype.name,<EOL>shape=self.shape, newb_dtype=newb.dtype.name,<EOL>newb_shape=newb.shape))<EOL><DEDENT><DEDENT>return newb<EOL>
Coerce to the new type

        Parameters
        ----------
        dtype : str, dtype convertible
        copy : boolean, default False
            copy if indicated
        errors : str, {'raise', 'ignore'}, default 'ignore'
            - ``raise`` : allow exceptions to be raised
            - ``ignore`` : suppress exceptions. On error return original object

        Returns
        -------
        Block