Skip to content

Commit

Permalink
BUG: conversion of Series to Categorical (pandas-dev#16557)
Browse files Browse the repository at this point in the history
fix pandas-dev#16524

(cherry picked from commit 9fdea65)
  • Loading branch information
preddy5 authored and TomAugspurger committed Jul 6, 2017
1 parent 7043a9e commit 7236a42
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.20.3.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
^^^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions pandas/tests/series/test_dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 7236a42

Please sign in to comment.