Skip to content

Commit e84dece

Browse files
authored
Merge branch 'main' into main
2 parents 62a7cbb + c47296a commit e84dece

File tree

4 files changed

+16
-17
lines changed

4 files changed

+16
-17
lines changed

doc/source/whatsnew/v3.0.0.rst

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

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/core/indexes/base.py

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4153,7 +4153,8 @@ def reindex(
41534153
preserve_names = not hasattr(target, "name")
41544154

41554155
# GH7774: preserve dtype/tz if target is empty and not an Index.
4156-
target = ensure_has_len(target) # target may be an iterator
4156+
if is_iterator(target):
4157+
target = list(target)
41574158

41584159
if not isinstance(target, Index) and len(target) == 0:
41594160
if level is not None and self._is_multi:
@@ -7568,21 +7569,9 @@ def ensure_index(index_like: Axes, copy: bool = False) -> Index:
75687569
return Index(index_like, copy=copy)
75697570

75707571

7571-
def ensure_has_len(seq):
7572-
"""
7573-
If seq is an iterator, put its values into a list.
7574-
"""
7575-
try:
7576-
len(seq)
7577-
except TypeError:
7578-
return list(seq)
7579-
else:
7580-
return seq
7581-
7582-
75837572
def trim_front(strings: list[str]) -> list[str]:
75847573
"""
7585-
Trims zeros and decimal points.
7574+
Trims leading spaces evenly among all strings.
75867575
75877576
Examples
75887577
--------
@@ -7594,8 +7583,9 @@ def trim_front(strings: list[str]) -> list[str]:
75947583
"""
75957584
if not strings:
75967585
return strings
7597-
while all(strings) and all(x[0] == " " for x in strings):
7598-
strings = [x[1:] for x in strings]
7586+
smallest_leading_space = min(len(x) - len(x.lstrip()) for x in strings)
7587+
if smallest_leading_space > 0:
7588+
strings = [x[smallest_leading_space:] for x in strings]
75997589
return strings
76007590

76017591

pandas/tests/computation/test_eval.py

Lines changed: 8 additions & 0 deletions
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)