Skip to content

query fails with local variables in expressions #5087

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
cpcloud opened this issue Oct 2, 2013 · 1 comment · Fixed by #6366
Closed

query fails with local variables in expressions #5087

cpcloud opened this issue Oct 2, 2013 · 1 comment · Fixed by #6366
Assignees
Labels
Bug Error Reporting Incorrect or improved errors from pandas
Milestone

Comments

@cpcloud
Copy link
Member

cpcloud commented Oct 2, 2013

Proper message for overlapping locals/frame (tested):

In [28]: a = Series(randint(3, size=5), name='a')

In [29]: b = Series(randint(10, size=5), name='b')

In [30]: df = DataFrame({'a': a, 'b': b})

In [31]: df.query('b - 1 in a')
NameResolutionError: resolvers and locals overlap on names ['b']

Expression works when there's no local (tested)

In [50]: del b

In [51]: a
Out[51]:
0    2
1    2
2    0
3    1
4    2
Name: a, dtype: int64

In [52]: df.b - 1
Out[52]:
0    3
1    4
2    7
3    7
4   -1
Name: b, dtype: int64

In [53]: df.query('b - 1 in a')
Out[53]:
Empty DataFrame
Columns: [a, b]
Index: []

Works fine when I use the local by itself (tested):

In [34]: df.query('@b in a')
Out[34]:
   a  b
4  2  0

However, when I try to reference the local b using @b in an expression, things go awry (not tested):

In [55]: b = Series(randint(10, size=5), name='b')

In [56]: df.query('@b - 1 in a')
UndefinedVariableError: local variable '@b' is not defined
@ghost ghost assigned cpcloud Oct 2, 2013
@jreback
Copy link
Contributor

jreback commented Oct 11, 2013

@cpcloud for 0.14?

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

Successfully merging a pull request may close this issue.

2 participants