diff --git a/pandas/tests/dtypes/test_dtypes.py b/pandas/tests/dtypes/test_dtypes.py index 8ba8562affb67..410731820dc73 100644 --- a/pandas/tests/dtypes/test_dtypes.py +++ b/pandas/tests/dtypes/test_dtypes.py @@ -218,6 +218,12 @@ def test_repr_range_categories(self): expected = "CategoricalDtype(categories=range(0, 3), ordered=False)" assert result == expected + def test_update_dtype(self): + # GH 27338 + result = CategoricalDtype(["a"]).update_dtype(Categorical(["b"], ordered=True)) + expected = CategoricalDtype(["b"], ordered=True) + assert result == expected + class TestDatetimeTZDtype(Base): @pytest.fixture diff --git a/pandas/tests/series/methods/test_update.py b/pandas/tests/series/methods/test_update.py index d00a4299cb690..51760c451ebca 100644 --- a/pandas/tests/series/methods/test_update.py +++ b/pandas/tests/series/methods/test_update.py @@ -108,3 +108,13 @@ def test_update_from_non_series(self, series, other, expected): def test_update_extension_array_series(self, result, target, expected): result.update(target) tm.assert_series_equal(result, expected) + + def test_update_with_categorical_type(self): + # GH 25744 + dtype = CategoricalDtype(["a", "b", "c", "d"]) + s1 = Series(["a", "b", "c"], index=[1, 2, 3], dtype=dtype) + s2 = Series(["b", "a"], index=[1, 2], dtype=dtype) + s1.update(s2) + result = s1 + expected = Series(["b", "a", "c"], index=[1, 2, 3], dtype=dtype) + tm.assert_series_equal(result, expected)