Skip to content

Commit 4a1d3d7

Browse files
authored
TST: Series.update with categorical (#38873)
1 parent f9ce9d6 commit 4a1d3d7

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

pandas/tests/dtypes/test_dtypes.py

+6
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,12 @@ def test_repr_range_categories(self):
218218
expected = "CategoricalDtype(categories=range(0, 3), ordered=False)"
219219
assert result == expected
220220

221+
def test_update_dtype(self):
222+
# GH 27338
223+
result = CategoricalDtype(["a"]).update_dtype(Categorical(["b"], ordered=True))
224+
expected = CategoricalDtype(["b"], ordered=True)
225+
assert result == expected
226+
221227

222228
class TestDatetimeTZDtype(Base):
223229
@pytest.fixture

pandas/tests/series/methods/test_update.py

+10
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,13 @@ def test_update_from_non_series(self, series, other, expected):
108108
def test_update_extension_array_series(self, result, target, expected):
109109
result.update(target)
110110
tm.assert_series_equal(result, expected)
111+
112+
def test_update_with_categorical_type(self):
113+
# GH 25744
114+
dtype = CategoricalDtype(["a", "b", "c", "d"])
115+
s1 = Series(["a", "b", "c"], index=[1, 2, 3], dtype=dtype)
116+
s2 = Series(["b", "a"], index=[1, 2], dtype=dtype)
117+
s1.update(s2)
118+
result = s1
119+
expected = Series(["b", "a", "c"], index=[1, 2, 3], dtype=dtype)
120+
tm.assert_series_equal(result, expected)

0 commit comments

Comments
 (0)