diff options
author | Paul Anton Letnes <paul.anton.letnes@gmail.com> | 2011-07-28 22:50:58 +0200 |
---|---|---|
committer | Ralf Gommers <ralf.gommers@googlemail.com> | 2011-07-31 13:09:38 +0200 |
commit | 72ab385d17d9067f97652aeae87a820f7de41298 (patch) | |
tree | 67415466f8bc09ce0323fd69fe692214ca09e163 /numpy/lib/npyio.py | |
parent | 2acb9282bc991c4d3789bf2f7be8a2aaf1859df0 (diff) | |
download | numpy-72ab385d17d9067f97652aeae87a820f7de41298.tar.gz |
ENH: let genfromtxt return empty array for empty input file instead of an error.
A warning for empty files is issued, including file name. Closes #1793.
Diffstat (limited to 'numpy/lib/npyio.py')
-rw-r--r-- | numpy/lib/npyio.py | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/numpy/lib/npyio.py b/numpy/lib/npyio.py index f7cde270d..44a91c0c7 100644 --- a/numpy/lib/npyio.py +++ b/numpy/lib/npyio.py @@ -1274,8 +1274,10 @@ def genfromtxt(fname, dtype=float, comments='#', delimiter=None, first_line = asbytes('').join(first_line.split(comments)[1:]) first_values = split_line(first_line) except StopIteration: - # might want to return empty array instead of raising error. - raise IOError('End-of-file reached before encountering data.') + # return an empty array if the datafile is empty + first_line = '' + first_values = [] + warnings.warn('genfromtxt: Empty input file: "%s"' % fname) # Should we take the first values as names ? if names is True: |