-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
ENH/API: Change query/eval local variable API #5987
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
Comments
+1 for adopting "say what you mean" as a guiding principle. |
+1 for cool emoji! |
Slight update here: We'll have to keep the current scheme because otherwise locals in |
That means that c = 1
df.query('a > c') will still work because first frame cols are searched then locals, then globals. If they weren't, then toplevel However, you'll get a warning with a new parameter |
I kind of feel like adding a keyword for this might betray a poor design decision on my part and this might require some more deliberation and discussion. |
I agree re the Instead of saying @ means vars and no prefix means columns, think 'scope'.
When you asked me to review PR a few months ago, I mentioned this ambiguity |
@y-p Agreed. Thanks. |
doing this for 0.13.1? |
Assuming that's in a few days...don't think so. This is going to take me a bit ... Just need to sit down with it for a while and hash it out in my head. |
figured that |
Currently, with
query
andeval
you can use local variables a la the@
symbol. It's a bit confusing since you're not allowed to have a local variable and a column name with the same name, but it will try to pull the local if possible.Current API:
Fails with a
NameError
:But this works:
And so does this, which is confusing:
As suggested by @y-p and @jreback, the following API is less confusing IMO.
From now on, all local variables will need an explicit reference and if there is a column name and a local with the same name then the column will be used. Thus you can always be sure that you're referring to a column, or it doesn't exist, in which case you'll get an error. And if you use
@
then you can be sure that you're referring to local, and likewise get an error if it doesn't exist. As a bonus ( 🐺 in 🐑 's clothing), this allows you to use both a local and a column name with the same name.Examples:
The text was updated successfully, but these errors were encountered: