Skip to content

Commit 8aa627a

Browse files
phoflnoatamir
authored andcommitted
TST: Add test for replace categorical no replacement changes dtype (pandas-dev#48168)
1 parent 62e5f7d commit 8aa627a

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

pandas/tests/frame/methods/test_replace.py

+14
Original file line numberDiff line numberDiff line change
@@ -1559,3 +1559,17 @@ def test_replace_with_value_also_being_replaced(self):
15591559
result = df.replace({0: 1, 1: np.nan})
15601560
expected = DataFrame({"A": [1, np.nan, 2], "B": [np.nan, 1, 2]})
15611561
tm.assert_frame_equal(result, expected)
1562+
1563+
def test_replace_categorical_no_replacement(self):
1564+
# GH#46672
1565+
df = DataFrame(
1566+
{
1567+
"a": ["one", "two", None, "three"],
1568+
"b": ["one", None, "two", "three"],
1569+
},
1570+
dtype="category",
1571+
)
1572+
expected = df.copy()
1573+
1574+
result = df.replace(to_replace=[".", "def"], value=["_", None])
1575+
tm.assert_frame_equal(result, expected)

0 commit comments

Comments
 (0)