From cb71c43d45c0ad6e14db97a51e317b771f6a9ebb Mon Sep 17 00:00:00 2001 From: Abhay Raghuvanshi Date: Fri, 19 Mar 2021 04:45:07 +0530 Subject: MAINT: Added Chain exceptions where appropriate (#18400) * Added chain exception in _pocketfft.py * Added chain exception in format.py * Added chain exception in make_lite.py * Added chain exception in mrecords.py * added from e for exceptions * Minor update for _read_array_header exception msg * Removed \n from excp msg and e from msg format. Co-authored-by: Eric Wieser * Update numpy/linalg/lapack_lite/make_lite.py Co-authored-by: Eric Wieser Co-authored-by: Eric Wieser Co-authored-by: Charles Harris --- numpy/fft/_pocketfft.py | 2 +- numpy/lib/format.py | 4 ++-- numpy/ma/mrecords.py | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'numpy') diff --git a/numpy/fft/_pocketfft.py b/numpy/fft/_pocketfft.py index bf0e60b6d..4ed3042a6 100644 --- a/numpy/fft/_pocketfft.py +++ b/numpy/fft/_pocketfft.py @@ -112,7 +112,7 @@ def _swap_direction(norm): return _SWAP_DIRECTION_MAP[norm] except KeyError: raise ValueError(f'Invalid norm value {norm}; should be "backward", ' - '"ortho" or "forward".') + '"ortho" or "forward".') from None def _fft_dispatcher(a, n=None, axis=None, norm=None): diff --git a/numpy/lib/format.py b/numpy/lib/format.py index ac5f75fba..904c32cc7 100644 --- a/numpy/lib/format.py +++ b/numpy/lib/format.py @@ -594,8 +594,8 @@ def _read_array_header(fp, version): try: d = safe_eval(header) except SyntaxError as e: - msg = "Cannot parse header: {!r}\nException: {!r}" - raise ValueError(msg.format(header, e)) from None + msg = "Cannot parse header: {!r}" + raise ValueError(msg.format(header)) from e if not isinstance(d, dict): msg = "Header is not a dictionary: {!r}" raise ValueError(msg.format(d)) diff --git a/numpy/ma/mrecords.py b/numpy/ma/mrecords.py index 126bdd9dc..9ea4e4e36 100644 --- a/numpy/ma/mrecords.py +++ b/numpy/ma/mrecords.py @@ -660,8 +660,8 @@ def openfile(fname): # Try to open the file and guess its type try: f = open(fname) - except IOError: - raise IOError(f"No such file: '{fname}'") + except IOError as e: + raise IOError(f"No such file: '{fname}'") from e if f.readline()[:2] != "\\x": f.seek(0, 0) return f -- cgit v1.2.1