Skip to content

Commit

Permalink
Hide warnings from pandas in test_array_ufunc.py. (#10324)
Browse files Browse the repository at this point in the history
This PR hides pandas warnings in `test_array_ufunc.py`. (I am working through one test file at a time so we can enable `-Werr` in the future.) These warnings come from specific functions like `arccos` for which the provided integer inputs are out-of-range. It is fine for us to hide these warnings because they do not come from cudf.

Alternatives and why I chose against them:
- Why not limit the test data input to be in the domain of the ufunc? Limiting data inputs would hide the warning. However, it would decrease our coverage that ensures cudf and pandas agree on those results for values outside the domain of the ufunc (particularly trigonometric functions). It would additionally require inputs to be generated based on the ufunc, which would be lengthy.
- Why not make cudf raise a warning and ensure that pandas/cudf agree on warning behavior? I chose against this because we generally avoid data introspection in cudf, and this would involve a significantly more complex approach to ufunc execution.

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

Approvers:
  - GALI PREM SAGAR (https://github.com/galipremsagar)
  - Vyas Ramasubramani (https://github.com/vyasr)

URL: #10324
  • Loading branch information
bdice authored Feb 17, 2022
1 parent d48dd6f commit b28bad6
Showing 1 changed file with 37 additions and 2 deletions.
39 changes: 37 additions & 2 deletions python/cudf/cudf/tests/test_array_ufunc.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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])
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit b28bad6

Please sign in to comment.