@@ -82,6 +82,13 @@ def __str__(self) -> str:
82
82
"IntStorage" ,
83
83
"ByteStorage" ,
84
84
},
85
+ "numpy" : {
86
+ "dtype" ,
87
+ "ndarray" ,
88
+ },
89
+ "numpy.core.multiarray" : {
90
+ "_reconstruct" ,
91
+ },
85
92
"torch._utils" : {"_rebuild_tensor_v2" },
86
93
}
87
94
@@ -141,8 +148,7 @@ def __str__(self) -> str:
141
148
# https://www.tensorflow.org/api_docs/python/tf/keras/models/load_model
142
149
#
143
150
144
- # TODO: support .npz files
145
- _numpy_file_extensions = {".npy" }
151
+ _numpy_file_extensions = {".npy" } # Note: .npz is handled as zip files
146
152
_pytorch_file_extensions = {".bin" , ".pt" , ".pth" , ".ckpt" }
147
153
_pickle_file_extensions = {".pkl" , ".pickle" , ".joblib" , ".dat" , ".data" }
148
154
_zip_file_extensions = {".zip" , ".npz" }
@@ -301,10 +307,15 @@ def scan_zip_bytes(data: IO[bytes], file_id) -> ScanResult:
301
307
file_names = zip .namelist ()
302
308
_log .debug ("Files in archive %s: %s" , file_id , file_names )
303
309
for file_name in file_names :
304
- if os .path .splitext (file_name )[1 ] in _pickle_file_extensions :
310
+ file_ext = os .path .splitext (file_name )[1 ]
311
+ if file_ext in _pickle_file_extensions :
305
312
_log .debug ("Scanning file %s in zip archive %s" , file_name , file_id )
306
313
with zip .open (file_name , "r" ) as file :
307
314
result .merge (scan_pickle_bytes (file , f"{ file_id } :{ file_name } " ))
315
+ elif file_ext in _numpy_file_extensions :
316
+ _log .debug ("Scanning file %s in zip archive %s" , file_name , file_id )
317
+ with zip .open (file_name , "r" ) as file :
318
+ result .merge (scan_numpy (file , f"{ file_id } :{ file_name } " ))
308
319
309
320
return result
310
321
@@ -323,7 +334,7 @@ def scan_numpy(data: IO[bytes], file_id) -> ScanResult:
323
334
data .seek (- min (N , len (magic )), 1 ) # back-up
324
335
if magic .startswith (_ZIP_PREFIX ) or magic .startswith (_ZIP_SUFFIX ):
325
336
# .npz file
326
- raise NotImplementedError ( "Scanning of .npz files is not implemented yet " )
337
+ raise ValueError ( f" .npz file not handled as zip file: { file_id } " )
327
338
elif magic == np .lib .format .MAGIC_PREFIX :
328
339
# .npy file
329
340
0 commit comments