summaryrefslogtreecommitdiff
path: root/numpy/lib/npyio.py
diff options
context:
space:
mode:
authorRalf Gommers <ralf.gommers@googlemail.com>2011-04-03 12:04:35 +0200
committerRalf Gommers <ralf.gommers@googlemail.com>2011-04-03 12:04:35 +0200
commite340e665adba35a5aba7fac09e28ac1f2e4d949b (patch)
tree2ac233607fc744e4f4133a84df5501346d58393e /numpy/lib/npyio.py
parenta15b605771903c85a103dc0fcad423e9a9eb3a98 (diff)
downloadnumpy-e340e665adba35a5aba7fac09e28ac1f2e4d949b.tar.gz
ENH: return empty array from loadtxt for an empty file. Closes #1752.
Thanks to Paul Anton Letnes and Derek Homeier.
Diffstat (limited to 'numpy/lib/npyio.py')
-rw-r--r--numpy/lib/npyio.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/numpy/lib/npyio.py b/numpy/lib/npyio.py
index 263aa82c2..25737cbbe 100644
--- a/numpy/lib/npyio.py
+++ b/numpy/lib/npyio.py
@@ -750,7 +750,10 @@ def loadtxt(fname, dtype=float, comments='#', delimiter=None,
while not first_vals:
first_line = fh.readline()
if not first_line: # EOF reached
- raise IOError('End-of-file reached before encountering data.')
+ # Break out of the loop here, so that we return an empty array.
+ first_line = ''
+ first_vals = []
+ break
first_vals = split_line(first_line)
N = len(usecols or first_vals)