Skip to content

Commit c4449f0

Browse files
authored
ERR: improve exception message for Series.replace (#62686)
1 parent a609b57 commit c4449f0

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

pandas/core/generic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7627,8 +7627,8 @@ def replace(
76277627
# Operate column-wise
76287628
if self.ndim == 1:
76297629
raise ValueError(
7630-
"Series.replace cannot use dict-like to_replace "
7631-
"and non-None value"
7630+
"Series.replace cannot specify both a dict-like "
7631+
"'to_replace' and a 'value'"
76327632
)
76337633
mapping = {
76347634
col: (to_rep, value) for col, to_rep in to_replace.items()

pandas/tests/series/methods/test_replace.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,9 @@ def test_replace_only_one_dictlike_arg(self, fixed_now_ts):
486486
ser = pd.Series([1, 2, "A", fixed_now_ts, True])
487487
to_replace = {0: 1, 2: "A"}
488488
value = "foo"
489-
msg = "Series.replace cannot use dict-like to_replace and non-None value"
489+
msg = (
490+
"Series.replace cannot specify both a dict-like 'to_replace' and a 'value'"
491+
)
490492
with pytest.raises(ValueError, match=msg):
491493
ser.replace(to_replace, value)
492494

0 commit comments

Comments
 (0)