From 72ab385d17d9067f97652aeae87a820f7de41298 Mon Sep 17 00:00:00 2001 From: Paul Anton Letnes Date: Thu, 28 Jul 2011 22:50:58 +0200 Subject: 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. --- numpy/lib/tests/test_io.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'numpy/lib/tests/test_io.py') diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py index f9da258dc..18585375e 100644 --- a/numpy/lib/tests/test_io.py +++ b/numpy/lib/tests/test_io.py @@ -5,6 +5,7 @@ import threading from tempfile import mkstemp, NamedTemporaryFile import time from datetime import datetime +import warnings import numpy as np import numpy.ma as ma @@ -637,7 +638,6 @@ class TestFromTxt(TestCase): assert_equal(test, ctrl) def test_skip_footer_with_invalid(self): - import warnings basestr = '1 1\n2 2\n3 3\n4 4\n5 \n6 \n7 \n' warnings.filterwarnings("ignore") # Footer too small to get rid of all invalid values @@ -959,12 +959,12 @@ M 33 21.99 usecols=('a', 'c'), **kwargs) assert_equal(test, ctrl) - def test_empty_file(self): - "Test that an empty file raises the proper exception" + "Test that an empty file raises the proper warning." + warnings.filterwarnings("ignore", message="genfromtxt: Empty input file:") 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" @@ -1440,5 +1440,6 @@ def test_npzfile_dict(): assert_('x' in list(z.iterkeys())) + if __name__ == "__main__": run_module_suite() -- cgit v1.2.1