You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think silently returning corrupt data is pretty much the worst possible behaviour in this case. Either of these options would be an improvement:
Teach np.fromfile() to read from gzip (and possible other compression formats) file objects
Raise an error explaining that NumPy can't deal with this kind of file object
At least clearly document what kind of "file object" np.fromfile() expects.
Right now, the file parameter of np.fromfile is documented as:
file : file or str
Open file object or filename.
And the file object returned from gzip.openis a file object, but apparently not the right kind. That's pretty confusing and should at least be changed in the documentation.
That's largely the fault of the gzip module: it implements the API that
enables PyObject_AsFileDescriptor, but returns a file handle to the
compressed stream.
Uh oh!
There was an error while loading. Please reload this page.
Hi, I was trying to read directly from a compressed file:
Unfortunately, this returns garbage data:
[6542475788951259935 7594864974085029634 1008947487324530028 3113290099057413416 691954333390038676 6865743131250406218]
The workaround is to load the data into a buffer first, and then let
np.frombuffer
read it:Returns:
[9 8 7 6 5 4 3 2 1]
as expected.I think silently returning corrupt data is pretty much the worst possible behaviour in this case. Either of these options would be an improvement:
np.fromfile()
to read fromgzip
(and possible other compression formats) file objectsnp.fromfile()
expects.Right now, the
file
parameter ofnp.fromfile
is documented as:And the file object returned from
gzip.open
is a file object, but apparently not the right kind. That's pretty confusing and should at least be changed in the documentation.Operating System: Fedora 27, 64-Bit
Python version: 3.6.4
NumPy version: 1.13.3
The text was updated successfully, but these errors were encountered: