diff --git a/doc/source/whatsnew/v0.20.3.txt b/doc/source/whatsnew/v0.20.3.txt index 2032209c4aa23..83cd5cc4b470c 100644 --- a/doc/source/whatsnew/v0.20.3.txt +++ b/doc/source/whatsnew/v0.20.3.txt @@ -44,6 +44,7 @@ Conversion ^^^^^^^^^^ - Bug in pickle compat prior to the v0.20.x series, when ``UTC`` is a timezone in a Series/DataFrame/Index (:issue:`16608`) +- Bug in Series construction when passing a Series with ``dtype='category'`` (:issue:`16524`). Indexing ^^^^^^^^ diff --git a/pandas/core/internals.py b/pandas/core/internals.py index 58690ad632152..f2a7ac76481d4 100644 --- a/pandas/core/internals.py +++ b/pandas/core/internals.py @@ -471,7 +471,7 @@ def astype(self, dtype, copy=False, errors='raise', values=None, **kwargs): **kwargs) def _astype(self, dtype, copy=False, errors='raise', values=None, - klass=None, mgr=None, **kwargs): + 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 diff --git a/pandas/tests/series/test_dtypes.py b/pandas/tests/series/test_dtypes.py index e084fa58d6c51..9ab02a8c2aad7 100644 --- a/pandas/tests/series/test_dtypes.py +++ b/pandas/tests/series/test_dtypes.py @@ -248,3 +248,12 @@ def test_intercept_astype_object(self): result = df.values.squeeze() assert (result[:, 0] == expected.values).all() + + def test_series_to_categorical(self): + # see gh-16524: test conversion of Series to Categorical + series = Series(['a', 'b', 'c']) + + result = Series(series, dtype='category') + expected = Series(['a', 'b', 'c'], dtype='category') + + tm.assert_series_equal(result, expected)