8000 Ticket #1793 by pletnes · Pull Request #123 · numpy/numpy · GitHub
[go: up one dir, main page]

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 1 commit
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
Prev Previous commit
Next Next commit
Ticket #1793 patch: genfromtxt now returns an empty array if the input
file is empty.  The unit test has been rewritten to check for this and
the test is passed.
  • Loading branch information
pletnes committed Jul 28, 2011
commit ef3915a0b431ea74f3346d849f735a22d417b362
5 changes: 3 additions & 2 deletions numpy/lib/npyio.py
Original file line number Diff line number Diff line change
Expand Up @@ -1274,8 +1274,9 @@ 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 = []

# Should we take the first values as names ?
if names is True:
Expand Down
6 changes: 3 additions & 3 deletions numpy/lib/tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -959,12 +959,12 @@ 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)
ctrl = np.array([])
assert_equal(test, ctrl)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could probably shorten this to simply assert_equal(test, [])


def test_fancy_dtype_alt(self):
"Check that a nested dtype isn't MIA"
Expand Down
0