-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: float truncation in eval with py 2 #14255
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -678,6 +678,31 @@ def test_line_continuation(self): | |
result = pd.eval(exp, engine=self.engine, parser=self.parser) | ||
self.assertEqual(result, 12) | ||
|
||
def test_float_truncation(self): | ||
# GH 14241 | ||
exp = '1000000000.006' | ||
result = pd.eval(exp, engine=self.engine, parser=self.parser) | ||
expected = np.float64(exp) | ||
self.assertEqual(result, expected) | ||
|
||
df = pd.DataFrame({'A': [1000000000.0009, | ||
1000000000.0011, | ||
1000000000.0015]}) | ||
cutoff = 1000000000.0006 | ||
result = df.query("A < %.4f" % cutoff) | ||
self.assertTrue(result.empty) | ||
|
||
cutoff = 1000000000.0010 | ||
result = df.query("A > %.4f" % cutoff) | ||
expected = df.loc[[1, 2], :] | ||
tm.assert_frame_equal(expected, result) | ||
|
||
exact = 1000000000.0011 | ||
result = df.query('A == %.4f' % exact) | ||
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. oh I didn't mean for this last one to be 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. I know float precision is thorny generally, but shouldn't this be guaranteed with HDF5? |
||
expected = df.loc[[1], :] | ||
tm.assert_frame_equal(expected, result) | ||
|
||
|
||
|
||
class TestEvalNumexprPython(TestEvalNumexprPandas): | ||
|
||
|
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 bet this is a similar problem when selecting from pytables, can you add a test for that?
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.
Added a test/fix for this