Skip to content

Can't use result of binary operator in DataFrame.eval() #20367

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
scizzorz opened this issue Mar 15, 2018 · 1 comment
Closed

Can't use result of binary operator in DataFrame.eval() #20367

scizzorz opened this issue Mar 15, 2018 · 1 comment
Labels
Duplicate Report Duplicate issue or pull request Enhancement

Comments

@scizzorz
Copy link

Code Sample, a copy-pastable example if possible

import pandas as pd
df = pd.DataFrame({'x': [1, 2, 3], 'y': [2, 3, 4]})
df.eval('(x - y)').std() # evaluates
df.eval('(x - y).std()') # exception: AttributeError: 'BinOp' object has no attribute 'value'

Problem description

I expected this type of eval() expression to work correctly. I'm not sure how to justify the behavior other than it being more intuitive and practical.

I searched and was able to find similar errors, but the cause seems to be with UnaryOp instead of BinOp:

Expected Output

>>> import pandas as pd
>>> df = pd.DataFrame({'x': [1, 2, 3], 'y': [2, 3, 4]})
>>> df.eval('(x - y)').std() # evaluates
0.0
>>> df.eval('(x - y).std()') # should also evaluate
0.0

Output of pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 3.6.3.final.0
python-bits: 64
OS: Linux
OS-release: 4.13.0-32-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8

pandas: 0.22.0
pytest: None
pip: 9.0.1
setuptools: 32.3.1
Cython: None
numpy: 1.14.0
scipy: None
pyarrow: None
xarray: None
IPython: None
sphinx: None
patsy: None
dateutil: 2.6.1
pytz: 2017.3
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 2.2.0
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: 0.999999999
sqlalchemy: 1.2.2
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None

@jreback
Copy link
Contributor

jreback commented Mar 16, 2018

closing as duplicate of #16363

function calls are simply not implemented. would take a PR fixing this.

@jreback jreback closed this as completed Mar 16, 2018
@jreback jreback added Duplicate Report Duplicate issue or pull request Enhancement labels Mar 16, 2018
@jreback jreback added this to the No action milestone Mar 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate Report Duplicate issue or pull request Enhancement
Projects
None yet
Development

No branches or pull requests

2 participants