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

Fix warnings in test_binops.py. #10327

Merged
merged 3 commits into from
Feb 23, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 28 additions & 4 deletions python/cudf/cudf/tests/test_binops.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import decimal
import operator
import random
from contextlib import contextmanager
from itertools import combinations_with_replacement, product

import cupy as cp
Expand All @@ -26,6 +27,24 @@

STRING_TYPES = {"str"}


@contextmanager
def _hide_deprecated_ops_warnings(func, lhs, rhs):
if func in {
cudf.logical_and,
cudf.logical_or,
cudf.remainder,
} and isinstance(lhs, cudf.Series):
name = func.__name__
with pytest.warns(
FutureWarning,
match=f"Series.{name} is deprecated and will be removed.",
):
yield
else:
yield


_binops = [
operator.add,
operator.sub,
Expand Down Expand Up @@ -170,7 +189,8 @@ def test_series_logical_binop(lhstype, rhstype, binop, cubinop):
arr2 = arr2 * (np.random.random(10) * 100).astype(rhstype)
sr2 = Series(arr2)

result = cubinop(sr1, sr2)
with _hide_deprecated_ops_warnings(cubinop, sr1, sr2):
result = cubinop(sr1, sr2)
expect = binop(arr1, arr2)

utils.assert_eq(result, expect)
Expand Down Expand Up @@ -955,7 +975,9 @@ def test_ufunc_ops(lhs, rhs, ops):
curhs = rhs

expect = np_op(lhs, rhs)
got = cu_op(culhs, curhs)
with _hide_deprecated_ops_warnings(cu_op, culhs, curhs):
got = cu_op(culhs, curhs)

if np.isscalar(expect):
assert got == expect
else:
Expand Down Expand Up @@ -1741,8 +1763,10 @@ def test_binops_with_lhs_numpy_scalar(frame, dtype):
else:
val = cudf.dtype(dtype).type(4)

expected = val == data.to_pandas()
got = val == data
# Compare equality with series on left side to dispatch to the pandas/cudf
# __eq__ operator and avoid a DeprecationWarning from numpy.
expected = data.to_pandas() == val
got = data == val
bdice marked this conversation as resolved.
Show resolved Hide resolved

# In case of index, expected would be a numpy array
if isinstance(data, cudf.BaseIndex):
Expand Down