From 71e252931afb9b8e29849fdb6993be2fcdebb610 Mon Sep 17 00:00:00 2001 From: galipremsagar Date: Tue, 7 May 2024 20:16:04 +0000 Subject: [PATCH 1/8] implement isub and iadd --- python/cudf/cudf/pandas/fast_slow_proxy.py | 18 ++++++++++++++++++ .../cudf/cudf_pandas_tests/test_cudf_pandas.py | 14 ++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/python/cudf/cudf/pandas/fast_slow_proxy.py b/python/cudf/cudf/pandas/fast_slow_proxy.py index 835cfa89133..f3b9e17131c 100644 --- a/python/cudf/cudf/pandas/fast_slow_proxy.py +++ b/python/cudf/cudf/pandas/fast_slow_proxy.py @@ -681,6 +681,24 @@ def __matmul__(self, other): def __rmatmul__(self, other): return _fast_slow_function_call(operator.matmul, other, self)[0] + def __isub__(self, other): + return _fast_slow_function_call( + lambda x, y: x.__isub__(y) + if hasattr(x, "__isub__") + else NotImplemented, + self, + other, + )[0] + + def __idd__(self, other): + return _fast_slow_function_call( + lambda x, y: x.__iadd__(y) + if hasattr(x, "__iadd__") + else NotImplemented, + self, + other, + )[0] + class _FinalProxy(_FastSlowProxy): """ diff --git a/python/cudf/cudf_pandas_tests/test_cudf_pandas.py b/python/cudf/cudf_pandas_tests/test_cudf_pandas.py index dff735cfd05..350ade57fb3 100644 --- a/python/cudf/cudf_pandas_tests/test_cudf_pandas.py +++ b/python/cudf/cudf_pandas_tests/test_cudf_pandas.py @@ -1228,3 +1228,17 @@ def my_apply(df, unused): result = df.apply(my_apply, axis=1, unused=True) expected = xpd.Series([1]) tm.assert_series_equal(result, expected) + + +@pytest.mark.parametrize("op", [operator.isub, operator.iadd]) +def test_isub_iadd(op): + xarray1 = xpd.array([10, 11, 12]) + xarray2 = xpd.array([1, 2, 3]) + + array1 = pd.array([10, 11, 12]) + array2 = pd.array([1, 2, 3]) + + xarray1 = op(xarray1, xarray2) + array1 = op(array1, array2) + + tm.assert_equal(xarray1, array1) From b566edf8e7ccbd42193b920b88f8bd24da6a79bb Mon Sep 17 00:00:00 2001 From: galipremsagar Date: Wed, 8 May 2024 19:16:51 +0000 Subject: [PATCH 2/8] Re-order --- python/cudf/cudf/pandas/fast_slow_proxy.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/python/cudf/cudf/pandas/fast_slow_proxy.py b/python/cudf/cudf/pandas/fast_slow_proxy.py index a977c01d272..efd3c9d7d5b 100644 --- a/python/cudf/cudf/pandas/fast_slow_proxy.py +++ b/python/cudf/cudf/pandas/fast_slow_proxy.py @@ -1083,9 +1083,19 @@ def _replace_closurevars( # Added on a per-proxy basis # https://github.com/rapidsai/xdf/pull/306#pullrequestreview-1636155428 # "__hash__", + "__iadd__", + "__iand__", + "__ifloordiv__", + "__imod__", + "__imul__", "__int__", "__invert__", + "__ior__", + "__ipow__", + "__isub__", "__iter__", + "__itruediv__", + "__ixor__", "__le__", "__len__", "__lshift__", @@ -1122,14 +1132,4 @@ def _replace_closurevars( "__sub__", "__truediv__", "__xor__", - "__iadd__", - "__iand__", - "__ifloordiv__", - "__imod__", - "__imul__", - "__ior__", - "__ipow__", - "__isub__", - "__itruediv__", - "__ixor__", } From 2edf54de0fb5ba11e3b8503851f1b66d94e1ebef Mon Sep 17 00:00:00 2001 From: galipremsagar Date: Wed, 8 May 2024 19:25:33 +0000 Subject: [PATCH 3/8] update tests --- .../cudf_pandas_tests/test_cudf_pandas.py | 32 +++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/python/cudf/cudf_pandas_tests/test_cudf_pandas.py b/python/cudf/cudf_pandas_tests/test_cudf_pandas.py index 087eebd5d2d..bebe84e5a08 100644 --- a/python/cudf/cudf_pandas_tests/test_cudf_pandas.py +++ b/python/cudf/cudf_pandas_tests/test_cudf_pandas.py @@ -1243,18 +1243,32 @@ def my_apply(df, unused): tm.assert_series_equal(result, expected) -@pytest.mark.parametrize("op", [operator.isub, operator.iadd]) -def test_isub_iadd(op): - xarray1 = xpd.array([10, 11, 12]) - xarray2 = xpd.array([1, 2, 3]) +@pytest.mark.parametrize( + "op", + [ + "__iadd__", + "__iand__", + "__ifloordiv__", + "__imod__", + "__imul__", + "__ior__", + "__ipow__", + "__isub__", + "__itruediv__", + "__ixor__", + ], +) +def test_inplace_ops(op): + xdf1 = xpd.DataFrame({"a": [10, 11, 12]}) + xdf2 = xpd.DataFrame({"a": [1, 2, 3]}) - array1 = pd.array([10, 11, 12]) - array2 = pd.array([1, 2, 3]) + df1 = pd.DataFrame({"a": [10, 11, 12]}) + df2 = pd.DataFrame({"a": [1, 2, 3]}) - xarray1 = op(xarray1, xarray2) - array1 = op(array1, array2) + xdf1 = getattr(xdf1, op)(xdf2) + df1 = getattr(df1, op)(df2) - tm.assert_equal(xarray1, array1) + tm.assert_equal(xdf1, df1) @pytest.mark.parametrize("data", [pd.NaT, 1234, "nat"]) From 985f0e1fdb3197f519be3b00c52389808d21a658 Mon Sep 17 00:00:00 2001 From: GALI PREM SAGAR Date: Wed, 8 May 2024 14:48:35 -0500 Subject: [PATCH 4/8] Update python/cudf/cudf/pandas/fast_slow_proxy.py Co-authored-by: Bradley Dice --- python/cudf/cudf/pandas/fast_slow_proxy.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/python/cudf/cudf/pandas/fast_slow_proxy.py b/python/cudf/cudf/pandas/fast_slow_proxy.py index efd3c9d7d5b..f91cdeac149 100644 --- a/python/cudf/cudf/pandas/fast_slow_proxy.py +++ b/python/cudf/cudf/pandas/fast_slow_proxy.py @@ -1085,13 +1085,17 @@ def _replace_closurevars( # "__hash__", "__iadd__", "__iand__", + "__iconcat__", "__ifloordiv__", + "__ilshift__", + "__imatmul__", "__imod__", "__imul__", "__int__", "__invert__", "__ior__", "__ipow__", + "__irshift__", "__isub__", "__iter__", "__itruediv__", From eb0fc9d115a3c83e87fbf458c388bee747093643 Mon Sep 17 00:00:00 2001 From: GALI PREM SAGAR Date: Wed, 8 May 2024 14:48:57 -0500 Subject: [PATCH 5/8] Update python/cudf/cudf_pandas_tests/test_cudf_pandas.py Co-authored-by: Bradley Dice --- python/cudf/cudf_pandas_tests/test_cudf_pandas.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/python/cudf/cudf_pandas_tests/test_cudf_pandas.py b/python/cudf/cudf_pandas_tests/test_cudf_pandas.py index bebe84e5a08..feccc5fa142 100644 --- a/python/cudf/cudf_pandas_tests/test_cudf_pandas.py +++ b/python/cudf/cudf_pandas_tests/test_cudf_pandas.py @@ -1265,10 +1265,10 @@ def test_inplace_ops(op): df1 = pd.DataFrame({"a": [10, 11, 12]}) df2 = pd.DataFrame({"a": [1, 2, 3]}) - xdf1 = getattr(xdf1, op)(xdf2) - df1 = getattr(df1, op)(df2) + actual = getattr(xdf1, op)(xdf2) + expected = getattr(df1, op)(df2) - tm.assert_equal(xdf1, df1) + tm.assert_equal(actual, expected) @pytest.mark.parametrize("data", [pd.NaT, 1234, "nat"]) From 831cf114705e52804311fd2eddfa6a7d06befd3e Mon Sep 17 00:00:00 2001 From: GALI PREM SAGAR Date: Wed, 8 May 2024 14:51:54 -0500 Subject: [PATCH 6/8] Update test_cudf_pandas.py --- python/cudf/cudf_pandas_tests/test_cudf_pandas.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/python/cudf/cudf_pandas_tests/test_cudf_pandas.py b/python/cudf/cudf_pandas_tests/test_cudf_pandas.py index feccc5fa142..f1d9a56c7a6 100644 --- a/python/cudf/cudf_pandas_tests/test_cudf_pandas.py +++ b/python/cudf/cudf_pandas_tests/test_cudf_pandas.py @@ -1271,6 +1271,19 @@ def test_inplace_ops(op): tm.assert_equal(actual, expected) +def test_inplace_matmul_series(op): + xser1 = xpd.Series([10, 11, 12]) + xser2 = xpd.Series([1, 2, 3]) + + ser1 = pd.Series([10, 11, 12]) + ser2 = pd.Series([1, 2, 3]) + + actual = getattr(xser1, "__imatmul__")(xser2) + expected = getattr(ser1, "__imatmul__")(ser2) + + tm.assert_equal(actual, expected) + + @pytest.mark.parametrize("data", [pd.NaT, 1234, "nat"]) def test_timestamp(data): xtimestamp = xpd.Timestamp(data) From 92b4697da1c397d722fe4d8d7cc4b80981cf2f92 Mon Sep 17 00:00:00 2001 From: GALI PREM SAGAR Date: Wed, 8 May 2024 14:55:13 -0500 Subject: [PATCH 7/8] Update test_cudf_pandas.py --- .../cudf_pandas_tests/test_cudf_pandas.py | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/python/cudf/cudf_pandas_tests/test_cudf_pandas.py b/python/cudf/cudf_pandas_tests/test_cudf_pandas.py index f1d9a56c7a6..04dc533b6d3 100644 --- a/python/cudf/cudf_pandas_tests/test_cudf_pandas.py +++ b/python/cudf/cudf_pandas_tests/test_cudf_pandas.py @@ -1271,15 +1271,31 @@ def test_inplace_ops(op): tm.assert_equal(actual, expected) -def test_inplace_matmul_series(op): +@pytest.mark.parametrize( + "op", + [ + "__iadd__", + "__iand__", + "__ifloordiv__", + "__imatmul__", + "__imod__", + "__imul__", + "__ior__", + "__ipow__", + "__isub__", + "__itruediv__", + "__ixor__", + ], +) +def test_inplace_ops_series(op): xser1 = xpd.Series([10, 11, 12]) xser2 = xpd.Series([1, 2, 3]) ser1 = pd.Series([10, 11, 12]) ser2 = pd.Series([1, 2, 3]) - actual = getattr(xser1, "__imatmul__")(xser2) - expected = getattr(ser1, "__imatmul__")(ser2) + actual = getattr(xser1, op)(xser2) + expected = getattr(ser1, op)(ser2) tm.assert_equal(actual, expected) From b5379eb53e306f898a64d2c44f0fbc8f0aa4d172 Mon Sep 17 00:00:00 2001 From: GALI PREM SAGAR Date: Wed, 8 May 2024 15:03:00 -0500 Subject: [PATCH 8/8] Update python/cudf/cudf_pandas_tests/test_cudf_pandas.py --- python/cudf/cudf_pandas_tests/test_cudf_pandas.py | 1 - 1 file changed, 1 deletion(-) diff --git a/python/cudf/cudf_pandas_tests/test_cudf_pandas.py b/python/cudf/cudf_pandas_tests/test_cudf_pandas.py index 04dc533b6d3..dcba1edd5fe 100644 --- a/python/cudf/cudf_pandas_tests/test_cudf_pandas.py +++ b/python/cudf/cudf_pandas_tests/test_cudf_pandas.py @@ -1277,7 +1277,6 @@ def test_inplace_ops(op): "__iadd__", "__iand__", "__ifloordiv__", - "__imatmul__", "__imod__", "__imul__", "__ior__",