Skip to content

Commit f736d72

Browse files
Filter ufunc related warnings in pytests (#14652)
This PR ignores ufunc runtime warnings that show up in eval API and setitem deprecation warnings. On pandas_2.0_feature_branch: = 260 failed, 101179 passed, 2091 skipped, 954 xfailed, 312 xpassed in 1104.58s (0:18:24) = This PR: = 211 failed, 101228 passed, 2091 skipped, 954 xfailed, 312 xpassed in 1095.49s (0:18:15) =
1 parent 194e487 commit f736d72

File tree

2 files changed

+95
-6
lines changed

2 files changed

+95
-6
lines changed

python/cudf/cudf/tests/test_array_ufunc.py

Lines changed: 63 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@
1010
import pytest
1111

1212
import cudf
13-
from cudf.core._compat import PANDAS_GE_150, PANDAS_GE_200
14-
from cudf.testing._utils import assert_eq, set_random_null_mask_inplace
13+
from cudf.core._compat import PANDAS_GE_150, PANDAS_GE_200, PANDAS_GE_210
14+
from cudf.testing._utils import (
15+
assert_eq,
16+
set_random_null_mask_inplace,
17+
expect_warning_if,
18+
)
1519

1620
_UFUNCS = [
1721
obj
@@ -47,6 +51,21 @@ def _hide_ufunc_warnings(ufunc):
4751
category=RuntimeWarning,
4852
)
4953
yield
54+
elif name in {
55+
"bitwise_and",
56+
"bitwise_or",
57+
"bitwise_xor",
58+
}:
59+
with warnings.catch_warnings():
60+
warnings.filterwarnings(
61+
"ignore",
62+
"Operation between non boolean Series with different "
63+
"indexes will no longer return a boolean result in "
64+
"a future version. Cast both Series to object type "
65+
"to maintain the prior behavior.",
66+
category=FutureWarning,
67+
)
68+
yield
5069
else:
5170
yield
5271

@@ -217,7 +236,27 @@ def test_ufunc_series(request, ufunc, has_nulls, indexed):
217236
assert_eq(g, e, check_exact=False)
218237
else:
219238
if has_nulls:
220-
expect[mask] = np.nan
239+
with expect_warning_if(
240+
PANDAS_GE_210
241+
and fname
242+
in (
243+
"isfinite",
244+
"isinf",
245+
"isnan",
246+
"logical_and",
247+
"logical_not",
248+
"logical_or",
249+
"logical_xor",
250+
"signbit",
251+
"equal",
252+
"greater",
253+
"greater_equal",
254+
"less",
255+
"less_equal",
256+
"not_equal",
257+
)
258+
):
259+
expect[mask] = np.nan
221260
assert_eq(got, expect, check_exact=False)
222261

223262

@@ -443,5 +482,25 @@ def test_ufunc_dataframe(request, ufunc, has_nulls, indexed):
443482
assert_eq(g, e, check_exact=False)
444483
else:
445484
if has_nulls:
446-
expect[mask] = np.nan
485+
with expect_warning_if(
486+
PANDAS_GE_210
487+
and fname
488+
in (
489+
"isfinite",
490+
"isinf",
491+
"isnan",
492+
"logical_and",
493+
"logical_not",
494+
"logical_or",
495+
"logical_xor",
496+
"signbit",
497+
"equal",
498+
"greater",
499+
"greater_equal",
500+
"less",
501+
"less_equal",
502+
"not_equal",
503+
)
504+
):
505+
expect[mask] = np.nan
447506
assert_eq(got, expect, check_exact=False)

python/cudf/cudf/tests/test_dataframe.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import re
1010
import string
1111
import textwrap
12+
import warnings
13+
from contextlib import contextmanager
1214
from collections import OrderedDict, defaultdict, namedtuple
1315
from copy import copy
1416

@@ -65,6 +67,32 @@
6567
pytest_xfail = pytest.mark.skipif
6668

6769

70+
@contextmanager
71+
def _hide_ufunc_warnings(eval_str):
72+
# pandas raises warnings for some inputs to the following ufuncs:
73+
if any(
74+
x in eval_str
75+
for x in {
76+
"arctanh",
77+
"log",
78+
}
79+
):
80+
with warnings.catch_warnings():
81+
warnings.filterwarnings(
82+
"ignore",
83+
"invalid value encountered in",
84+
category=RuntimeWarning,
85+
)
86+
warnings.filterwarnings(
87+
"ignore",
88+
"divide by zero encountered in",
89+
category=RuntimeWarning,
90+
)
91+
yield
92+
else:
93+
yield
94+
95+
6896
def test_init_via_list_of_tuples():
6997
data = [
7098
(5, "cats", "jump", np.nan),
@@ -10071,7 +10099,8 @@ def df_eval(request):
1007110099
)
1007210100
def test_dataframe_eval(df_eval, expr, dtype):
1007310101
df_eval = df_eval.astype(dtype)
10074-
expect = df_eval.to_pandas().eval(expr)
10102+
with _hide_ufunc_warnings(expr):
10103+
expect = df_eval.to_pandas().eval(expr)
1007510104
got = df_eval.eval(expr)
1007610105
# In the specific case where the evaluated expression is a unary function
1007710106
# of a single column with no nesting, pandas will retain the name. This
@@ -10081,7 +10110,8 @@ def test_dataframe_eval(df_eval, expr, dtype):
1008110110
# Test inplace
1008210111
if re.search("[^=><]=[^=]", expr) is not None:
1008310112
pdf_eval = df_eval.to_pandas()
10084-
pdf_eval.eval(expr, inplace=True)
10113+
with _hide_ufunc_warnings(expr):
10114+
pdf_eval.eval(expr, inplace=True)
1008510115
df_eval.eval(expr, inplace=True)
1008610116
assert_eq(pdf_eval, df_eval)
1008710117

0 commit comments

Comments
 (0)