Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Signed-off-by: Wenqi Li <wenqil@nvidia.com>
  • Loading branch information
wyli committed Sep 13, 2021
1 parent c50235c commit ea59fdc
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion monai/_extensions/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def timeout(time, message):
except KeyboardInterrupt as e:
if timer is not None and timer.is_alive():
raise e # interrupt from user?
raise TimeoutError(message)
raise TimeoutError(message) from e
finally:
if timer is not None:
try:
Expand Down
2 changes: 1 addition & 1 deletion monai/data/grid_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def __iter__(self):
try:
iter_end = len(self.dataset) # TODO: support iterable self.dataset
except TypeError:
raise NotImplementedError("image dataset must implement `len()`.")
raise NotImplementedError("image dataset must implement `len()`.") from None

if worker_info is not None:
# split workload
Expand Down
4 changes: 2 additions & 2 deletions monai/data/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ def list_data_collate(batch: Sequence):
+ "`DataLoader` with `collate_fn=pad_list_data_collate` might solve this problem (check its "
+ "documentation)."
)
raise RuntimeError(re_str)
raise RuntimeError(re_str) from re
except TypeError as re:
re_str = str(re)
if "numpy" in re_str and "Tensor" in re_str:
Expand All @@ -294,7 +294,7 @@ def list_data_collate(batch: Sequence):
+ "creating your `DataLoader` with `collate_fn=pad_list_data_collate` might solve this problem "
+ "(check its documentation)."
)
raise TypeError(re_str)
raise TypeError(re_str) from re


def decollate_batch(batch, detach: bool = True):
Expand Down
2 changes: 1 addition & 1 deletion monai/transforms/inverse_batch_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def __call__(self, data: Dict[str, Any]) -> Any:
re_str = str(re)
if "equal size" in re_str:
re_str += "\nMONAI hint: try creating `BatchInverseTransform` with `collate_fn=lambda x: x`."
raise RuntimeError(re_str)
raise RuntimeError(re_str) from re


class Decollated(MapTransform):
Expand Down
4 changes: 2 additions & 2 deletions monai/utils/aliases.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ def resolve_name(name):
try:
mod = importlib.import_module(modname)
obj = getattr(mod, declname, None)
except ModuleNotFoundError:
raise ValueError(f"Module {modname!r} not found.")
except ModuleNotFoundError as not_found_err:
raise ValueError(f"Module {modname!r} not found.") from not_found_err

if obj is None:
raise ValueError(f"Module {modname!r} does not have member {declname!r}.")
Expand Down
2 changes: 1 addition & 1 deletion tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def test_pretrained_networks(network, input_param, device):
try:
net = network(**input_param).to(device)
except (URLError, HTTPError, ContentTooShortError) as e:
raise unittest.SkipTest(e)
raise unittest.SkipTest(e) from e
return net


Expand Down

0 comments on commit ea59fdc

Please sign in to comment.