Skip to content

Commit b2a73b8

Browse files
tom-birdjreback
authored andcommitted
BUG: #14095. Amend eval() resolvers kwarg to accept lists
closes #14095 Author: Tom Bird <[email protected]> Closes #14121 from theultimatecrouton/resolvers and squashes the following commits: 227d734 [Tom Bird] BUG: #14095. Amend eval() resolvers kwarg to accept lists f27963c [Tom Bird] BUG: #14095. Amend eval() resolvers kwarg to accept lists 77500da [Tom Bird] BUG: #14095. Amend eval() resolvers kwarg to accept lists ef03d59 [Tom Bird] BUG: #14095. Amend eval() resolvers kwarg to accept lists
1 parent 8654a9e commit b2a73b8

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

doc/source/whatsnew/v0.19.0.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,3 +1358,4 @@ Bug Fixes
13581358
- Bug in ``.to_string()`` when called with an integer ``line_width`` and ``index=False`` raises an UnboundLocalError exception because ``idx`` referenced before assignment.
13591359

13601360
- Bug in ``read_csv()``, where aliases for utf-xx (e.g. UTF-xx, UTF_xx, utf_xx) raised UnicodeDecodeError (:issue:`13549`)
1361+
- Bug in ``eval()`` where the ``resolvers`` argument would not accept a list (:issue`14095`)

pandas/core/frame.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2272,7 +2272,7 @@ def eval(self, expr, inplace=None, **kwargs):
22722272
resolvers = dict(self.iteritems()), index_resolvers
22732273
if 'target' not in kwargs:
22742274
kwargs['target'] = self
2275-
kwargs['resolvers'] = kwargs.get('resolvers', ()) + resolvers
2275+
kwargs['resolvers'] = kwargs.get('resolvers', ()) + tuple(resolvers)
22762276
return _eval(expr, inplace=inplace, **kwargs)
22772277

22782278
def select_dtypes(self, include=None, exclude=None):

pandas/tests/frame/test_query_eval.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,16 @@ def test_query_non_str(self):
147147
with tm.assertRaisesRegexp(ValueError, msg):
148148
df.query(111)
149149

150+
def test_eval_resolvers_as_list(self):
151+
# GH 14095
152+
df = DataFrame(randn(10, 2), columns=list('ab'))
153+
dict1 = {'a': 1}
154+
dict2 = {'b': 2}
155+
self.assertTrue(df.eval('a + b', resolvers=[dict1, dict2]) ==
156+
dict1['a'] + dict2['b'])
157+
self.assertTrue(pd.eval('a + b', resolvers=[dict1, dict2]) ==
158+
dict1['a'] + dict2['b'])
159+
150160

151161
class TestDataFrameQueryWithMultiIndex(tm.TestCase):
152162

0 commit comments

Comments
 (0)