Skip to content

Commit 9192881

Browse files
committed
Add a test
1 parent f7c4694 commit 9192881

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

pandas/tests/arrays/categorical/test_astype.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,16 @@ def test_astype_category(self, dtype_ordered, ordered):
130130
expected = cat
131131
tm.assert_categorical_equal(result, expected)
132132

133+
def test_astype_category_copy_false_nocopy_codes(self):
134+
cat = Categorical([3, 2, 4, 1])
135+
# ensure that the categories are not copied
136+
assert cat.codes.base is not None
137+
138+
new = cat.astype("category", copy=False)
139+
assert new.codes.base is cat.codes.base or new.codes is cat.codes
140+
new = cat.astype("category", copy=True)
141+
assert not (new.codes.base is cat.codes.base or new.codes is cat.codes)
142+
133143
def test_astype_object_datetime_categories(self):
134144
# GH#40754
135145
cat = Categorical(to_datetime(["2021-03-27", NaT]))

0 commit comments

Comments
 (0)