Skip to content

Commit 79e356d

Browse files
committed
Revert "New eval keyword to disallow assignment"
This reverts commit 655fb5e5be3981b43ff146d68a0fa53e75d98dd1.
1 parent afe2d47 commit 79e356d

File tree

2 files changed

+4
-11
lines changed

2 files changed

+4
-11
lines changed

pandas/computation/eval.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def _check_for_locals(expr, stack_level, parser):
138138

139139
def eval(expr, parser='pandas', engine='numexpr', truediv=True,
140140
local_dict=None, global_dict=None, resolvers=(), level=0,
141-
target=None, assignment_allowed=True):
141+
target=None):
142142
"""Evaluate a Python expression as a string using various backends.
143143
144144
The following arithmetic operations are supported: ``+``, ``-``, ``*``,
@@ -196,9 +196,6 @@ def eval(expr, parser='pandas', engine='numexpr', truediv=True,
196196
scope. Most users will **not** need to change this parameter.
197197
target : a target object for assignment, optional, default is None
198198
essentially this is a passed in resolver
199-
assignment_allowed : bool
200-
Whether the eval should be able to modify the input through
201-
assigment.
202199
203200
Returns
204201
-------
@@ -239,11 +236,7 @@ def eval(expr, parser='pandas', engine='numexpr', truediv=True,
239236

240237
# assign if needed
241238
if env.target is not None and parsed_expr.assigner is not None:
242-
if assignment_allowed:
243-
env.target[parsed_expr.assigner] = ret
244-
return None
245-
else:
246-
raise ValueError("Expression includes assignment statement: \n"
247-
"\t not allowed from DataFrame.query")
239+
env.target[parsed_expr.assigner] = ret
240+
return None
248241

249242
return ret

pandas/core/frame.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1935,7 +1935,7 @@ def query(self, expr, **kwargs):
19351935
>>> df[df.a > df.b] # same result as the previous expression
19361936
"""
19371937
kwargs['level'] = kwargs.pop('level', 0) + 1
1938-
res = self.eval(expr, assignment_allowed=False, **kwargs)
1938+
res = self.eval(expr, **kwargs)
19391939

19401940
try:
19411941
return self.loc[res]

0 commit comments

Comments
 (0)