Skip to content

Commit 37f6edb

Browse files
committed
fix replacer's dtypes not respected for frame replace
1 parent b4807ca commit 37f6edb

File tree

3 files changed

+4
-2
lines changed

3 files changed

+4
-2
lines changed

pandas/core/internals/blocks.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2833,6 +2833,8 @@ def _replace_coerce(
28332833
if convert:
28342834
block = [b.convert(numeric=False, copy=True) for b in block]
28352835
return block
2836+
if convert:
2837+
return [self.convert(numeric=False, copy=True)]
28362838
return self
28372839

28382840

pandas/core/internals/managers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ def comp(s, regex=False):
632632
convert=convert,
633633
regex=regex,
634634
)
635-
if m.any():
635+
if m.any() or convert:
636636
new_rb = _extend_blocks(result, new_rb)
637637
else:
638638
new_rb.append(b)

pandas/tests/frame/test_replace.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1307,6 +1307,6 @@ def test_replace_method(self, to_replace, method, expected):
13071307
def test_replace_replacer_dtype(self, replacer):
13081308
# GH26632
13091309
df = pd.DataFrame(["a"])
1310-
result = df.replace({"a": replacer})
1310+
result = df.replace({"a": replacer, "b": replacer})
13111311
expected = pd.DataFrame([replacer])
13121312
tm.assert_frame_equal(result, expected)

0 commit comments

Comments
 (0)