Skip to content

Commit 2122bfe

Browse files
Merge branch 'main' into fix-61099
2 parents 75e2c2b + 83979d6 commit 2122bfe

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

.github/workflows/wheels.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ jobs:
153153
run: echo "sdist_name=$(cd ./dist && ls -d */)" >> "$GITHUB_ENV"
154154

155155
- name: Build wheels
156-
uses: pypa/[email protected].1
156+
uses: pypa/[email protected].2
157157
with:
158158
package-dir: ./dist/${{ startsWith(matrix.buildplat[1], 'macosx') && env.sdist_name || needs.build_sdist.outputs.sdist_file }}
159159
env:

doc/source/whatsnew/v3.0.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,7 @@ Other
826826
- Bug in :class:`DataFrame` when passing a ``dict`` with a NA scalar and ``columns`` that would always return ``np.nan`` (:issue:`57205`)
827827
- Bug in :class:`Series` ignoring errors when trying to convert :class:`Series` input data to the given ``dtype`` (:issue:`60728`)
828828
- Bug in :func:`eval` on :class:`ExtensionArray` on including division ``/`` failed with a ``TypeError``. (:issue:`58748`)
829+
- Bug in :func:`eval` where method calls on binary operations like ``(x + y).dropna()`` would raise ``AttributeError: 'BinOp' object has no attribute 'value'`` (:issue:`61175`)
829830
- Bug in :func:`eval` where the names of the :class:`Series` were not preserved when using ``engine="numexpr"``. (:issue:`10239`)
830831
- Bug in :func:`eval` with ``engine="numexpr"`` returning unexpected result for float division. (:issue:`59736`)
831832
- Bug in :func:`to_numeric` raising ``TypeError`` when ``arg`` is a :class:`Timedelta` or :class:`Timestamp` scalar. (:issue:`59944`)

pandas/core/computation/expr.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,11 @@ def visit_Attribute(self, node, **kwargs):
644644
ctx = node.ctx
645645
if isinstance(ctx, ast.Load):
646646
# resolve the value
647-
resolved = self.visit(value).value
647+
visited_value = self.visit(value)
648+
if hasattr(visited_value, "value"):
649+
resolved = visited_value.value
650+
else:
651+
resolved = visited_value(self.env)
648652
try:
649653
v = getattr(resolved, attr)
650654
name = self.env.add_tmp(v)

pandas/tests/computation/test_eval.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2006,3 +2006,24 @@ def test_eval_float_div_numexpr():
20062006
result = pd.eval("1 / 2", engine="numexpr")
20072007
expected = 0.5
20082008
assert result == expected
2009+
2010+
2011+
def test_method_calls_on_binop():
2012+
# GH 61175
2013+
x = Series([1, 2, 3, 5])
2014+
y = Series([2, 3, 4])
2015+
2016+
# Method call on binary operation result
2017+
result = pd.eval("(x + y).dropna()")
2018+
expected = (x + y).dropna()
2019+
tm.assert_series_equal(result, expected)
2020+
2021+
# Test with other binary operations
2022+
result = pd.eval("(x * y).dropna()")
2023+
expected = (x * y).dropna()
2024+
tm.assert_series_equal(result, expected)
2025+
2026+
# Test with method chaining
2027+
result = pd.eval("(x + y).dropna().reset_index(drop=True)")
2028+
expected = (x + y).dropna().reset_index(drop=True)
2029+
tm.assert_series_equal(result, expected)

0 commit comments

Comments
 (0)