Skip to content

Commit 567d48f

Browse files
author
Ghasem Naddaf
committed
Move test to test_unique and add whats new
1 parent b35f16e commit 567d48f

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

doc/source/whatsnew/v0.21.1.txt

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ Bug Fixes
6161
- Bug in :class:`DatetimeIndex` subtracting datetimelike from DatetimeIndex could fail to overflow (:issue:`18020`)
6262
- Bug in ``pd.Series.rolling.skew()`` and ``rolling.kurt()`` with all equal values has floating issue (:issue:`18044`)
6363
- Bug in ``pd.DataFrameGroupBy.count()`` when counting over a datetimelike column (:issue:`13393`)
64+
- Bug in ``pd.Categorical.unique()`` returning read-only array when all categories were ``NaN`` (:issue:`18051`)
6465

6566
Conversion
6667
^^^^^^^^^^

pandas/tests/test_categorical.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1227,10 +1227,6 @@ def test_set_categories(self):
12271227
exp_categories = Index(["a", "b", "c", "d"])
12281228
tm.assert_index_equal(cat.categories, exp_categories)
12291229

1230-
# all-nan categories GH 18051
1231-
cat_nan = Categorical([np.nan])
1232-
assert cat_nan.unique()._codes.flags.writeable
1233-
12341230
# internals...
12351231
c = Categorical([1, 2, 3, 4, 1], categories=[1, 2, 3, 4], ordered=True)
12361232
tm.assert_numpy_array_equal(c._codes, np.array([0, 1, 2, 3, 0],
@@ -1679,6 +1675,10 @@ def test_unique(self):
16791675
exp_cat = Categorical(["b", np.nan, "a"], categories=["b", "a"])
16801676
tm.assert_categorical_equal(res, exp_cat)
16811677

1678+
# GH 18051 unique()._codes should be writeable
1679+
cat_nan = Categorical([np.nan])
1680+
assert cat_nan.unique()._codes.flags.writeable
1681+
16821682
def test_unique_ordered(self):
16831683
# keep categories order when ordered=True
16841684
cat = Categorical(['b', 'a', 'b'], categories=['a', 'b'], ordered=True)

0 commit comments

Comments
 (0)