From 3e1d73f69ac98d3d367995de9363f77162c4731b Mon Sep 17 00:00:00 2001 From: Pradyumna Reddy Date: Thu, 1 Jun 2017 21:15:04 +0530 Subject: [PATCH] bug fix #16524 --- doc/source/whatsnew/v0.20.2.txt | 1 + pandas/core/categorical.py | 3 ++- pandas/tests/series/test_dtypes.py | 11 ++++++++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/doc/source/whatsnew/v0.20.2.txt b/doc/source/whatsnew/v0.20.2.txt index 379249b6e55d67..e809af3d739eac 100644 --- a/doc/source/whatsnew/v0.20.2.txt +++ b/doc/source/whatsnew/v0.20.2.txt @@ -54,6 +54,7 @@ Conversion - Bug in ``pd.to_numeric()`` in which empty data inputs were causing Python to crash (:issue:`16302`) - Silence numpy warnings when broadcasting DataFrame to Series with comparison ops (:issue:`16378`, :issue:`16306`) +- Bug in ``Series`` with dtype='category' (:issue:`16524`) Indexing diff --git a/pandas/core/categorical.py b/pandas/core/categorical.py index f58eed74f760eb..f62a3d54185bac 100644 --- a/pandas/core/categorical.py +++ b/pandas/core/categorical.py @@ -248,7 +248,8 @@ class Categorical(PandasObject): __array_priority__ = 1000 _typ = 'categorical' - def __init__(self, values, categories=None, ordered=False, fastpath=False): + def __init__(self, values, categories=None, ordered=False, fastpath=False, + **kwargs): self._validate_ordered(ordered) diff --git a/pandas/tests/series/test_dtypes.py b/pandas/tests/series/test_dtypes.py index e084fa58d6c51c..db3e5f7e58872f 100644 --- a/pandas/tests/series/test_dtypes.py +++ b/pandas/tests/series/test_dtypes.py @@ -12,7 +12,8 @@ from numpy import nan import numpy as np -from pandas import Series, Timestamp, Timedelta, DataFrame, date_range +from pandas import (Categorical, Series, Timestamp, Timedelta, + DataFrame, date_range) from pandas.compat import lrange, range, u from pandas import compat @@ -248,3 +249,11 @@ def test_intercept_astype_object(self): result = df.values.squeeze() assert (result[:, 0] == expected.values).all() + + def test_series_to_categorical(self): + series = Series(['a', 'b', 'c']) + + categorical_series = Series(series, dtype='category') + expected = Categorical(['a', 'b', 'c']) + + assert (categorical_series == expected).all()