Skip to content

Commit 36e9a5d

Browse files
Added extra testcase
1 parent 9617165 commit 36e9a5d

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

pandas/core/internals/blocks.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -731,12 +731,7 @@ def _replace_regex(
731731
replace_regex(new_values, rx, value, mask)
732732

733733
block = self.make_block(new_values)
734-
if (self.ndim == 1 or self.shape[0] == 1) or (
735-
self.ndim == 2 and self.shape[0] != 1
736-
):
737-
return block.convert(numeric=False, copy=False)
738-
else:
739-
return [block]
734+
return block.convert(numeric=False, copy=False)
740735

741736
@final
742737
def replace_list(

pandas/tests/frame/methods/test_replace.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1506,7 +1506,13 @@ def test_regex_replace_scalar(
15061506

15071507
@pytest.mark.parametrize("regex", [False, True])
15081508
def test_replace_regex_dtype_frame(self, regex):
1509-
df = DataFrame({"A": ["0"], "B": ["0"]})
1510-
expected = DataFrame({"A": [1], "B": [1]})
1511-
result = df.replace(to_replace="0", value=1, regex=regex)
1512-
tm.assert_frame_equal(result, expected)
1509+
# GH-48644
1510+
df1 = DataFrame({"A": ["0"], "B": ["0"]})
1511+
expected_df1 = DataFrame({"A": [1], "B": [1]})
1512+
result_df1 = df1.replace(to_replace="0", value=1, regex=regex)
1513+
tm.assert_frame_equal(result_df1, expected_df1)
1514+
1515+
df2 = DataFrame({"A": ["0"], "B": [np.NaN]})
1516+
expected_df2 = DataFrame({"A": [1], "B": [np.NaN]})
1517+
result_df2 = df2.replace(to_replace="0", value=1, regex=regex)
1518+
tm.assert_frame_equal(result_df2, expected_df2)

pandas/tests/series/methods/test_replace.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ def test_pandas_replace_na(self):
516516
tm.assert_series_equal(result, exp)
517517

518518
@pytest.mark.parametrize("regex", [False, True])
519-
def test_replace_regex_dtype(self, regex):
519+
def test_replace_regex_dtype_series(self, regex):
520520
# GH-48644
521521
series = pd.Series(["0"])
522522
expected = pd.Series([1])

0 commit comments

Comments
 (0)