# Buggy code
def _astype(
    self, dtype, copy=False, errors="raise", values=None, klass=None, mgr=None, **kwargs
):
    """
    Coerce to the new type (if copy=True, return a new copy)
    raise on an except if raise == True
    """
    errors_legal_values = ("raise", "ignore")

    if errors not in errors_legal_values:
        invalid_arg = (
            "Expected value of kwarg 'errors' to be one of {}. "
            "Supplied value is '{}'".format(list(errors_legal_values), errors)
        )
        raise ValueError(invalid_arg)

    # may need to convert to categorical
    # this is only called for non-categoricals
    if self.is_categorical_astype(dtype):
        return self.make_block(Categorical(self.values, **kwargs))

    # astype processing
    dtype = np.dtype(dtype)
    if self.dtype == dtype:
        if copy:
            return self.copy()
        return self

    if klass is None:
        if dtype == np.object_:
            klass = ObjectBlock
    try:
        # force the copy here
        if values is None:
            if issubclass(dtype.type, (compat.text_type, compat.string_types)):
                # use native type formatting for datetime/tz/timedelta
                if self.is_datelike:
                    values = self.to_native_types()

                # astype formatting
                else:
                    values = self.values

            else:
                values = self.get_values(dtype=dtype)

            # _astype_nansafe works fine with 1-d only
            values = astype_nansafe(values.ravel(), dtype, copy=True)
            values = values.reshape(self.shape)

        newb = make_block(values, placement=self.mgr_locs, dtype=dtype, klass=klass)
    except:
        if errors == "raise":
            raise
        newb = self.copy() if copy else self

    if newb.is_numeric and self.is_numeric:
        if newb.shape != self.shape:
            raise TypeError(
                "cannot set astype for copy = [%s] for dtype "
                "(%s [%s]) with smaller itemsize that current "
                "(%s [%s])"
                % (copy, self.dtype.name, self.itemsize, newb.dtype.name, newb.itemsize)
            )
    return newb


# Traceback (TypeError)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-32-6c903a3f0db3> in <module>()
----> 1 pd.Series(pd.Series(['a', 'b', 'c']), dtype='category')

/Users/ttylec/.virtualenvs/zettafox/lib/python3.6/site-packages/pandas/core/series.py in __init__(self, data, index, dtype, name, copy, fastpath)
241                 if dtype is not None:
242                     data = data.astype(dtype=dtype, raise_on_error=False,
--> 243                                        copy=copy)
244                 elif copy:
245                     data = data.copy()

/Users/ttylec/.virtualenvs/zettafox/lib/python3.6/site-packages/pandas/core/internals.py in astype(self, dtype, **kwargs)
3222
3223     def astype(self, dtype, **kwargs):
-> 3224         return self.apply('astype', dtype=dtype, **kwargs)
3225
3226     def convert(self, **kwargs):

/Users/ttylec/.virtualenvs/zettafox/lib/python3.6/site-packages/pandas/core/internals.py in apply(self, f, axes, filter, do_integrity_check, consolidate, **kwargs)
3089
3090             kwargs['mgr'] = self
-> 3091             applied = getattr(b, f)(**kwargs)
3092             result_blocks = _extend_blocks(applied, result_blocks)
3093

/Users/ttylec/.virtualenvs/zettafox/lib/python3.6/site-packages/pandas/core/internals.py in astype(self, dtype, copy, errors, values, **kwargs)
469     def astype(self, dtype, copy=False, errors='raise', values=None, **kwargs):
470         return self._astype(dtype, copy=copy, errors=errors, values=values,
--> 471                             **kwargs)
472
473     def _astype(self, dtype, copy=False, errors='raise', values=None,

/Users/ttylec/.virtualenvs/zettafox/lib/python3.6/site-packages/pandas/core/internals.py in _astype(self, dtype, copy, errors, values, klass, mgr, **kwargs)
488         # this is only called for non-categoricals
489         if self.is_categorical_astype(dtype):
--> 490             return self.make_block(Categorical(self.values, **kwargs))
491
492         # astype processing

TypeError: __init__() got an unexpected keyword argument 'raise_on_error'

# Fixed code
def _astype(
    self,
    dtype,
    copy=False,
    errors="raise",
    values=None,
    klass=None,
    mgr=None,
    raise_on_error=False,
    **kwargs,
):
    """
    Coerce to the new type (if copy=True, return a new copy)
    raise on an except if raise == True
    """
    errors_legal_values = ("raise", "ignore")

    if errors not in errors_legal_values:
        invalid_arg = (
            "Expected value of kwarg 'errors' to be one of {}. "
            "Supplied value is '{}'".format(list(errors_legal_values), errors)
        )
        raise ValueError(invalid_arg)

    # may need to convert to categorical
    # this is only called for non-categoricals
    if self.is_categorical_astype(dtype):
        return self.make_block(Categorical(self.values, **kwargs))

    # astype processing
    dtype = np.dtype(dtype)
    if self.dtype == dtype:
        if copy:
            return self.copy()
        return self

    if klass is None:
        if dtype == np.object_:
            klass = ObjectBlock
    try:
        # force the copy here
        if values is None:
            if issubclass(dtype.type, (compat.text_type, compat.string_types)):
                # use native type formatting for datetime/tz/timedelta
                if self.is_datelike:
                    values = self.to_native_types()

                # astype formatting
                else:
                    values = self.values

            else:
                values = self.get_values(dtype=dtype)

            # _astype_nansafe works fine with 1-d only
            values = astype_nansafe(values.ravel(), dtype, copy=True)
            values = values.reshape(self.shape)

        newb = make_block(values, placement=self.mgr_locs, dtype=dtype, klass=klass)
    except:
        if errors == "raise":
            raise
        newb = self.copy() if copy else self

    if newb.is_numeric and self.is_numeric:
        if newb.shape != self.shape:
            raise TypeError(
                "cannot set astype for copy = [%s] for dtype "
                "(%s [%s]) with smaller itemsize that current "
                "(%s [%s])"
                % (copy, self.dtype.name, self.itemsize, newb.dtype.name, newb.itemsize)
            )
    return newb