-
-
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #25928 +/- ##
==========================================
- Coverage 91.8% 91.79% -0.01%
==========================================
Files 174 174
Lines 52536 52536
==========================================
- Hits 48231 48226 -5
- Misses 4305 4310 +5
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #25928 +/- ##
==========================================
- Coverage 91.8% 91.8% -0.01%
==========================================
Files 174 175 +1
Lines 52536 52578 +42
==========================================
+ Hits 48231 48269 +38
- Misses 4305 4309 +4
Continue to review full report at Codecov.
|
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.
Can you add a whatsnew note for v0.25?
# 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 comment
The reason will be displayed to describe this comment to others. Learn more.
What's the reason for , res
here? I think also causing CI failure
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.
Good catch, removing this.
@@ -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)}) |
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.
Does this still work if the operands are switched? i.e.
-0.1 > x
?
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.
an you parameterize on the dtype (at least float32/float64)
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
doc/source/whatsnew/v0.25.0.rst
Outdated
@@ -228,6 +228,7 @@ Performance Improvements | |||
Bug Fixes | |||
~~~~~~~~~ | |||
|
|||
- Bug in :meth:`~pandas.eval` when comparing floats with scalar operators that don't have a 'value' attribute (e.g., unary operators) (:issue:`25928`) |
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.
can you move down to numeric section.
make this more like:
Bug in :meth:`~pandas.eval` when comparing floats with scalar operators, for example: ``x < 0.1`` (: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.
Yep, will do.
@@ -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)}) |
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)
@jreback Should be ready for another review. |
thanks @alexcwatt |
@jreback & @alexcwatt - this was also an issue for string data, as I showed in this previous comment on #16363 : The test case is:
Is that also fixed now? If not, we should keep #16363 open as not fixed. |
you can test on master and if not pls open. new issue if it works then can add an additional test (pls do a PR) |
I don't think I'll have time for that very soon, I'd recommend just re-opening #16363 until the full set of problems identified in the ticket can be verified as fixed. |
plan make a new issue instead |
git diff upstream/master -u -- "*.py" | flake8 --diff
Checking
hasattr(side, 'value')
resolves the bug and is consistent with the way that other methods of theBaseExprVisitor
class work (e.g., bothvisit_Call_35
andvisit_Call_legacy
check for 'value').