Skip to content

Commit

Permalink
Add inplace arithmetic operators to MaskedType (#11987)
Browse files Browse the repository at this point in the history
Closes #11887

After merging, we will support syntax like `a += b` inside UDFs used through `DataFrame.apply` and `Series.apply`.

Authors:
  - https://github.com/brandon-b-miller

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

URL: #11987
  • Loading branch information
brandon-b-miller authored Oct 26, 2022
1 parent b7d0115 commit b89c0e2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
7 changes: 7 additions & 0 deletions python/cudf/cudf/core/udf/_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
operator.floordiv,
operator.mod,
operator.pow,
operator.iadd,
operator.isub,
operator.imul,
operator.itruediv,
operator.floordiv,
operator.ipow,
operator.imod,
]

bitwise_ops = [operator.and_, operator.or_, operator.xor]
Expand Down
16 changes: 12 additions & 4 deletions python/cudf/cudf/tests/test_udf_masked_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@ def func(row):
operator.pow,
operator.truediv,
operator.floordiv,
operator.imod,
operator.ipow,
operator.itruediv,
operator.ifloordiv,
}:
# The following tests cases yield undefined behavior:
# - truediv(x, False) because its dividing by zero
Expand All @@ -219,7 +223,7 @@ def func(row):
# Just a single column -> result will be all NA
gdf = cudf.DataFrame({"data": data})

if constant == 1 and op is operator.pow:
if constant == 1 and op in {operator.pow, operator.ipow}:
# The following tests cases yield differing results from pandas:
# - 1**NA
# - True**NA
Expand All @@ -237,7 +241,7 @@ def func(row):

gdf = cudf.DataFrame({"data": data})

if 1 in gdf["data"] and op is operator.pow:
if 1 in gdf["data"] and op in {operator.pow, operator.ipow}:
# In pandas, 1**NA == 1.
pytest.skip()
run_masked_udf_test(func, gdf, check_dtype=False)
Expand Down Expand Up @@ -483,7 +487,7 @@ def func(x):

# Just a single column -> result will be all NA
data = cudf.Series([1, 2, cudf.NA])
if constant is cudf.NA and op is operator.pow:
if constant is cudf.NA and op in {operator.pow, operator.ipow}:
# in pandas, 1**NA == 1. In cudf, 1**NA == 1.
with pytest.xfail():
run_masked_udf_series(func, data, check_dtype=False)
Expand All @@ -499,7 +503,11 @@ def func(x):

# Just a single column -> result will be all NA
data = cudf.Series([1, 2, cudf.NA])
if constant is not cudf.NA and constant == 1 and op is operator.pow:
if (
constant is not cudf.NA
and constant == 1
and op in {operator.pow, operator.ipow}
):
# in pandas, 1**NA == 1. In cudf, 1**NA == 1.
with pytest.xfail():
run_masked_udf_series(func, data, check_dtype=False)
Expand Down

0 comments on commit b89c0e2

Please sign in to comment.