8000 loadtxt fails to load large unsigned int64 integers. (Trac #1565) · Issue #2162 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content
loadtxt fails to load large unsigned int64 integers. (Trac #1565) #2162
Closed
@numpy-gitbot

Description

@numpy-gitbot

Original ticket http://projects.scipy.org/numpy/ticket/1565 on 2010-07-28 by @fengy-research, assigned to unknown.

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0