BUG: AttributeError on method call after binary operation in eval expression · Issue #61175 · pandas-dev/pandas (original) (raw)

Pandas version checks

Reproducible Example

import pandas as pd

x = pd.Series([1,2,3,5]) y = pd.Series([2,3,4])

pd.eval("(x + y).dropna()")

raises AttributeError: 'BinOp' object has no attribute 'value'

Note that something like pd.eval("(x.dropna() + y)") works!

Issue Description

Also effects other Series methods called on the result of a binary operation, which work well if applied to one operand.

See also #24670

Expected Behavior

Should return a Series of sums with nan values removed. Generally I would expect that it should be possible to apply a Series method to the result of a binary operation as part of an eval expression.

Installed Versions

INSTALLED VERSIONS

commit : 0691c5c
python : 3.13.2
python-bits : 64
OS : Linux
OS-release : 6.13.7-arch1-1
Version : #1 SMP PREEMPT_DYNAMIC Thu, 13 Mar 2025 18:12:00 +0000
machine : x86_64
processor :
byteorder : little
LC_ALL : None
LANG : de_DE.UTF-8
LOCALE : de_DE.UTF-8

pandas : 2.2.3
numpy : 2.2.3
pytz : 2025.1
dateutil : 2.9.0.post0
pip : 25.0.1
Cython : None
sphinx : None
IPython : 9.0.1
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : 4.13.3
blosc : None
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : 2025.2.0
html5lib : None
hypothesis : None
gcsfs : None
jinja2 : 3.1.5
lxml.etree : 5.3.1
matplotlib : 3.10.1
numba : None
numexpr : 2.10.2
odfpy : None
openpyxl : None
pandas_gbq : None
psycopg2 : None
pymysql : None
pyarrow : None
pyreadstat : None
pytest : 8.3.5
python-calamine : None
pyxlsb : None
s3fs : None
scipy : 1.15.2
sqlalchemy : 2.0.38
tables : 3.10.2
tabulate : None
xarray : 2025.1.2
xlrd : None
xlsxwriter : None
zstandard : None
tzdata : 2025.1
qtpy : None
pyqt5 : None