diff options
author | Chris Holland <41524756+ChrisAHolland@users.noreply.github.com> | 2020-05-01 05:01:45 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-01 15:01:45 +0300 |
commit | ae6ba5d215451273990f2826f2cf28f091d71446 (patch) | |
tree | 7f00e0a7f5be2d587ed17ad90a0ca99f932b23a5 | |
parent | 6f8d7fd467b69229c0a7ed3662966573e8b3d85c (diff) | |
download | numpy-ae6ba5d215451273990f2826f2cf28f091d71446.tar.gz |
MAINT: Chain exceptions in memmap.py and core.py (#16067)
* Improve chained exception reporting
Co-authored-by: Eric Wieser <wieser.eric@gmail.com>
-rw-r--r-- | numpy/core/memmap.py | 8 | ||||
-rw-r--r-- | numpy/ma/core.py | 6 |
2 files changed, 9 insertions, 5 deletions
diff --git a/numpy/core/memmap.py b/numpy/core/memmap.py index ad66446c2..cb025736e 100644 --- a/numpy/core/memmap.py +++ b/numpy/core/memmap.py @@ -209,10 +209,12 @@ class memmap(ndarray): import os.path try: mode = mode_equivalents[mode] - except KeyError: + except KeyError as e: if mode not in valid_filemodes: - raise ValueError("mode must be one of %s" % - (valid_filemodes + list(mode_equivalents.keys()))) + raise ValueError( + "mode must be one of {!r} (got {!r})" + .format(valid_filemodes + list(mode_equivalents.keys()), mode) + ) from None if mode == 'w+' and shape is None: raise ValueError("shape must be given") diff --git a/numpy/ma/core.py b/numpy/ma/core.py index a5e59bb74..a7214f9bf 100644 --- a/numpy/ma/core.py +++ b/numpy/ma/core.py @@ -285,8 +285,10 @@ def _extremum_fill_value(obj, extremum, extremum_name): def _scalar_fill_value(dtype): try: return extremum[dtype] - except KeyError: - raise TypeError(f"Unsuitable type {dtype} for calculating {extremum_name}.") + except KeyError as e: + raise TypeError( + f"Unsuitable type {dtype} for calculating {extremum_name}." + ) from None dtype = _get_dtype_of(obj) return _recursive_fill_value(dtype, _scalar_fill_value) |