Skip to content

Commit 1237f20

Browse files
authored
TST:add test for df replace GH34871 (#34904)
1 parent e8dcaf9 commit 1237f20

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

pandas/tests/frame/methods/test_replace.py

+13
Original file line numberDiff line numberDiff line change
@@ -1407,3 +1407,16 @@ def test_replace_with_duplicate_columns(self, replacement):
14071407
result["B"] = result["B"].replace(7, replacement)
14081408

14091409
tm.assert_frame_equal(result, expected)
1410+
1411+
@pytest.mark.xfail(
1412+
reason="replace() changes dtype from period to object, see GH34871", strict=True
1413+
)
1414+
def test_replace_period_ignore_float(self):
1415+
"""
1416+
Regression test for GH#34871: if df.replace(1.0, 0.0) is called on a df
1417+
with a Period column the old, faulty behavior is to raise TypeError.
1418+
"""
1419+
df = pd.DataFrame({"Per": [pd.Period("2020-01")] * 3})
1420+
result = df.replace(1.0, 0.0)
1421+
expected = pd.DataFrame({"Per": [pd.Period("2020-01")] * 3})
1422+
tm.assert_frame_equal(expected, result)

0 commit comments

Comments
 (0)