Assert that at least one file in npz zipfile ends with .npy

from https://pydoc.dev/numpy/latest/numpy.lib.npyio.NpzFile.html:

> NpzFile is used to load files in the NumPy .npz data archive format. It assumes that files in the archive have a .npy extension, other files are ignored.
This commit is contained in:
mvdbeek
2024-03-25 09:20:50 +01:00
parent ed69e0f821
commit 28c19ebadf
+3 -3
View File
@@ -4135,9 +4135,9 @@ class Npz(CompressedArchive):
def sniff(self, filename: str) -> bool:
try:
npz = np.load(filename)
if isinstance(npz, np.lib.npyio.NpzFile):
return True
with np.load(filename) as npz:
if isinstance(npz, np.lib.npyio.NpzFile) and any(f.filename.endswith(".npy") for f in npz.zip.filelist):
return True
except Exception:
return False
return False