From ce75d262b5b67c03d972e14d7c7f1d24ffea5e68 Mon Sep 17 00:00:00 2001 From: dhuard Date: Fri, 5 Sep 2008 13:58:00 +0000 Subject: Applied patch from R. May fixing ticket #905 (loadtxt). Fixed other bug occurring when both usecols and converters are provided. Added related regression tests. --- numpy/lib/tests/test_io.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (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 1d2c2321a..4e6412e09 100644 --- a/numpy/lib/tests/test_io.py +++ b/numpy/lib/tests/test_io.py @@ -170,7 +170,6 @@ class TestLoadTxt(TestCase): a = np.array([1,2,3,4], int) assert_array_equal(x, a) - def test_missing(self): c = StringIO.StringIO() c.write('1,2,3,,5\n') @@ -180,6 +179,16 @@ class TestLoadTxt(TestCase): a = np.array([1,2,3,-999,5], int) assert_array_equal(x, a) + def test_converters_with_usecols(self): + c = StringIO.StringIO() + c.write('1,2,3,,5\n6,7,8,9,10\n') + c.seek(0) + x = np.loadtxt(c, dtype=int, delimiter=',', \ + converters={3:lambda s: int(s or -999)}, \ + usecols=(1, 3, )) + a = np.array([[2, -999],[7, 9]], int) + assert_array_equal(x, a) + def test_comments(self): c = StringIO.StringIO() c.write('# comment\n1,2,3,5\n') @@ -221,6 +230,11 @@ class TestLoadTxt(TestCase): x = np.loadtxt(c, dtype=float, usecols=(1,2)) assert_array_equal(x, a[:,1:]) + # Testing with arrays instead of tuples. + c.seek(0) + x = np.loadtxt(c, dtype=float, usecols=np.array([1,2])) + assert_array_equal(x, a[:,1:]) + # Checking with dtypes defined converters. data = '''JOE 70.1 25.3 BOB 60.5 27.9 -- cgit v1.2.1