Skip to content

Commit 870c9d1

Browse files
committed
BUG: pd.eval with engine="numexpr" fails with float division
1 parent 23c497b commit 870c9d1

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

pandas/core/computation/align.py

Lines changed: 1 addition & 1 deletion
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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1998,3 +1998,10 @@ 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+
def test_eval_float_div_numexpr():
2004+
# GH59736
2005+
result = pd.eval("1 / 2", engine="numexpr")
2006+
expected = 0.5
2007+
assert result == expected

0 commit comments

Comments
 (0)