Skip to content

Commit 5fc3df3

Browse files
authored
[backport 2.3.x] TST: remove expected warnings for new numexpr version (#62553) (#62557)
1 parent 9c8bc3e commit 5fc3df3

File tree

3 files changed

+60
-34
lines changed

3 files changed

+60
-34
lines changed

pandas/tests/frame/test_arithmetic.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import pytest
1313

1414
from pandas.compat import HAS_PYARROW
15+
from pandas.compat._optional import import_optional_dependency
1516
import pandas.util._test_decorators as td
1617

1718
import pandas as pd
@@ -27,6 +28,7 @@
2728
_check_mixed_float,
2829
_check_mixed_int,
2930
)
31+
from pandas.util.version import Version
3032

3133

3234
@pytest.fixture
@@ -1092,6 +1094,8 @@ def test_binop_other(self, op, value, dtype, switch_numexpr_min_elements):
10921094
(operator.mod, "complex128"),
10931095
}
10941096

1097+
ne = import_optional_dependency("numexpr", errors="ignore")
1098+
ne_warns_on_op = ne is not None and Version(ne.__version__) < Version("2.13.1")
10951099
if (op, dtype) in invalid:
10961100
warn = None
10971101
if (dtype == "<M8[ns]" and op == operator.add) or (
@@ -1120,7 +1124,11 @@ def test_binop_other(self, op, value, dtype, switch_numexpr_min_elements):
11201124

11211125
elif (op, dtype) in skip:
11221126
if op in [operator.add, operator.mul]:
1123-
if expr.USE_NUMEXPR and switch_numexpr_min_elements == 0:
1127+
if (
1128+
expr.USE_NUMEXPR
1129+
and switch_numexpr_min_elements == 0
1130+
and ne_warns_on_op
1131+
):
11241132
# "evaluating in Python space because ..."
11251133
warn = UserWarning
11261134
else:

pandas/tests/series/test_arithmetic.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
from pandas._libs import lib
1313
from pandas._libs.tslibs import IncompatibleFrequency
14+
from pandas.compat._optional import import_optional_dependency
1415

1516
import pandas as pd
1617
from pandas import (
@@ -26,7 +27,7 @@
2627
import pandas._testing as tm
2728
from pandas.core import ops
2829
from pandas.core.computation import expressions as expr
29-
from pandas.core.computation.check import NUMEXPR_INSTALLED
30+
from pandas.util.version import Version
3031

3132

3233
@pytest.fixture(autouse=True, params=[0, 1000000], ids=["numexpr", "python"])
@@ -353,9 +354,12 @@ def test_add_list_to_masked_array(self, val, dtype):
353354

354355
def test_add_list_to_masked_array_boolean(self, request):
355356
# GH#22962
357+
ne = import_optional_dependency("numexpr", errors="ignore")
356358
warning = (
357359
UserWarning
358-
if request.node.callspec.id == "numexpr" and NUMEXPR_INSTALLED
360+
if request.node.callspec.id == "numexpr"
361+
and ne
362+
and Version(ne.__version__) < Version("2.13.1")
359363
else None
360364
)
361365
ser = Series([True, None, False], dtype="boolean")

pandas/tests/test_expressions.py

Lines changed: 45 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
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 (
@@ -12,6 +14,7 @@
1214
Series,
1315
)
1416
from pandas.core.computation import expressions as expr
17+
from pandas.util.version import Version
1518

1619

1720
@pytest.fixture
@@ -324,7 +327,7 @@ def test_bool_ops_raise_on_arithmetic(self, op_str, opname):
324327
@pytest.mark.parametrize(
325328
"op_str,opname", [("+", "add"), ("*", "mul"), ("-", "sub")]
326329
)
327-
def test_bool_ops_warn_on_arithmetic(self, op_str, opname):
330+
def test_bool_ops_warn_on_arithmetic(self, op_str, opname, monkeypatch):
328331
n = 10
329332
df = DataFrame(
330333
{
@@ -343,36 +346,47 @@ def test_bool_ops_warn_on_arithmetic(self, op_str, opname):
343346
# raises TypeError
344347
return
345348

346-
with tm.use_numexpr(True, min_elements=5):
347-
with tm.assert_produces_warning():
348-
r = f(df, df)
349-
e = fe(df, df)
350-
tm.assert_frame_equal(r, e)
351-
352-
with tm.assert_produces_warning():
353-
r = f(df.a, df.b)
354-
e = fe(df.a, df.b)
355-
tm.assert_series_equal(r, e)
356-
357-
with tm.assert_produces_warning():
358-
r = f(df.a, True)
359-
e = fe(df.a, True)
360-
tm.assert_series_equal(r, e)
361-
362-
with tm.assert_produces_warning():
363-
r = f(False, df.a)
364-
e = fe(False, df.a)
365-
tm.assert_series_equal(r, e)
366-
367-
with tm.assert_produces_warning():
368-
r = f(False, df)
369-
e = fe(False, df)
370-
tm.assert_frame_equal(r, e)
371-
372-
with tm.assert_produces_warning():
373-
r = f(df, True)
374-
e = fe(df, True)
375-
tm.assert_frame_equal(r, e)
349+
msg = "operator is not supported by numexpr"
350+
ne = import_optional_dependency("numexpr", errors="ignore")
351+
warning = (
352+
UserWarning
353+
if ne
354+
and op_str in {"+", "*"}
355+
and Version(ne.__version__) < Version("2.13.1")
356+
else None
357+
)
358+
with monkeypatch.context() as m:
359+
m.setattr(expr, "_MIN_ELEMENTS", 5)
360+
with option_context("compute.use_numexpr", True):
361+
with tm.assert_produces_warning(warning, match=msg):
362+
r = f(df, df)
363+
e = fe(df, df)
364+
tm.assert_frame_equal(r, e)
365+
366+
with tm.assert_produces_warning(warning, match=msg):
367+
r = f(df.a, df.b)
368+
e = fe(df.a, df.b)
369+
tm.assert_series_equal(r, e)
370+
371+
with tm.assert_produces_warning(warning, match=msg):
372+
r = f(df.a, True)
373+
e = fe(df.a, True)
374+
tm.assert_series_equal(r, e)
375+
376+
with tm.assert_produces_warning(warning, match=msg):
377+
r = f(False, df.a)
378+
e = fe(False, df.a)
379+
tm.assert_series_equal(r, e)
380+
381+
with tm.assert_produces_warning(warning, match=msg):
382+
r = f(False, df)
383+
e = fe(False, df)
384+
tm.assert_frame_equal(r, e)
385+
386+
with tm.assert_produces_warning(warning, match=msg):
387+
r = f(df, True)
388+
e = fe(df, True)
389+
tm.assert_frame_equal(r, e)
376390

377391
@pytest.mark.parametrize(
378392
"test_input,expected",

0 commit comments

Comments
 (0)