diff options
author | pierregm <pierregm@localhost> | 2009-10-06 03:47:07 +0000 |
---|---|---|
committer | pierregm <pierregm@localhost> | 2009-10-06 03:47:07 +0000 |
commit | 6386708bcd6deaf3f6e5f145fb59c0d4b9af86d9 (patch) | |
tree | c5ef08d00870e076b37298cf37c9bb4ca868d5fb /numpy/lib/tests | |
parent | 9a41e774079340e1a8887d9f2310c2458580ec6c (diff) | |
download | numpy-6386708bcd6deaf3f6e5f145fb59c0d4b9af86d9.tar.gz |
* _iotools.StringConverter
- use '1' instead of '0' to test the update
- add `iterupgrade` to upgrade from an iterator
* io.genfromtxt (bug #1212)
- use `iterupgrade` to upgrade the converters, and reprocess if there's a problem to catch the offending line
Diffstat (limited to 'numpy/lib/tests')
-rw-r--r-- | numpy/lib/tests/test_io.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py index ecf87980b..bc05ed4d3 100644 --- a/numpy/lib/tests/test_io.py +++ b/numpy/lib/tests/test_io.py @@ -11,6 +11,8 @@ from tempfile import mkstemp, NamedTemporaryFile import sys, time from datetime import datetime +from numpy.lib._iotools import ConverterError, ConverterLockError + MAJVER, MINVER = sys.version_info[:2] @@ -624,6 +626,19 @@ M 33 21.99 assert_equal(test, [33, 66]) + def test_invalid_converter(self): + strip_rand = lambda x : float(('r' in x.lower() and x.split()[-1]) or + (not 'r' in x.lower() and x.strip() or 0.0)) + strip_per = lambda x : float(('%' in x.lower() and x.split()[0]) or + (not '%' in x.lower() and x.strip() or 0.0)) + s = StringIO.StringIO("D01N01,10/1/2003 ,1 %,R 75,400,600\r\n" \ + "L24U05,12/5/2003, 2 %,1,300, 150.5\r\n" + "D02N03,10/10/2004,R 1,,7,145.55") + kwargs = dict(converters={2 : strip_per, 3 : strip_rand}, delimiter=",", + dtype=None) + assert_raises(ConverterError, np.genfromtxt, s, **kwargs) + + def test_dtype_with_converters(self): dstr = "2009; 23; 46" test = np.ndfromtxt(StringIO.StringIO(dstr,), @@ -863,6 +878,16 @@ M 33 21.99 assert_equal(mtest, control) + def test_inconsistent_dtype(self): + data = ["1, 1, 1, 1, -1.1"] * 50 + mdata = StringIO.StringIO("\n".join(data)) + + converters = {4: lambda x:np.sqrt(float(x))} + kwargs = dict(delimiter=",", converters=converters, + dtype=[(_, int) for _ in 'abcde'],) + assert_raises(TypeError, np.genfromtxt, mdata, **kwargs) + + def test_recfromtxt(self): # data = StringIO.StringIO('A,B\n0,1\n2,3') |