diff --git a/python/cudf/cudf/tests/test_array_ufunc.py b/python/cudf/cudf/tests/test_array_ufunc.py index f1aad1af9e6..e4b4d5020ea 100644 --- a/python/cudf/cudf/tests/test_array_ufunc.py +++ b/python/cudf/cudf/tests/test_array_ufunc.py @@ -1,6 +1,8 @@ # Copyright (c) 2020-2022, NVIDIA CORPORATION. import operator +import warnings +from contextlib import contextmanager from functools import reduce import cupy as cp @@ -17,6 +19,37 @@ ] +@contextmanager +def _hide_ufunc_warnings(ufunc): + # pandas raises warnings for some inputs to the following ufuncs: + name = ufunc.__name__ + if name in { + "arccos", + "arccosh", + "arcsin", + "arctanh", + "fmod", + "log", + "log10", + "log2", + "reciprocal", + }: + with warnings.catch_warnings(): + warnings.filterwarnings( + "ignore", + f"invalid value encountered in {name}", + category=RuntimeWarning, + ) + warnings.filterwarnings( + "ignore", + f"divide by zero encountered in {name}", + category=RuntimeWarning, + ) + yield + else: + yield + + @pytest.mark.parametrize("ufunc", _UFUNCS) @pytest.mark.parametrize("has_nulls", [True, False]) @pytest.mark.parametrize("indexed", [True, False]) @@ -76,7 +109,8 @@ def test_ufunc_series(ufunc, has_nulls, indexed): pytest.xfail(reason="Operation not supported by cupy") raise - expect = ufunc(*(arg.to_pandas() for arg in pandas_args)) + with _hide_ufunc_warnings(ufunc): + expect = ufunc(*(arg.to_pandas() for arg in pandas_args)) try: if ufunc.nout > 1: @@ -256,7 +290,8 @@ def test_ufunc_dataframe(ufunc, has_nulls, indexed): pytest.xfail(reason="Operation not supported by cupy") raise - expect = ufunc(*(arg.to_pandas() for arg in pandas_args)) + with _hide_ufunc_warnings(ufunc): + expect = ufunc(*(arg.to_pandas() for arg in pandas_args)) try: if ufunc.nout > 1: