-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Fix #16363 - Prevent visit_BinOp from accessing value on UnaryOp #25928
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
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ef777e7
BUG: Fix #16363 - Prevent visit_BinOp from accessing value on UnaryOp
alexcwatt 5242bef
Fix test and add note to whatsnew
alexcwatt f0e0b3d
Attempt to fix test style
alexcwatt 5d6ea06
Update whatsnew and add another test case
alexcwatt 1b88337
Use parametrize to test both float32 and float64
alexcwatt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -608,6 +608,12 @@ def test_unary_in_array(self): | |
-False, False, ~False, +False, | ||
-37, 37, ~37, +37], dtype=np.object_)) | ||
|
||
def test_float_comparison_bin_op(self): | ||
# GH 16363 | ||
df = pd.DataFrame({'x': np.array([0], dtype=np.float32)}) | ||
res = df.eval('x < -0.1') | ||
assert np.array_equal(res, np.array([False])), res | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the reason for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch, removing this. |
||
|
||
def test_disallow_scalar_bool_ops(self): | ||
exprs = '1 or 2', '1 and 2' | ||
exprs += 'a and b', 'a or b' | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this specific to float32? Read briefly through issue and seemed like it affected other things
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@WillAyd The bug arises when one side returns a float32 and the other side is a scalar that doesn't have a 'value' attribute.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this still work if the operands are switched? i.e.
-0.1 > x
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
an you parameterize on the dtype (at least float32/float64)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will add a test with a negative value on the left.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you like a test for float64? This particular bug was caused by code that handles float32's, so float64's were fine, but I can add a test to ensure that this does not become an issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jreback Oh, I see now pytest's
parametrize
in some of the other tests, I will update this