Skip to content

Commit

Permalink
Assert that at least one file in npz zipfile ends with .npy
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mvdbeek committed Mar 25, 2024
1 parent ed69e0f commit 28c19eb
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/galaxy/datatypes/binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -4135,9 +4135,9 @@ def __init__(self, **kwd):

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
Expand Down

0 comments on commit 28c19eb

Please sign in to comment.