-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
ENH: fix eval scoping issues #6366
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
Conversation
oh boy! looks like the right way to do this..... 👍 |
Last issue is a scoping issue with py3 ... somehow not capturing scope from |
guess this was not a small change 🔢 |
Nope. But scope is less of a hack and I think overall implementation is easier to understand. Actually got up early to try and fix this but all the back and forth of comparing py2 and 3 is huge time sink |
turns out that list comprehensions work differently re the stack in python 3....each iteration generates a new stack frame. std for loops don't work that way so that should do it |
Ok this is passing locally on py27 and py33 |
@jreback Whenever you get a chance .... this is passing. |
won't pretend I understand! hahah can you build the docs and just check that everything looks ok their? I find sometimes they are good tests in and of themselves (aside which they need slight changing anyhow, right?) |
Oh right! Those have to be changed anyway becuase of the new API ... let me add some new check boxes.. |
Biggest changes are
|
maybe post on the top the relevant changes (from an ipython session)..... |
sure |
@y-p @jreback @jorisvandenbossche Would be very grateful for any comments y'all might have. |
your exceptions should be multi line (looking at the syntax error one for using a @ in eval) |
u should put what u put in release notes in v0.14 API change section |
done |
adding a test for #5087. this closes that too! |
u create temporaries for the locals to avoid name collisions? |
looks fine to me |
Temporaries are created for strings and lists |
For locals I just rename them when the terms are created during parsing. |
oh ok looks fine 2 me otherwise can merge when u r ready |
|
||
df.eval('@a + b') | ||
With :func:`~pandas.eval` you cannot use the ``@`` prefix *at all*, because it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe you can leave out the ~
here (so just :func:
pandas.eval``, this will show it in the docs as pandas.eval()
instead of `eval()`) so it is clear it is not about the same eval as the paragraph above
@@ -1738,6 +1738,8 @@ def _getitem_frame(self, key): | |||
def query(self, expr, **kwargs): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe mention something of @
in the docstring?
I am not really familiar with this code, but just added some minor doc comments. |
Thanks for the comments guys. |
@jreback Should I squash some more? This is ready for merging if there are no more comments. |
maybe a bit more? |
Okay squashed and cleaned up the query docstring. Would like to keep some history so that I remember why I made change X especially some of these python version differences |
ChainMap implements a list of mappings that effectively functions as a single dictionary. This class is very useful for implementing scope. This commit also adds a DeepChainMap subclass of ChainMap for writing and deleting keys.
Also useful for replacing local variable names with their mangled versions.
cool....go for it |
So backport that as well.
In Python 3.x list comprehension build up stack frames, thus providing the stack level to search is not the same as it is in Python 2.x.
bombs away |
closes #5987
closes #5087
Relevant user-facing changes:
repr
ofScope
objects work or revert to previous versionpd.eval('@a + b')
numexpr
supports, since you cannot override them innumexpr.evaluate
, even when explicitly passing them. For exampleFor reference, after this PR local variables are given lower precedence than column names. For example
will no longer raise an exception about overlapping variable names. If you want the local
a
(as opposed to the columna
) you must do