summaryrefslogtreecommitdiff
path: root/numpy/lib/npyio.py
diff options
context:
space:
mode:
authormfkasim91 <firman.kasim@gmail.com>2018-09-16 11:29:40 +0100
committermattip <matti.picus@gmail.com>2018-09-30 13:39:09 +0300
commit9e86f6311a88a989241fd34da39dcccce08a19dc (patch)
tree855d885b16772e99543181505021d8fe127e8cef /numpy/lib/npyio.py
parent88c01b8ab4260b938f23f88f8a5f385fd361bc33 (diff)
downloadnumpy-9e86f6311a88a989241fd34da39dcccce08a19dc.tar.gz
ENH: add max_rows kwarg to numpy.loadtxt like numpy.genfromtxt
Diffstat (limited to 'numpy/lib/npyio.py')
-rw-r--r--numpy/lib/npyio.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/numpy/lib/npyio.py b/numpy/lib/npyio.py
index d8cfbf769..6e1d26bb9 100644
--- a/numpy/lib/npyio.py
+++ b/numpy/lib/npyio.py
@@ -773,7 +773,7 @@ _loadtxt_chunksize = 50000
def loadtxt(fname, dtype=float, comments='#', delimiter=None,
converters=None, skiprows=0, usecols=None, unpack=False,
- ndmin=0, encoding='bytes'):
+ ndmin=0, encoding='bytes', max_rows=None):
"""
Load data from a text file.
@@ -835,6 +835,11 @@ def loadtxt(fname, dtype=float, comments='#', delimiter=None,
the system default is used. The default value is 'bytes'.
.. versionadded:: 1.14.0
+ max_rows : int, optional
+ Read `max_rows` lines of content after `skiprows` lines. The default
+ (`None`) is to read all the lines.
+
+ .. versionadded:: 1.16.0
Returns
-------
@@ -1014,7 +1019,9 @@ def loadtxt(fname, dtype=float, comments='#', delimiter=None,
"""
X = []
- for i, line in enumerate(itertools.chain([first_line], fh)):
+ line_iter = itertools.chain([first_line], fh)
+ line_iter = itertools.islice(line_iter, max_rows)
+ for i, line in enumerate(line_iter):
vals = split_line(line)
if len(vals) == 0:
continue