Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add proxy for inplace operations in cudf.pandas #15695

Merged
merged 13 commits into from
May 8, 2024
14 changes: 14 additions & 0 deletions python/cudf/cudf/pandas/fast_slow_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -1083,9 +1083,23 @@ def _replace_closurevars(
# Added on a per-proxy basis
# https://github.com/rapidsai/xdf/pull/306#pullrequestreview-1636155428
# "__hash__",
"__iadd__",
"__iand__",
"__iconcat__",
"__ifloordiv__",
"__ilshift__",
"__imatmul__",
"__imod__",
"__imul__",
"__int__",
"__invert__",
"__ior__",
"__ipow__",
"__irshift__",
"__isub__",
"__iter__",
"__itruediv__",
"__ixor__",
"__le__",
"__len__",
"__lshift__",
Expand Down
57 changes: 57 additions & 0 deletions python/cudf/cudf_pandas_tests/test_cudf_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -1243,6 +1243,63 @@ def my_apply(df, unused):
tm.assert_series_equal(result, expected)


@pytest.mark.parametrize(
"op",
[
"__iadd__",
"__iand__",
"__ifloordiv__",
"__imod__",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

__imatmul__ is implemented for Series, so please test that. This test only appears to cover DataFrame.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 👍

"__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]})

df1 = pd.DataFrame({"a": [10, 11, 12]})
df2 = pd.DataFrame({"a": [1, 2, 3]})

actual = getattr(xdf1, op)(xdf2)
expected = getattr(df1, op)(df2)

tm.assert_equal(actual, expected)


@pytest.mark.parametrize(
"op",
[
"__iadd__",
"__iand__",
"__ifloordiv__",
"__imatmul__",
galipremsagar marked this conversation as resolved.
Show resolved Hide resolved
"__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, op)(xser2)
expected = getattr(ser1, op)(ser2)

tm.assert_equal(actual, expected)


@pytest.mark.parametrize("data", [pd.NaT, 1234, "nat"])
def test_timestamp(data):
xtimestamp = xpd.Timestamp(data)
Expand Down
Loading