Skip to content

Commit 9fdea65

Browse files
preddy5jorisvandenbossche
authored andcommitted
BUG: conversion of Series to Categorical (pandas-dev#16557)
fix pandas-dev#16524
1 parent 73930c5 commit 9fdea65

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

doc/source/whatsnew/v0.20.3.txt

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ Conversion
4444
^^^^^^^^^^
4545

4646
- Bug in pickle compat prior to the v0.20.x series, when ``UTC`` is a timezone in a Series/DataFrame/Index (:issue:`16608`)
47+
- Bug in Series construction when passing a Series with ``dtype='category'`` (:issue:`16524`).
4748

4849
Indexing
4950
^^^^^^^^

pandas/core/internals.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ def astype(self, dtype, copy=False, errors='raise', values=None, **kwargs):
471471
**kwargs)
472472

473473
def _astype(self, dtype, copy=False, errors='raise', values=None,
474-
klass=None, mgr=None, **kwargs):
474+
klass=None, mgr=None, raise_on_error=False, **kwargs):
475475
"""
476476
Coerce to the new type (if copy=True, return a new copy)
477477
raise on an except if raise == True

pandas/tests/series/test_dtypes.py

+9
Original file line numberDiff line numberDiff line change
@@ -248,3 +248,12 @@ def test_intercept_astype_object(self):
248248

249249
result = df.values.squeeze()
250250
assert (result[:, 0] == expected.values).all()
251+
252+
def test_series_to_categorical(self):
253+
# see gh-16524: test conversion of Series to Categorical
254+
series = Series(['a', 'b', 'c'])
255+
256+
result = Series(series, dtype='category')
257+
expected = Series(['a', 'b', 'c'], dtype='category')
258+
259+
tm.assert_series_equal(result, expected)

0 commit comments

Comments
 (0)