Skip to content

Commit 83e908f

Browse files
committed
Merge remote-tracking branch 'upstream/main' into series-sum-attrs
2 parents 3a80cf9 + 4c5f4ca commit 83e908f

File tree

6 files changed

+34
-3
lines changed

6 files changed

+34
-3
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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,7 @@ Other
825825
- Bug in :class:`DataFrame` when passing a ``dict`` with a NA scalar and ``columns`` that would always return ``np.nan`` (:issue:`57205`)
826826
- Bug in :class:`Series` ignoring errors when trying to convert :class:`Series` input data to the given ``dtype`` (:issue:`60728`)
827827
- Bug in :func:`eval` on :class:`ExtensionArray` on including division ``/`` failed with a ``TypeError``. (:issue:`58748`)
828+
- 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`)
828829
- Bug in :func:`eval` where the names of the :class:`Series` were not preserved when using ``engine="numexpr"``. (:issue:`10239`)
829830
- Bug in :func:`eval` with ``engine="numexpr"`` returning unexpected result for float division. (:issue:`59736`)
830831
- Bug in :func:`to_numeric` raising ``TypeError`` when ``arg`` is a :class:`Timedelta` or :class:`Timestamp` scalar. (:issue:`59944`)
@@ -834,6 +835,7 @@ Other
834835
- Bug in :meth:`DataFrame.eval` and :meth:`DataFrame.query` which did not allow to use ``tan`` function. (:issue:`55091`)
835836
- Bug in :meth:`DataFrame.query` where using duplicate column names led to a ``TypeError``. (:issue:`59950`)
836837
- Bug in :meth:`DataFrame.query` which raised an exception or produced incorrect results when expressions contained backtick-quoted column names containing the hash character ``#``, backticks, or characters that fall outside the ASCII range (U+0001..U+007F). (:issue:`59285`) (:issue:`49633`)
838+
- Bug in :meth:`DataFrame.query` which raised an exception when querying integer column names using backticks. (:issue:`60494`)
837839
- Bug in :meth:`DataFrame.shift` where passing a ``freq`` on a DataFrame with no columns did not shift the index correctly. (:issue:`60102`)
838840
- Bug in :meth:`DataFrame.sort_index` when passing ``axis="columns"`` and ``ignore_index=True`` and ``ascending=False`` not returning a :class:`RangeIndex` columns (:issue:`57293`)
839841
- Bug in :meth:`DataFrame.transform` that was returning the wrong order unless the index was monotonically increasing. (:issue:`57069`)

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,6 @@ def _get_cleaned_column_resolvers(self) -> dict[Hashable, Series]:
612612
v, copy=False, index=self.index, name=k, dtype=dtype
613613
).__finalize__(self)
614614
for k, v, dtype in zip(self.columns, self._iter_column_arrays(), dtypes)
615-
if not isinstance(k, int)
616615
}
617616

618617
@final

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)

pandas/tests/frame/test_query_eval.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,6 +1345,11 @@ def test_start_with_spaces(self, df):
13451345
expect = df[" A"] + df[" "]
13461346
tm.assert_series_equal(res, expect)
13471347

1348+
def test_ints(self, df):
1349+
res = df.query("`1` == 7")
1350+
expect = df[df[1] == 7]
1351+
tm.assert_frame_equal(res, expect)
1352+
13481353
def test_lots_of_operators_string(self, df):
13491354
res = df.query("` &^ :!€$?(} > <++*'' ` > 4")
13501355
expect = df[df[" &^ :!€$?(} > <++*'' "] > 4]

0 commit comments

Comments
 (0)