Skip to content

Commit 53a4f11

Browse files
saehuihwangfeefladder
authored andcommitted
BUG: compute.use_numexpr option not respected (pandas-dev#42668)
1 parent 7db8e39 commit 53a4f11

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

doc/source/whatsnew/v1.4.0.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ Numeric
204204
^^^^^^^
205205
- Bug in :meth:`DataFrame.rank` raising ``ValueError`` with ``object`` columns and ``method="first"`` (:issue:`41931`)
206206
- Bug in :meth:`DataFrame.rank` treating missing values and extreme values as equal (for example ``np.nan`` and ``np.inf``), causing incorrect results when ``na_option="bottom"`` or ``na_option="top`` used (:issue:`41931`)
207-
-
207+
- Bug in ``numexpr`` engine still being used when the option ``compute.use_numexpr`` is set to ``False`` (:issue:`32556`)
208208

209209
Conversion
210210
^^^^^^^^^^

pandas/core/computation/eval.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,10 @@ def _check_engine(engine: str | None) -> str:
4343
Engine name.
4444
"""
4545
from pandas.core.computation.check import NUMEXPR_INSTALLED
46+
from pandas.core.computation.expressions import USE_NUMEXPR
4647

4748
if engine is None:
48-
engine = "numexpr" if NUMEXPR_INSTALLED else "python"
49+
engine = "numexpr" if USE_NUMEXPR else "python"
4950

5051
if engine not in ENGINES:
5152
valid_engines = list(ENGINES.keys())

pandas/tests/computation/test_eval.py

+29
Original file line numberDiff line numberDiff line change
@@ -1865,6 +1865,35 @@ def test_invalid_engine():
18651865
pd.eval("x + y", local_dict={"x": 1, "y": 2}, engine="asdf")
18661866

18671867

1868+
@td.skip_if_no_ne
1869+
@pytest.mark.parametrize(
1870+
("use_numexpr", "expected"),
1871+
(
1872+
(True, "numexpr"),
1873+
(False, "python"),
1874+
),
1875+
)
1876+
def test_numexpr_option_respected(use_numexpr, expected):
1877+
# GH 32556
1878+
from pandas.core.computation.eval import _check_engine
1879+
1880+
with pd.option_context("compute.use_numexpr", use_numexpr):
1881+
result = _check_engine(None)
1882+
assert result == expected
1883+
1884+
1885+
@td.skip_if_no_ne
1886+
def test_numexpr_option_incompatible_op():
1887+
# GH 32556
1888+
with pd.option_context("compute.use_numexpr", False):
1889+
df = DataFrame(
1890+
{"A": [True, False, True, False, None, None], "B": [1, 2, 3, 4, 5, 6]}
1891+
)
1892+
result = df.query("A.isnull()")
1893+
expected = DataFrame({"A": [None, None], "B": [5, 6]}, index=[4, 5])
1894+
tm.assert_frame_equal(result, expected)
1895+
1896+
18681897
@td.skip_if_no_ne
18691898
def test_invalid_parser():
18701899
msg = "Invalid parser 'asdf' passed"

0 commit comments

Comments
 (0)