Skip to content

Commit c8213d1

Browse files
authored
TST: remove expected warnings for new numexpr version (#62553)
1 parent 72ba35b commit c8213d1

File tree

3 files changed

+33
-9
lines changed

3 files changed

+33
-9
lines changed

pandas/tests/frame/test_arithmetic.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import numpy as np
1212
import pytest
1313

14+
from pandas.compat._optional import import_optional_dependency
15+
1416
import pandas as pd
1517
from pandas import (
1618
DataFrame,
@@ -24,6 +26,7 @@
2426
_check_mixed_float,
2527
_check_mixed_int,
2628
)
29+
from pandas.util.version import Version
2730

2831

2932
@pytest.fixture
@@ -1114,6 +1117,8 @@ def test_binop_other(self, op, value, dtype, switch_numexpr_min_elements):
11141117
(operator.mod, "complex128"),
11151118
}
11161119

1120+
ne = import_optional_dependency("numexpr", errors="ignore")
1121+
ne_warns_on_op = ne is not None and Version(ne.__version__) < Version("2.13.1")
11171122
if (op, dtype) in invalid:
11181123
warn = None
11191124
if (dtype == "<M8[ns]" and op == operator.add) or (
@@ -1142,7 +1147,11 @@ def test_binop_other(self, op, value, dtype, switch_numexpr_min_elements):
11421147

11431148
elif (op, dtype) in skip:
11441149
if op in [operator.add, operator.mul]:
1145-
if expr.USE_NUMEXPR and switch_numexpr_min_elements == 0:
1150+
if (
1151+
expr.USE_NUMEXPR
1152+
and switch_numexpr_min_elements == 0
1153+
and ne_warns_on_op
1154+
):
11461155
warn = UserWarning
11471156
else:
11481157
warn = None

pandas/tests/series/test_arithmetic.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import pytest
1111

1212
from pandas._libs import lib
13+
from pandas.compat._optional import import_optional_dependency
1314

1415
import pandas as pd
1516
from pandas import (
@@ -25,7 +26,7 @@
2526
import pandas._testing as tm
2627
from pandas.core import ops
2728
from pandas.core.computation import expressions as expr
28-
from pandas.core.computation.check import NUMEXPR_INSTALLED
29+
from pandas.util.version import Version
2930

3031

3132
@pytest.fixture(autouse=True, params=[0, 1000000], ids=["numexpr", "python"])
@@ -348,9 +349,12 @@ def test_add_list_to_masked_array(self, val, dtype):
348349

349350
def test_add_list_to_masked_array_boolean(self, request):
350351
# GH#22962
352+
ne = import_optional_dependency("numexpr", errors="ignore")
351353
warning = (
352354
UserWarning
353-
if request.node.callspec.id == "numexpr" and NUMEXPR_INSTALLED
355+
if request.node.callspec.id == "numexpr"
356+
and ne
357+
and Version(ne.__version__) < Version("2.13.1")
354358
else None
355359
)
356360
ser = Series([True, None, False], dtype="boolean")

pandas/tests/test_expressions.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@
44
import numpy as np
55
import pytest
66

7+
from pandas.compat._optional import import_optional_dependency
8+
79
from pandas import option_context
810
import pandas._testing as tm
911
from pandas.core.api import DataFrame
1012
from pandas.core.computation import expressions as expr
13+
from pandas.util.version import Version
1114

1215

1316
@pytest.fixture
@@ -340,35 +343,43 @@ def test_bool_ops_warn_on_arithmetic(self, op_str, opname, monkeypatch):
340343
return
341344

342345
msg = "operator is not supported by numexpr"
346+
ne = import_optional_dependency("numexpr", errors="ignore")
347+
warning = (
348+
UserWarning
349+
if ne
350+
and op_str in {"+", "*"}
351+
and Version(ne.__version__) < Version("2.13.1")
352+
else None
353+
)
343354
with monkeypatch.context() as m:
344355
m.setattr(expr, "_MIN_ELEMENTS", 5)
345356
with option_context("compute.use_numexpr", True):
346-
with tm.assert_produces_warning(UserWarning, match=msg):
357+
with tm.assert_produces_warning(warning, match=msg):
347358
r = f(df, df)
348359
e = fe(df, df)
349360
tm.assert_frame_equal(r, e)
350361

351-
with tm.assert_produces_warning(UserWarning, match=msg):
362+
with tm.assert_produces_warning(warning, match=msg):
352363
r = f(df.a, df.b)
353364
e = fe(df.a, df.b)
354365
tm.assert_series_equal(r, e)
355366

356-
with tm.assert_produces_warning(UserWarning, match=msg):
367+
with tm.assert_produces_warning(warning, match=msg):
357368
r = f(df.a, True)
358369
e = fe(df.a, True)
359370
tm.assert_series_equal(r, e)
360371

361-
with tm.assert_produces_warning(UserWarning, match=msg):
372+
with tm.assert_produces_warning(warning, match=msg):
362373
r = f(False, df.a)
363374
e = fe(False, df.a)
364375
tm.assert_series_equal(r, e)
365376

366-
with tm.assert_produces_warning(UserWarning, match=msg):
377+
with tm.assert_produces_warning(warning, match=msg):
367378
r = f(False, df)
368379
e = fe(False, df)
369380
tm.assert_frame_equal(r, e)
370381

371-
with tm.assert_produces_warning(UserWarning, match=msg):
382+
with tm.assert_produces_warning(warning, match=msg):
372383
r = f(df, True)
373384
e = fe(df, True)
374385
tm.assert_frame_equal(r, e)

0 commit comments

Comments
 (0)