Skip to content

BUG: #14095. Amend eval() resolvers kwarg to accept lists #14121

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
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.19.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1290,3 +1290,4 @@ Bug Fixes
- Bug in ``.to_string()`` when called with an integer ``line_width`` and ``index=False`` raises an UnboundLocalError exception because ``idx`` referenced before assignment.

- Bug in ``read_csv()``, where aliases for utf-xx (e.g. UTF-xx, UTF_xx, utf_xx) raised UnicodeDecodeError (:issue:`13549`)
- Bug in ``eval()`` where the ``resolvers`` argument would not accept a list (:issue`14095`)
2 changes: 1 addition & 1 deletion pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -2266,7 +2266,7 @@ def eval(self, expr, inplace=None, **kwargs):
resolvers = dict(self.iteritems()), index_resolvers
if 'target' not in kwargs:
kwargs['target'] = self
kwargs['resolvers'] = kwargs.get('resolvers', ()) + resolvers
kwargs['resolvers'] = kwargs.get('resolvers', ()) + tuple(resolvers)
return _eval(expr, inplace=inplace, **kwargs)

def select_dtypes(self, include=None, exclude=None):
Expand Down
9 changes: 9 additions & 0 deletions pandas/tests/frame/test_query_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,15 @@ def test_query_non_str(self):
with tm.assertRaisesRegexp(ValueError, msg):
df.query(111)

def test_eval_resolvers_as_list(self):
df = DataFrame(randn(10, 2), columns=list('ab'))
dict1 = {'a': 1}
dict2 = {'b': 2}
self.assertTrue(df.eval('a + b', resolvers=[dict1, dict2]) ==
dict1['a'] + dict2['b'])
self.assertTrue(pd.eval('a + b', resolvers=[dict1, dict2]) ==
dict1['a'] + dict2['b'])


class TestDataFrameQueryWithMultiIndex(tm.TestCase):

Expand Down