summaryrefslogtreecommitdiff
path: root/numpy/lib/tests/test_io.py
diff options
context:
space:
mode:
authorpierregm <pierregm@localhost>2009-10-05 06:46:22 +0000
committerpierregm <pierregm@localhost>2009-10-05 06:46:22 +0000
commit31de18a3c12a748d4a929fa1d00a056e1d02b892 (patch)
treee57a6a752685845d8b190e97ce3def035650d0e4 /numpy/lib/tests/test_io.py
parent3cebdec318dd5e188eb45bc034264c68722457b9 (diff)
downloadnumpy-31de18a3c12a748d4a929fa1d00a056e1d02b892.tar.gz
* Add warnings to genfromtxt describing inconsistencies in the number of columns (bug #1212)
Diffstat (limited to 'numpy/lib/tests/test_io.py')
-rw-r--r--numpy/lib/tests/test_io.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py
index 185ceef7c..ecf87980b 100644
--- a/numpy/lib/tests/test_io.py
+++ b/numpy/lib/tests/test_io.py
@@ -825,6 +825,44 @@ M 33 21.99
assert_equal(test, control)
+ def test_invalid_raise(self):
+ "Test invalid raise"
+ data = ["1, 1, 1, 1, 1"] * 50
+ for i in range(5):
+ data[10 * i] = "2, 2, 2, 2 2"
+ data.insert(0, "a, b, c, d, e")
+ mdata = StringIO.StringIO("\n".join(data))
+ #
+ mtest = np.ndfromtxt(mdata, delimiter=",", names=True, dtype=None,)
+ assert_equal(len(mtest), 45)
+ assert_equal(mtest, np.ones(45, dtype=[(_, int) for _ in 'abcde']))
+ #
+ mdata.seek(0)
+ assert_raises(ValueError, np.ndfromtxt, mdata,
+ delimiter=",", names=True, invalid_raise=True)
+
+ def test_invalid_raise_with_usecols(self):
+ "Test invalid_raise with usecols"
+ data = ["1, 1, 1, 1, 1"] * 50
+ for i in range(5):
+ data[10 * i] = "2, 2, 2, 2 2"
+ data.insert(0, "a, b, c, d, e")
+ mdata = StringIO.StringIO("\n".join(data))
+ #
+ mtest = np.ndfromtxt(mdata, delimiter=",", names=True, dtype=None,
+ usecols=(0, 4))
+ assert_equal(len(mtest), 45)
+ assert_equal(mtest, np.ones(45, dtype=[(_, int) for _ in 'ae']))
+ #
+ mdata.seek(0)
+ mtest = np.ndfromtxt(mdata, delimiter=",", names=True, dtype=None,
+ usecols=(0, 1))
+ assert_equal(len(mtest), 50)
+ control = np.ones(50, dtype=[(_, int) for _ in 'ab'])
+ control[[10 * _ for _ in range(5)]] = (2, 2)
+ assert_equal(mtest, control)
+
+
def test_recfromtxt(self):
#
data = StringIO.StringIO('A,B\n0,1\n2,3')