[NumPy-Tickets] [NumPy] #1565: loadtxt fails to load large unsigned int64 integers.

NumPy Trac numpy-tickets@scipy....
Wed Jul 28 17:02:28 CDT 2010


#1565: loadtxt fails to load large unsigned int64 integers.
-------------------------+--------------------------------------------------
 Reporter:  rainwoodman  |       Owner:  somebody
     Type:  defect       |      Status:  new     
 Priority:  normal       |   Milestone:  1.5.0   
Component:  Other        |     Version:  1.4.0   
 Keywords:               |  
-------------------------+--------------------------------------------------
 Prepare the following file:

 -------file /tmp/test -----
 9223372043271415339
 9223372043271415853
 9223372043271415612
 9223372043271416107
 9223372043271415594
 9223372043271415836
 9223372043761290139
 9223372044088967272
 9223372044088967273
 9223372043925949039
 ---------end of file-----

 And run the following code:

 In [16]: print loadtxt('/tmp/test', dtype='uint64')
 -------> print(loadtxt('/tmp/test', dtype='uint64'))
 [9223372043271415808 9223372043271415808 9223372043271415808
  9223372043271415808 9223372043271415808 9223372043271415808
  9223372043761289216 9223372044088967168 9223372044088967168
  9223372043925948416]

 On the other hand, with fromfile(),

 In [2]: print fromfile('/tmp/test', dtype='uint64', sep=' ')
 ------> print(fromfile('/tmp/test', dtype='uint64', sep=' '))
 [9223372043271415339 9223372043271415853 9223372043271415612
  9223372043271416107 9223372043271415594 9223372043271415836
  9223372043761290139 9223372044088967272 9223372044088967273
  9223372043925949039]

 Clearly the first few numbers are wrongly converted by loadtxt

 The problem was tracked to line 453 in numpy/lib/io.py, _getconv. The
 conversion for np.integer is int(float(x)), which is inexact for large
 integers.

 I don't know if a priority of normal is appropriate, as this bug will
 produce hidden errors in programs that use numpy.

-- 
Ticket URL: <http://projects.scipy.org/numpy/ticket/1565>
NumPy <http://projects.scipy.org/numpy>
My example project


More information about the NumPy-Tickets mailing list