Skip to content

Commit 8268b17

Browse files
committed
Add exception message about pickle loading.
Signed-off-by: Eric Kerfoot <17726042+ericspod@users.noreply.github.com>
1 parent 6cad5d9 commit 8268b17

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

monai/data/image_reader.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1285,7 +1285,16 @@ def read(self, data: Sequence[PathLike] | PathLike, **kwargs):
12851285
kwargs_ = self.kwargs.copy()
12861286
kwargs_.update(kwargs)
12871287
for name in filenames:
1288-
img = np.load(name, allow_pickle=self.allow_pickle, **kwargs_)
1288+
try:
1289+
img = np.load(name, allow_pickle=self.allow_pickle, **kwargs_)
1290+
except ValueError as e:
1291+
# if a ValueError is raised, this is likely about pickle loading so raise an exception about this
1292+
raise ValueError(
1293+
"MONAI default value for argument `allow_pickle` of `np.load` changed to `False`, "
1294+
"explicitly pass `allow_pickle=True` as a constructor argument to NumpyReader "
1295+
"to enable pickle loading."
1296+
) from e
1297+
12891298
if Path(name).name.endswith(".npz"):
12901299
# load expected items from NPZ file
12911300
npz_keys = list(img.keys()) if self.npz_keys is None else self.npz_keys

0 commit comments

Comments
 (0)