Skip to content

BUG: allow use of both default+input resolvers in df.eval, GH34966 #45134

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

Merged
merged 8 commits into from
Jan 4, 2022

Conversation

bubblingoak
Copy link
Contributor

@bubblingoak bubblingoak commented Dec 30, 2021

Allows default resolvers to be used with input resolvers in pandas.dataframe.eval. Previously cases such as this would break:

import pandas as pd

df = pd.DataFrame({'a':[0,1,2], 'b':[7,8,9]}) 
d = {'c': 5}
df.eval('a+b*c', resolvers=[d])

with pandas.core.computation.ops.UndefinedVariableError: name 'a' is not defined as explained in #34966. Following this update, the above works as expected.
Added a test similar to the above: tests.frame.test_query_eval.TestDataFrameEval.test_eval_resolvers_combined

Allow default resolvers to be used with input resolvers in dataframe.eval. Resolves GH34966
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.

umm can you add a test which fails w/o this change

@pep8speaks
Copy link

pep8speaks commented Dec 30, 2021

Hello @bubblingoak! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2022-01-04 00:39:55 UTC

@bubblingoak
Copy link
Contributor Author

umm can you add a test which fails w/o this change

Added the test tests.frame.test_query_eval.TestDataFrameEval.test_eval_resolvers_combined. The updated code passes, but current master fails on line 174:

result = df.eval("a + b * c", resolvers=[dict1])

with pandas.core.computation.ops.UndefinedVariableError: name 'a' is not defined

@bubblingoak bubblingoak marked this pull request as ready for review December 31, 2021 01:22
@bubblingoak bubblingoak requested a review from jreback December 31, 2021 01:34
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.

small commment, ping on green

@jreback jreback added this to the 1.4 milestone Dec 31, 2021
@jreback jreback added Bug expressions pd.eval, query labels Dec 31, 2021
@jreback jreback merged commit ce86f55 into pandas-dev:master Jan 4, 2022
@jreback
Copy link
Contributor

jreback commented Jan 4, 2022

thanks @bubblingoak

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug expressions pd.eval, query
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DOC: Confusing 'resolvers' kwarg documentation for DataFrame.query()
3 participants