Skip to content

Commit 011d1d0

Browse files
authored
TST: add test to check dtype after replacing values in categorical Series inplace (#53993)
* TST: add test to check dtype after replacing categorical Series inplace * replace tm.assert_index_equal with tm.assert_series_equal
1 parent 6b4254e commit 011d1d0

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

pandas/tests/series/methods/test_replace.py

+10
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,16 @@ def test_replace_categorical(self, categorical, numeric):
387387
expected = expected.cat.add_categories(2)
388388
tm.assert_series_equal(expected, result)
389389

390+
@pytest.mark.parametrize(
391+
"data, data_exp", [(["a", "b", "c"], ["b", "b", "c"]), (["a"], ["b"])]
392+
)
393+
def test_replace_categorical_inplace(self, data, data_exp):
394+
# GH 53358
395+
result = pd.Series(data, dtype="category")
396+
result.replace(to_replace="a", value="b", inplace=True)
397+
expected = pd.Series(data_exp, dtype="category")
398+
tm.assert_series_equal(result, expected)
399+
390400
def test_replace_categorical_single(self):
391401
# GH 26988
392402
dti = pd.date_range("2016-01-01", periods=3, tz="US/Pacific")

0 commit comments

Comments
 (0)