Skip to content

Ticket #1793 #123

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions numpy/lib/npyio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 2 additions & 3 deletions numpy/lib/tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down