Skip to content

Commit

Permalink
Change chained replace inplace test to COW test for pandas 2.2 (#15049)
Browse files Browse the repository at this point in the history
`test_setitem_dataframe_series_inplace` failed with pandas 2.2 because it exhibits a chained indexing behavior that raised a `FutureWarning` in pandas 2.2 and will raise in 3.0. I refactored the test to test cudf copy on write to exhibit the 3.0 behavior, but it still seems to allow this chained indexing behavior, so xfailed it for now.

Authors:
  - Matthew Roeschke (https://github.com/mroeschke)

Approvers:
  - GALI PREM SAGAR (https://github.com/galipremsagar)

URL: #15049
  • Loading branch information
mroeschke authored Feb 20, 2024
1 parent f6c00ff commit 4ca9ac8
Showing 1 changed file with 11 additions and 22 deletions.
33 changes: 11 additions & 22 deletions python/cudf/cudf/tests/test_setitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,34 +118,23 @@ def test_series_setitem_singleton_range():
assert_eq(sr, psr, check_dtype=True)


@pytest.mark.xfail(reason="Copy-on-Write should make a copy")
@pytest.mark.parametrize(
"df",
"index",
[
pd.DataFrame(
{"a": [1, 2, 3]},
index=pd.MultiIndex.from_frame(
pd.DataFrame({"b": [3, 2, 1], "c": ["a", "b", "c"]})
),
pd.MultiIndex.from_frame(
pd.DataFrame({"b": [3, 2, 1], "c": ["a", "b", "c"]})
),
pd.DataFrame({"a": [1, 2, 3]}, index=["a", "b", "c"]),
["a", "b", "c"],
],
)
def test_setitem_dataframe_series_inplace(df):
pdf = df.copy(deep=True)
gdf = cudf.from_pandas(pdf)

pdf["a"].replace(1, 500, inplace=True)
gdf["a"].replace(1, 500, inplace=True)

assert_eq(pdf, gdf)

psr_a = pdf["a"]
gsr_a = gdf["a"]

psr_a.replace(500, 501, inplace=True)
gsr_a.replace(500, 501, inplace=True)
def test_setitem_dataframe_series_inplace(index):
gdf = cudf.DataFrame({"a": [1, 2, 3]}, index=index)
expected = gdf.copy()
with cudf.option_context("copy_on_write", True):
gdf["a"].replace(1, 500, inplace=True)

assert_eq(pdf, gdf)
assert_eq(expected, gdf)


@pytest.mark.parametrize(
Expand Down

0 comments on commit 4ca9ac8

Please sign in to comment.