From 9c68c2f7b1b2128a3b4af2134565f60d286fa8b9 Mon Sep 17 00:00:00 2001 From: Abhay Raghuvanshi Date: Fri, 19 Mar 2021 01:49:20 +0530 Subject: MAINT: Added Chain exceptions where appropriate (#18394) * Added chain exception in _bits_of func * Added chain exception * Added chain exception in unixccompiler.py * Added chain exception in config.py * Added chain exception in fcompiler __init__.py * Added chain exception in compaq.py * Added chain exception in format.py * Updated raise chain exception * STY: Break long line. Co-authored-by: Charles Harris --- numpy/lib/format.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'numpy/lib/format.py') diff --git a/numpy/lib/format.py b/numpy/lib/format.py index 5d951e262..ac5f75fba 100644 --- a/numpy/lib/format.py +++ b/numpy/lib/format.py @@ -378,7 +378,7 @@ def _wrap_header(header, version): header_prefix = magic(*version) + struct.pack(fmt, hlen + padlen) except struct.error: msg = "Header length {} too big for version={}".format(hlen, version) - raise ValueError(msg) + raise ValueError(msg) from None # Pad the header with spaces and a final newline such that the magic # string, the header-length short and the header are aligned on a @@ -595,7 +595,7 @@ def _read_array_header(fp, version): d = safe_eval(header) except SyntaxError as e: msg = "Cannot parse header: {!r}\nException: {!r}" - raise ValueError(msg.format(header, e)) + raise ValueError(msg.format(header, e)) from None if not isinstance(d, dict): msg = "Header is not a dictionary: {!r}" raise ValueError(msg.format(d)) @@ -614,9 +614,9 @@ def _read_array_header(fp, version): raise ValueError(msg.format(d['fortran_order'])) try: dtype = descr_to_dtype(d['descr']) - except TypeError: + except TypeError as e: msg = "descr is not a valid dtype descriptor: {!r}" - raise ValueError(msg.format(d['descr'])) + raise ValueError(msg.format(d['descr'])) from e return d['shape'], d['fortran_order'], dtype -- cgit v1.2.1