8000 MAINT: Chain exceptions in several places by keremh · Pull Request #16121 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

MAINT: Chain exceptions in several places #16121

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 30, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions numpy/lib/npyio.py
Original file line number Diff line number Diff line change
Expand Up @@ -1083,8 +1083,10 @@ def read_data(chunk_size):
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:
Expand Down Expand Up @@ -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,
Expand Down
0