summaryrefslogtreecommitdiff
path: root/numpy/lib/npyio.py
diff options
context:
space:
mode:
authorJohn Zwinck <jzwinck@gmail.com>2018-07-07 10:14:46 +0800
committerJohn Zwinck <jzwinck@gmail.com>2018-07-07 10:16:23 +0800
commit4c74e384a7ec961d171b7d6a0fbf20b2bc831c28 (patch)
tree09f4e4b24dd3723e8180dce59a90211fbcc9939e /numpy/lib/npyio.py
parent8eee9b7d3836b8d080b50e2dfb3ba98537a076c0 (diff)
downloadnumpy-4c74e384a7ec961d171b7d6a0fbf20b2bc831c28.tar.gz
BUG: fix np.load() of empty .npz file
Fixes #9989
Diffstat (limited to 'numpy/lib/npyio.py')
-rw-r--r--numpy/lib/npyio.py3
1 files changed, 2 insertions, 1 deletions
diff --git a/numpy/lib/npyio.py b/numpy/lib/npyio.py
index 7788ac319..d8cfbf769 100644
--- a/numpy/lib/npyio.py
+++ b/numpy/lib/npyio.py
@@ -412,12 +412,13 @@ def load(file, mmap_mode=None, allow_pickle=True, fix_imports=True,
try:
# Code to distinguish from NumPy binary files and pickles.
_ZIP_PREFIX = b'PK\x03\x04'
+ _ZIP_SUFFIX = b'PK\x05\x06' # empty zip files start with this
N = len(format.MAGIC_PREFIX)
magic = fid.read(N)
# If the file size is less than N, we need to make sure not
# 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):
# zip-file (assume .npz)
# Transfer file ownership to NpzFile
tmp = own_fid