summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorMatti Picus <matti.picus@gmail.com>2021-08-04 18:39:33 +0300
committerGitHub <noreply@github.com>2021-08-04 18:39:33 +0300
commit481e731368dd47705248b1832ebd70913e99772e (patch)
treedaef5ddf8f875b185b561ce76a8aea80555f96d5 /numpy
parentc136cb7f2982554a9ae305aafd81b9f68ac03ec5 (diff)
parent48f0cf0d317cbbfd6fff7dadf1d0ffa1add0d734 (diff)
downloadnumpy-481e731368dd47705248b1832ebd70913e99772e.tar.gz
Merge pull request #19593 from rossbar/loadtxt-supports-iterables
DOC,MAINT: Update wording surrounding `fname` parameter for loadtxt/genfromtxt
Diffstat (limited to 'numpy')
-rw-r--r--numpy/lib/npyio.py21
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,