diff --git a/numpy/lib/npyio.py b/numpy/lib/npyio.py index f7cde270d4a2..44a91c0c7995 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: diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py index f9da258dc583..55068b7ab561 100644 --- a/numpy/lib/tests/test_io.py +++ b/numpy/lib/tests/test_io.py @@ -959,12 +959,11 @@ def test_usecols_with_named_columns(self): usecols=('a', 'c'), **kwargs) assert_equal(test, ctrl) - def test_empty_file(self): "Test that an empty file raises the proper exception" data = StringIO() - assert_raises(IOError, np.ndfromtxt, data) - + test = np.genfromtxt(data) + assert_equal(test, np.array([])) def test_fancy_dtype_alt(self): "Check that a nested dtype isn't MIA"