From 4ca9ac83d2b103566d9b053e79b3a787b8ebf7f8 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Tue, 20 Feb 2024 05:13:14 -1000 Subject: [PATCH] Change chained replace inplace test to COW test for pandas 2.2 (#15049) `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: https://github.com/rapidsai/cudf/pull/15049 --- python/cudf/cudf/tests/test_setitem.py | 33 +++++++++----------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/python/cudf/cudf/tests/test_setitem.py b/python/cudf/cudf/tests/test_setitem.py index de0826d61e9..967c1d27fc1 100644 --- a/python/cudf/cudf/tests/test_setitem.py +++ b/python/cudf/cudf/tests/test_setitem.py @@ -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(