Skip to content

BUG?: np.fromfile on Py3k #4118

@larsoner

Description

@larsoner

I've translated some code we have from Python2 to Python3, and I think I've encountered a strange bug with np.fromfile. If I run the following code snippet:

import numpy as np

for mode in ['rb', 'rb+']:
    with open('test.w', mode) as fid:
        fid.read(2)
        pos1 = fid.tell()
        data = np.fromfile(fid, count=1)
        pos2 = fid.tell()
        print(pos1, pos2)

I get this output in Python2:

(2, 10)
(2, 10)

But this output in Python3:

2 12
2 10

This is not good, because subsequent reads from the file will not occur at correct positions. In other words, I have to add the + to the file open parameter in order to get multiple calls to fromfile to read with correct positions. I've uploaded the test file here in case someone wants to try to replicate:

http://faculty.washington.edu/larsoner/test.w

I'm running Ubuntu Linux 13.10 64-bit. I had this problem on the system version, as well as on a version I just compiled myself (with MKL support).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions