Skip to content

BUG: do not remove temporaries from eval/query scope #7303

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 1 commit into from
Jun 1, 2014
Merged
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
3 changes: 3 additions & 0 deletions doc/source/v0.14.1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,6 @@ Bug Fixes
and ``left`` keyword is specified (:issue:`7226`)
- BUG in ``DataFrame.hist`` raises ``TypeError`` when it contains non numeric column (:issue:`7277`)
- BUG in ``Index.delete`` does not preserve ``name`` and ``freq`` attributes (:issue:`7302`)
- Bug in ``DataFrame.query()``/``eval`` where local string variables with the @
sign were being treated as temporaries attempting to be deleted
(:issue:`7300`).
2 changes: 0 additions & 2 deletions pandas/computation/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,12 +340,10 @@ def _rewrite_membership_op(self, node, left, right):
# pop the string variable out of locals and replace it with a list
# of one string, kind of a hack
if right_str:
self.env.remove_tmp(right.name)
name = self.env.add_tmp([right.value])
right = self.term_type(name, self.env)

if left_str:
self.env.remove_tmp(left.name)
name = self.env.add_tmp([left.value])
left = self.term_type(name, self.env)

Expand Down
10 changes: 0 additions & 10 deletions pandas/computation/scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,16 +278,6 @@ def add_tmp(self, value):
# only increment if the variable gets put in the scope
return name

def remove_tmp(self, name):
"""Remove a temporary variable from this scope

Parameters
----------
name : str
The name of a temporary to be removed
"""
del self.temps[name]

@property
def ntemps(self):
"""The number of temporary variables in this scope"""
Expand Down
12 changes: 12 additions & 0 deletions pandas/tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -13685,6 +13685,18 @@ def test_query_single_element_booleans(self):
for parser, engine in product(PARSERS, ENGINES):
yield self.check_query_single_element_booleans, parser, engine

def check_query_string_scalar_variable(self, parser, engine):
tm.skip_if_no_ne(engine)
df = pd.DataFrame({'Symbol': ['BUD US', 'BUD US', 'IBM US', 'IBM US'],
'Price': [109.70, 109.72, 183.30, 183.35]})
e = df[df.Symbol == 'BUD US']
symb = 'BUD US'
r = df.query('Symbol == @symb', parser=parser, engine=engine)
tm.assert_frame_equal(e, r)

def test_query_string_scalar_variable(self):
for parser, engine in product(['pandas'], ENGINES):
yield self.check_query_string_scalar_variable, parser, engine

class TestDataFrameEvalNumExprPandas(tm.TestCase):

Expand Down