From 567d48f3bb786ab6ff96a950e38ee013ec41e9cd Mon Sep 17 00:00:00 2001 From: Ghasem Naddaf <> Date: Tue, 14 Nov 2017 16:16:57 -0800 Subject: [PATCH] Move test to test_unique and add whats new --- doc/source/whatsnew/v0.21.1.txt | 1 + pandas/tests/test_categorical.py | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/doc/source/whatsnew/v0.21.1.txt b/doc/source/whatsnew/v0.21.1.txt index ffabc7dfe81acc..0f6135ca2f045c 100644 --- a/doc/source/whatsnew/v0.21.1.txt +++ b/doc/source/whatsnew/v0.21.1.txt @@ -61,6 +61,7 @@ Bug Fixes - Bug in :class:`DatetimeIndex` subtracting datetimelike from DatetimeIndex could fail to overflow (:issue:`18020`) - Bug in ``pd.Series.rolling.skew()`` and ``rolling.kurt()`` with all equal values has floating issue (:issue:`18044`) - Bug in ``pd.DataFrameGroupBy.count()`` when counting over a datetimelike column (:issue:`13393`) +- Bug in ``pd.Categorical.unique()`` returning read-only array when all categories were ``NaN`` (:issue:`18051`) Conversion ^^^^^^^^^^ diff --git a/pandas/tests/test_categorical.py b/pandas/tests/test_categorical.py index a320696037a999..a8782b32d12f6d 100644 --- a/pandas/tests/test_categorical.py +++ b/pandas/tests/test_categorical.py @@ -1227,10 +1227,6 @@ def test_set_categories(self): exp_categories = Index(["a", "b", "c", "d"]) tm.assert_index_equal(cat.categories, exp_categories) - # all-nan categories GH 18051 - cat_nan = Categorical([np.nan]) - assert cat_nan.unique()._codes.flags.writeable - # internals... c = Categorical([1, 2, 3, 4, 1], categories=[1, 2, 3, 4], ordered=True) tm.assert_numpy_array_equal(c._codes, np.array([0, 1, 2, 3, 0], @@ -1679,6 +1675,10 @@ def test_unique(self): exp_cat = Categorical(["b", np.nan, "a"], categories=["b", "a"]) tm.assert_categorical_equal(res, exp_cat) + # GH 18051 unique()._codes should be writeable + cat_nan = Categorical([np.nan]) + assert cat_nan.unique()._codes.flags.writeable + def test_unique_ordered(self): # keep categories order when ordered=True cat = Categorical(['b', 'a', 'b'], categories=['a', 'b'], ordered=True)