Skip to content

Commit 66f52c7

Browse files
committed
add and mul operations do not issue a numexpr warning as of version 2.13.1.
Define NUMEXPR_VERSION in computation.check and use this to switch related tests on/off
1 parent 947ed16 commit 66f52c7

File tree

4 files changed

+26
-7
lines changed

4 files changed

+26
-7
lines changed

pandas/core/computation/check.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
from __future__ import annotations
22

3+
import re
4+
35
from pandas.compat._optional import import_optional_dependency
46

57
ne = import_optional_dependency("numexpr", errors="warn")
68
NUMEXPR_INSTALLED = ne is not None
7-
8-
__all__ = ["NUMEXPR_INSTALLED"]
9+
if NUMEXPR_INSTALLED:
10+
try:
11+
NUMEXPR_VERSION = tuple(map(int, re.findall(r"(\d+)", ne.__version__)))
12+
except Exception:
13+
NUMEXPR_VERSION = None
14+
else:
15+
NUMEXPR_VERSION = None

pandas/tests/frame/test_arithmetic.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
)
2121
import pandas._testing as tm
2222
from pandas.core.computation import expressions as expr
23+
from pandas.core.computation.check import NUMEXPR_VERSION
2324
from pandas.tests.frame.common import (
2425
_check_mixed_float,
2526
_check_mixed_int,
@@ -1095,9 +1096,12 @@ def test_binop_other(self, op, value, dtype, switch_numexpr_min_elements):
10951096
skip = {
10961097
(operator.truediv, "bool"),
10971098
(operator.pow, "bool"),
1098-
(operator.add, "bool"),
1099-
(operator.mul, "bool"),
11001099
}
1100+
if NUMEXPR_VERSION and NUMEXPR_VERSION <= (2, 13, 0):
1101+
skip |= {
1102+
(operator.add, "bool"),
1103+
(operator.mul, "bool"),
1104+
}
11011105

11021106
elem = DummyElement(value, dtype)
11031107
df = DataFrame({"A": [elem.value, elem.value]}, dtype=elem.dtype)

pandas/tests/series/test_arithmetic.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@
2525
import pandas._testing as tm
2626
from pandas.core import ops
2727
from pandas.core.computation import expressions as expr
28-
from pandas.core.computation.check import NUMEXPR_INSTALLED
28+
from pandas.core.computation.check import (
29+
NUMEXPR_INSTALLED,
30+
NUMEXPR_VERSION,
31+
)
2932

3033

3134
@pytest.fixture(autouse=True, params=[0, 1000000], ids=["numexpr", "python"])
@@ -350,7 +353,9 @@ def test_add_list_to_masked_array_boolean(self, request):
350353
# GH#22962
351354
warning = (
352355
UserWarning
353-
if request.node.callspec.id == "numexpr" and NUMEXPR_INSTALLED
356+
if request.node.callspec.id == "numexpr"
357+
and NUMEXPR_INSTALLED
358+
and NUMEXPR_VERSION <= (2, 13, 0)
354359
else None
355360
)
356361
ser = Series([True, None, False], dtype="boolean")

pandas/tests/test_expressions.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import pandas._testing as tm
99
from pandas.core.api import DataFrame
1010
from pandas.core.computation import expressions as expr
11+
from pandas.core.computation.check import NUMEXPR_VERSION
1112

1213

1314
@pytest.fixture
@@ -318,7 +319,7 @@ def test_bool_ops_raise_on_arithmetic(self, op_str, opname):
318319
f(df, True)
319320

320321
@pytest.mark.parametrize(
321-
"op_str,opname", [("+", "add"), ("*", "mul"), ("-", "sub")]
322+
"op_str, opname", [("+", "add"), ("*", "mul"), ("-", "sub")]
322323
)
323324
def test_bool_ops_warn_on_arithmetic(self, op_str, opname, monkeypatch):
324325
n = 10
@@ -328,6 +329,8 @@ def test_bool_ops_warn_on_arithmetic(self, op_str, opname, monkeypatch):
328329
"b": np.random.default_rng(2).random(n) > 0.5,
329330
}
330331
)
332+
if NUMEXPR_VERSION and NUMEXPR_VERSION >= (2, 13, 1) and op_str in ("+", "*"):
333+
return
331334

332335
subs = {"+": "|", "*": "&", "-": "^"}
333336
sub_funcs = {"|": "or_", "&": "and_", "^": "xor"}

0 commit comments

Comments
 (0)