Skip to content

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

Closed
wants to merge 6 commits into from

Conversation

chris-b1
Copy link
Contributor

@chris-b1 chris-b1 commented Sep 20, 2016

Python 2 only - apparently str() rounds shorter than repr()

In [1]: f = 1000000000.006

In [2]: str(f)
Out[2]: '1000000000.01'

In [3]: repr(f)
Out[3]: '1000000000.006'

@codecov-io
Copy link

codecov-io commented Sep 20, 2016

Current coverage is 85.25% (diff: 100%)

Merging #14255 into master will increase coverage by <.01%

@@             master     #14255   diff @@
==========================================
  Files           140        140          
  Lines         50568      50572     +4   
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
+ Hits          43112      43116     +4   
  Misses         7456       7456          
  Partials          0          0          

Powered by Codecov. Last update a7469cf...d679aa3

@jreback jreback added Bug Compat pandas objects compatability with Numpy or Python functions labels Sep 20, 2016
@jreback jreback added this to the 0.19.0 milestone Sep 20, 2016
def __unicode__(self):
# in python 2 str() of float
# can truncate shorter than repr()
return repr(self.name)
Copy link
Contributor

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?

Copy link
Contributor Author

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

@jreback
Copy link
Contributor

jreback commented Sep 21, 2016

can you change the pytables test to add 3 values, then have the scalar select the middle one select and having it return empty doesn't prove it works, more like proves it doesn't not work :>

tm.assert_frame_equal(expected, result)

exact = 1000000000.0011
result = df.query('A == %.4f' % exact)
Copy link
Contributor

Choose a reason for hiding this comment

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

oh I didn't mean for this last one to be ==, it might work but I wouldn't guarantee it (as float equality esp when you store may not be guaranteed )

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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?

@jreback
Copy link
Contributor

jreback commented Sep 21, 2016

i don't know how equality of floats works in numexpr / HDF5

it might test well for us but fail on some platforms (just a guess) - so include if passes

@jreback jreback closed this in 14a1c80 Sep 22, 2016
@jreback
Copy link
Contributor

jreback commented Sep 22, 2016

thanks!

@chris-b1 chris-b1 deleted the eval-float-cast branch September 24, 2016 14:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Compat pandas objects compatability with Numpy or Python functions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DataFrame Query Rounding Error
3 participants