diff options
author | Kerem HallaƧ <hallackerem@gmail.com> | 2020-07-01 00:44:10 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-30 16:44:10 -0500 |
commit | f38073be387190b7a6db3a1e064594d0c3fd695f (patch) | |
tree | ee6f1a58c75c11f53587334c3d1da3b4d0d2eca4 | |
parent | 4dc50ca33258c587cb8034d5c91d561343e97fc8 (diff) | |
download | numpy-f38073be387190b7a6db3a1e064594d0c3fd695f.tar.gz |
MAINT: Chain exceptions in npyio.py (gh16121)
this solution is related to the following issue #15986
Co-authored-by: Ross Barnowski <rossbar@berkeley.edu>
-rw-r--r-- | numpy/lib/npyio.py | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/numpy/lib/npyio.py b/numpy/lib/npyio.py index 6d6222d3e..3d7d3e08f 100644 --- a/numpy/lib/npyio.py +++ b/numpy/lib/npyio.py @@ -1083,8 +1083,10 @@ def loadtxt(fname, dtype=float, comments='#', delimiter=None, else: fh = iter(fname) fencoding = getattr(fname, 'encoding', 'latin1') - except TypeError: - raise ValueError('fname must be a string, file handle, or generator') + except TypeError as e: + raise ValueError( + 'fname must be a string, file handle, or generator' + ) from e # input may be a python2 io stream if encoding is not None: @@ -1768,10 +1770,10 @@ def genfromtxt(fname, dtype=float, comments='#', delimiter=None, fid = fname fid_ctx = contextlib_nullcontext(fid) fhd = iter(fid) - except TypeError: + except TypeError as e: raise TypeError( "fname must be a string, filehandle, list of strings, " - "or generator. Got %s instead." % type(fname)) + "or generator. Got %s instead." % type(fname)) from e with fid_ctx: split_line = LineSplitter(delimiter=delimiter, comments=comments, |