Skip to content

Commit

Permalink
Add proxy for inplace operations in cudf.pandas (#15695)
Browse files Browse the repository at this point in the history
Fixes: #15676 

This PR implements `__iadd__` and `__isub__` methods to allow in-place subtraction and addition operations.

Forks out from #14534

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

Approvers:
  - Bradley Dice (https://github.com/bdice)

URL: #15695
  • Loading branch information
galipremsagar authored May 8, 2024
1 parent 57e534a commit b09e794
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
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
56 changes: 56 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,62 @@ def my_apply(df, unused):
tm.assert_series_equal(result, expected)


@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]})

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__",
"__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

0 comments on commit b09e794

Please sign in to comment.