summaryrefslogtreecommitdiff
path: root/numpy/lib/tests/test_io.py
diff options
context:
space:
mode:
authordhuard <dhuard@localhost>2008-09-05 13:58:00 +0000
committerdhuard <dhuard@localhost>2008-09-05 13:58:00 +0000
commitce75d262b5b67c03d972e14d7c7f1d24ffea5e68 (patch)
tree6d162df1abf0eedeb6e002cc4aac391ce7e5bd41 /numpy/lib/tests/test_io.py
parentbcaa1793226b8dab929d8ccc786c23854f5886e0 (diff)
downloadnumpy-ce75d262b5b67c03d972e14d7c7f1d24ffea5e68.tar.gz
Applied patch from R. May fixing ticket #905 (loadtxt). Fixed other bug occurring when both usecols and converters are provided. Added related regression tests.
Diffstat (limited to 'numpy/lib/tests/test_io.py')
-rw-r--r--numpy/lib/tests/test_io.py16
1 files changed, 15 insertions, 1 deletions
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