Skip to content
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

Properly handle missing attributes in query/eval strings #32408

Merged
merged 10 commits into from
Apr 10, 2020

Conversation

alexmojaki
Copy link
Contributor

Consider this script:

import pandas as pd

pd.eval("pd.thing")

Currently it raises an error like this:

  File "/home/alex/work/pandas/pandas/core/computation/expr.py", line 640, in visit_Attribute
    raise ValueError(f"Invalid Attribute context {ctx.__name__}")
AttributeError: 'Load' object has no attribute '__name__'

Adding __class__ to that line changes the error to the more sensible:

ValueError: Invalid Attribute context Load

Re-raising the original error gives what's really needed:

  File "/home/alex/work/pandas/pandas/core/computation/expr.py", line 631, in visit_Attribute
    v = getattr(resolved, attr)
  File "/home/alex/work/pandas/pandas/__init__.py", line 260, in __getattr__
    raise AttributeError(f"module 'pandas' has no attribute '{name}'")
AttributeError: module 'pandas' has no attribute 'thing'

@alexmojaki
Copy link
Contributor Author

I don't know what the failure "codecov/patch — 0% of diff hit (target 50%)" means. Am I supposed to write tests for this change?

@jreback jreback added the Error Reporting Incorrect or improved errors from pandas label Mar 15, 2020
Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

always start with a test

@alexmojaki alexmojaki requested a review from jreback March 15, 2020 11:17
Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a whatsnew note for 1.1. in the conversion bug fix section

pandas/core/computation/expr.py Show resolved Hide resolved
@jreback jreback added this to the 1.1 milestone Mar 17, 2020
@jreback
Copy link
Contributor

jreback commented Mar 17, 2020

can you add a whatsnew note for 1.1, in the Other bug fix section

@jreback
Copy link
Contributor

jreback commented Mar 19, 2020

thanks @alexmojaki will merge on green.

@alexmojaki
Copy link
Contributor Author

Presumably that docs failure is for unrelated reasons?

no theme named 'pandas_sphinx_theme' found (missing theme.conf?)

@simonjayhawkins
Copy link
Member

Presumably that docs failure is for unrelated reasons?

no theme named 'pandas_sphinx_theme' found (missing theme.conf?)

I think fixed by #32840. can you merge master

@alexmojaki
Copy link
Contributor Author

@WillAyd
Copy link
Member

WillAyd commented Apr 7, 2020

Can you merge master again and re-push? Should be fixed on master

@alexmojaki
Copy link
Contributor Author

The last build succeeded 5 hours ago, but github hasn't been updated. I've never seen that before.

@WillAyd WillAyd merged commit f334fcc into pandas-dev:master Apr 10, 2020
@WillAyd
Copy link
Member

WillAyd commented Apr 10, 2020

Thanks @alexmojaki

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Error Reporting Incorrect or improved errors from pandas
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants