From b2940915a55cdb3c839327e414a33d3cf4f95889 Mon Sep 17 00:00:00 2001 From: Bradley Dice Date: Thu, 17 Feb 2022 16:25:57 -0600 Subject: [PATCH 1/3] Hide warnings from deprecated functions. --- python/cudf/cudf/tests/test_binops.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/python/cudf/cudf/tests/test_binops.py b/python/cudf/cudf/tests/test_binops.py index 02ca7a0cd58..4b3a5aeacca 100644 --- a/python/cudf/cudf/tests/test_binops.py +++ b/python/cudf/cudf/tests/test_binops.py @@ -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 @@ -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, @@ -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) @@ -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: From 522c09efbbda01a2927e5e00e8d73b40204d6cba Mon Sep 17 00:00:00 2001 From: Bradley Dice Date: Thu, 17 Feb 2022 16:32:57 -0600 Subject: [PATCH 2/3] Reverse equality check to use pandas/cudf logic instead of numpy scalar logic. --- python/cudf/cudf/tests/test_binops.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/cudf/cudf/tests/test_binops.py b/python/cudf/cudf/tests/test_binops.py index 4b3a5aeacca..e486ee9725f 100644 --- a/python/cudf/cudf/tests/test_binops.py +++ b/python/cudf/cudf/tests/test_binops.py @@ -1763,8 +1763,8 @@ def test_binops_with_lhs_numpy_scalar(frame, dtype): else: val = cudf.dtype(dtype).type(4) - expected = val == data.to_pandas() - got = val == data + expected = data.to_pandas() == val + got = data == val # In case of index, expected would be a numpy array if isinstance(data, cudf.BaseIndex): From 1fef1790eb7fab5bc63eda7d502baf755d5d1a75 Mon Sep 17 00:00:00 2001 From: Bradley Dice Date: Wed, 23 Feb 2022 15:36:43 -0600 Subject: [PATCH 3/3] Add comment about __eq__ operator dispatch. Co-authored-by: Vyas Ramasubramani --- python/cudf/cudf/tests/test_binops.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/python/cudf/cudf/tests/test_binops.py b/python/cudf/cudf/tests/test_binops.py index e486ee9725f..21168cc0885 100644 --- a/python/cudf/cudf/tests/test_binops.py +++ b/python/cudf/cudf/tests/test_binops.py @@ -1763,6 +1763,8 @@ def test_binops_with_lhs_numpy_scalar(frame, dtype): else: val = cudf.dtype(dtype).type(4) + # 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