From 99acd16d9582a78b11561108b63db3aacb042ccc Mon Sep 17 00:00:00 2001 From: Maxwell Aladago Date: Sun, 11 Aug 2019 09:47:12 -0400 Subject: fixes StopIteration error for empty file with skip_header > 0 --- numpy/lib/npyio.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'numpy/lib/npyio.py') diff --git a/numpy/lib/npyio.py b/numpy/lib/npyio.py index b9dc444f8..746e6043a 100644 --- a/numpy/lib/npyio.py +++ b/numpy/lib/npyio.py @@ -1776,12 +1776,13 @@ def genfromtxt(fname, dtype=float, comments='#', delimiter=None, replace_space=replace_space) # Skip the first `skip_header` rows - for i in range(skip_header): - next(fhd) - - # Keep on until we find the first valid values - first_values = None try: + for i in range(skip_header): + next(fhd) + + # Keep on until we find the first valid values + first_values = None + while not first_values: first_line = _decode_line(next(fhd), encoding) if (names is True) and (comments is not None): -- cgit v1.2.1