Skip to content

Commit 198ed86

Browse files
authored
BUG: pd.eval with engine="numexpr" fails with float division (#59907)
* BUG: pd.eval with engine="numexpr" fails with float division * Add skip * Add whatsnew * update
1 parent ba7e83d commit 198ed86

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

doc/source/whatsnew/v3.0.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,7 @@ Other
698698
- Bug in :class:`DataFrame` when passing a ``dict`` with a NA scalar and ``columns`` that would always return ``np.nan`` (:issue:`57205`)
699699
- Bug in :func:`eval` on :class:`ExtensionArray` on including division ``/`` failed with a ``TypeError``. (:issue:`58748`)
700700
- Bug in :func:`eval` where the names of the :class:`Series` were not preserved when using ``engine="numexpr"``. (:issue:`10239`)
701+
- Bug in :func:`eval` with ``engine="numexpr"`` returning unexpected result for float division. (:issue:`59736`)
701702
- Bug in :func:`unique` on :class:`Index` not always returning :class:`Index` (:issue:`57043`)
702703
- Bug in :meth:`DataFrame.apply` where passing ``engine="numba"`` ignored ``args`` passed to the applied function (:issue:`58712`)
703704
- Bug in :meth:`DataFrame.eval` and :meth:`DataFrame.query` which caused an exception when using NumPy attributes via ``@`` notation, e.g., ``df.eval("@np.floor(a)")``. (:issue:`58041`)

pandas/core/computation/align.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ def reconstruct_object(typ, obj, axes, dtype, name):
213213
if hasattr(res_t, "type") and typ == np.bool_ and res_t != np.bool_:
214214
ret_value = res_t.type(obj)
215215
else:
216-
ret_value = typ(obj).astype(res_t)
216+
ret_value = res_t.type(obj)
217217
# The condition is to distinguish 0-dim array (returned in case of
218218
# scalar) and 1 element array
219219
# e.g. np.array(0) and np.array([0])

pandas/tests/computation/test_eval.py

+8
Original file line numberDiff line numberDiff line change
@@ -1998,3 +1998,11 @@ def test_validate_bool_args(value):
19981998
msg = 'For argument "inplace" expected type bool, received type'
19991999
with pytest.raises(ValueError, match=msg):
20002000
pd.eval("2+2", inplace=value)
2001+
2002+
2003+
@td.skip_if_no("numexpr")
2004+
def test_eval_float_div_numexpr():
2005+
# GH 59736
2006+
result = pd.eval("1 / 2", engine="numexpr")
2007+
expected = 0.5
2008+
assert result == expected

0 commit comments

Comments
 (0)