-
-
Notifications
You must be signed in to change notification settings - Fork 11.9k
BUG: fix np.load() of empty .npz file #11522
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Trivial test missing for Should we prevent creating such files during savez()? Was there any discussion around that idea? |
|
@mattip There is no need for a test using As for preventing such files during |
| # 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): |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.
|
@mattip What do you think about merging this? |
|
looks good, thanks |
Fixes #9989