Skip to content

BUG: Multiline Eval broken for local variables after first line #15343

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

Conversation

stephenrauch
Copy link
Contributor

Also fixes the code which attempted to ignore any blank lines in the
multiline expression.

@stephenrauch stephenrauch changed the title Fix GH15342 - Multiline Eval broken for local variables after first line BUG: Multiline Eval broken for local variables after first line Feb 8, 2017
@codecov-io
Copy link

codecov-io commented Feb 8, 2017

Codecov Report

Merging #15343 into master will decrease coverage by -0.01%.

@@            Coverage Diff             @@
##           master   #15343      +/-   ##
==========================================
- Coverage   86.32%   86.32%   -0.01%     
==========================================
  Files         141      141              
  Lines       51163    51162       -1     
==========================================
- Hits        44167    44166       -1     
  Misses       6996     6996
Impacted Files Coverage Δ
pandas/computation/eval.py 94.56% <100%> (-0.06%)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d38d142...fe67ede. Read the comment docs.

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.

lgtm

expected['d'] = expected['c'] + local_var
ans = df.eval("""
c = a * @local_var
d = c + @local_var
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a test with a blank lines as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test does actually have a blank line. The """, inplace=... that terminates the string causes a line of nothing but space at the end of the string. Formulating the test case this way was how I found that the .strip() was needed in the compare.

@@ -1411,6 +1411,22 @@ def test_multi_line_expression_not_inplace(self):
e = a + 2""", inplace=False)
assert_frame_equal(expected, df)

def test_multi_line_expression_local_variable(self):
# GH 15342
tm.skip_if_no_ne('numexpr')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't need the skip (this is done generically)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is a cut and paste from the test case above. I assumed it was desired boilerplate. It is present in the three test cases above the the test case I added. Would you like me to take some action on this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you should be able to remove from the tests above too.

@jreback
Copy link
Contributor

jreback commented Feb 8, 2017

@chris-b1

@jreback jreback added Bug Numeric Operations Arithmetic, Comparison, and Logical operations labels Feb 8, 2017
@stephenrauch
Copy link
Contributor Author

stephenrauch commented Feb 8, 2017

@chris-b1 , so yesterday was the first time I had seen this code base, so I am not familiar with the workings of the scope levels. I did see all of the +1's, and thought it note-worthy, but didn't investigate any further.

@chris-b1
Copy link
Contributor

chris-b1 commented Feb 8, 2017

Looked at this again, and I'm fine with your fix. level is ultimately passed to sys._getframe, so makes sense that we keep incrementing as we go down the call stack.

…line

Also fixes the code which attempted to ignore any blank lines in the
multiline expression.

Also removes some extra `tm.skip_if_no_ne('numexpr')`.
@stephenrauch stephenrauch force-pushed the multi-line-eval-with-local branch from c7ac553 to fe67ede Compare February 9, 2017 05:30
@jreback jreback added this to the 0.20.0 milestone Feb 9, 2017
@jreback
Copy link
Contributor

jreback commented Feb 9, 2017

thanks @stephenrauch !

@jreback jreback closed this in 3c9fec3 Feb 9, 2017
AnkurDedania pushed a commit to AnkurDedania/pandas that referenced this pull request Mar 21, 2017
Also fixes the code which attempted to ignore any blank lines in the
multiline expression.

closes pandas-dev#15342

Author: Stephen Rauch <[email protected]>

Closes pandas-dev#15343 from stephenrauch/multi-line-eval-with-local and squashes the following commits:

fe67ede [Stephen Rauch] BUG: GH15342 - Multiline Eval broken for local variables after first line
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Numeric Operations Arithmetic, Comparison, and Logical operations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Multiline Eval broken for local variables after first line
4 participants