diff options
| -rw-r--r-- | numpy/lib/npyio.py | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/numpy/lib/npyio.py b/numpy/lib/npyio.py index 225b22a5c..07179fe86 100644 --- a/numpy/lib/npyio.py +++ b/numpy/lib/npyio.py @@ -838,10 +838,11 @@ def loadtxt(fname, dtype=float, comments='#', delimiter=None, Parameters ---------- - fname : file, str, or pathlib.Path - File, filename, or generator to read. If the filename extension is - ``.gz`` or ``.bz2``, the file is first decompressed. Note that - generators should return byte strings. + fname : file, str, pathlib.Path, list of str, generator + File, filename, list, or generator to read. If the filename + extension is ``.gz`` or ``.bz2``, the file is first decompressed. Note + that generators must return bytes or strings. The strings + in a list or produced by a generator are treated as lines. dtype : data-type, optional Data-type of the resulting array; default: float. If this is a structured data-type, the resulting array will be 1-dimensional, and @@ -1081,7 +1082,8 @@ def loadtxt(fname, dtype=float, comments='#', delimiter=None, fencoding = getattr(fname, 'encoding', 'latin1') except TypeError as e: raise ValueError( - 'fname must be a string, file handle, or generator' + f"fname must be a string, filehandle, list of strings,\n" + f"or generator. Got {type(fname)} instead." ) from e # input may be a python2 io stream @@ -1586,8 +1588,8 @@ def genfromtxt(fname, dtype=float, comments='#', delimiter=None, ---------- fname : file, str, pathlib.Path, list of str, generator File, filename, list, or generator to read. If the filename - extension is `.gz` or `.bz2`, the file is first decompressed. Note - that generators must return byte strings. The strings + extension is ``.gz`` or ``.bz2``, the file is first decompressed. Note + that generators must return bytes or strings. The strings in a list or produced by a generator are treated as lines. dtype : dtype, optional Data type of the resulting array. @@ -1806,8 +1808,9 @@ def genfromtxt(fname, dtype=float, comments='#', delimiter=None, fhd = iter(fid) except TypeError as e: raise TypeError( - "fname must be a string, filehandle, list of strings, " - "or generator. Got %s instead." % type(fname)) from e + f"fname must be a string, filehandle, list of strings,\n" + f"or generator. Got {type(fname)} instead." + ) from e with fid_ctx: split_line = LineSplitter(delimiter=delimiter, comments=comments, |
