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
  • Loading branch information
preddy5 authored and stangirala committed Jun 11, 2017
1 parent 9b0e0dc commit af037f9
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
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
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
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 af037f9

Please sign in to comment.