Skip to content

Conversation

@jzwinck
Copy link
Contributor

@jzwinck jzwinck commented Jul 7, 2018

Fixes #9989

@mattip
Copy link
Member

mattip commented Jul 7, 2018

Trivial test missing for savez_compressed(), just to be complete`.

Should we prevent creating such files during savez()? Was there any discussion around that idea?

@jzwinck
Copy link
Contributor Author

jzwinck commented Jul 7, 2018

@mattip There is no need for a test using savez_compressed(), because (1) the fixed bug is in load(), and (2) an empty Zip file doesn't really have a compression level, so savez_compressed() is exactly the same as savez() when no arrays are stored.

As for preventing such files during savez(), I don't prefer that because it breaks backward compatibility. Some people might want to save empty .npz files, and I haven't seen anyone complain that savez() works with no arrays.

# to seek past the beginning of the file
fid.seek(-min(N, len(magic)), 1) # back-up
if magic.startswith(_ZIP_PREFIX):
if magic.startswith(_ZIP_PREFIX) or magic.startswith(_ZIP_SUFFIX):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps worth noting that when np.loadtxt receives an empty input file it emits:
UserWarning: loadtxt: Empty input file

I'm not necessarily saying that should happen here, but just thought I'd bring that up in case some consistency with empty file loading is desired across functions. If we did want to do that, one could presumably just adjust the unit test to check for the appropriate warning (and still not allow an exception, obviously).

Copy link
Contributor Author

@jzwinck jzwinck Jul 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tylerjereddy Loading an empty text file is fundamentally not the same as loading an empty archive. Note that np.load() of a npy file containing a single empty array does not warn. Loading an empty text file is different, because there is really no way to guess what the dtype is supposed to be. Here there's no such problem.

@jzwinck
Copy link
Contributor Author

jzwinck commented Jul 28, 2018

@mattip What do you think about merging this?

@juliantaylor juliantaylor merged commit e3c2843 into numpy:master Jul 29, 2018
@juliantaylor
Copy link
Contributor

looks good, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants