summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBijesh Mohan <bijeshmohankm@gmail.com>2020-09-16 20:04:09 +0530
committerBijesh Mohan <bijeshmohankm@gmail.com>2020-09-16 20:15:04 +0530
commit260f2f144018f1c4c3de171160dc53b5c642b205 (patch)
treef28a575ac2a66c052916de62447d437cf9af4161
parentbd263912e11f7f79310c5516fab6bd0a7b7c8eb9 (diff)
downloadnumpy-260f2f144018f1c4c3de171160dc53b5c642b205.tar.gz
MAINT: Chaining exceptions in npyio.py
-rw-r--r--numpy/lib/npyio.py10
1 files changed, 5 insertions, 5 deletions
diff --git a/numpy/lib/npyio.py b/numpy/lib/npyio.py
index 90e16643c..805e59bc1 100644
--- a/numpy/lib/npyio.py
+++ b/numpy/lib/npyio.py
@@ -86,7 +86,7 @@ class BagObj:
try:
return object.__getattribute__(self, '_obj')[key]
except KeyError:
- raise AttributeError(key)
+ raise AttributeError(key) from None
def __dir__(self):
"""
@@ -446,9 +446,9 @@ def load(file, mmap_mode=None, allow_pickle=False, fix_imports=True,
"when allow_pickle=False")
try:
return pickle.load(fid, **pickle_kwargs)
- except Exception:
+ except Exception as e:
raise IOError(
- "Failed to interpret file %s as a pickle" % repr(file))
+ "Failed to interpret file %s as a pickle" % repr(file)) from e
def _save_dispatcher(file, arr, allow_pickle=None, fix_imports=None):
@@ -1435,10 +1435,10 @@ def savetxt(fname, X, fmt='%.18e', delimiter=' ', newline='\n', header='',
for row in X:
try:
v = format % tuple(row) + newline
- except TypeError:
+ except TypeError as e:
raise TypeError("Mismatch between array dtype ('%s') and "
"format specifier ('%s')"
- % (str(X.dtype), format))
+ % (str(X.dtype), format)) from e
fh.write(v)
if len(footer) > 0: