-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
Incorrect conversion to Int64 by loadtxt (traced to _getconv in numpy.lib.io) (Trac #1163) #1761
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
Comments
Milestone changed to |
@WarrenWeckesser wrote on 2010-08-18 There is a thread in the mailing list about this problem: |
Milestone changed to |
trac user dynetrekk wrote on 2011-03-26 I suggest a patch here. The patch will work both for long int as well as for converting floats into ints.
|
@rgommers wrote on 2011-03-31 It would be helpful if the patch includes a test. |
Milestone changed to |
Original ticket http://projects.scipy.org/numpy/ticket/1163 on 2009-07-09 by trac user onsi, assigned to unknown.
I'm running version 1.2.1 but this error should also occur in 1.3.0 based on the source currently in the trunk.
I try importing the following ascii data stored in "sample.csv":
9007200000000000,670927001710,0.010190886[[BR]]
9007200000000001,660927001348,0.00976051[[BR]]
9007200000000002,650883003926,0.009154096
using (maximal verbosity for clarity):
I get:
[(9007200000000000L, 670927001710L, 0.010190886445343494)[[BR]](9007200000000000L, 660927001348L, 0.0097605101764202118)[[BR]](9007200000000002L, 650883003926L, 0.009154096245765686)][[BR]]
After some digging, i found the culprit to be the converter used by loadtxt to convert strings to dtypes. lib.io._getconv (line 352 in trunk) returns:
as the converter for any dtype that is a subclass of int, which int64 is. Unfortunately, float does not faithfully reproduce long integers and so 9007200000000001 gets rounded to 9007200000000000.
This is fairly serious as int64s are often used as IDs in various numerical/simulation contexts. Changing the converter to int() should resolve this problem -- though then some error checking needs to take place to ensure that int is fed an integer string.
The text was updated successfully, but these errors were encountered: