diff options
author | Derek Homeir <derek@astro.phsik.uni-goettingen.de> | 2011-04-04 08:13:54 -0600 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2011-04-04 08:13:54 -0600 |
commit | ce0019c3c0ce3f5afe6eaf6326cd13093d0644e2 (patch) | |
tree | d84cda3125b3719ec8b73e95bc012199402cf3cd /numpy/lib/tests/test_io.py | |
parent | a528b98550f9e411342659069c5ac8fb7bca7bf3 (diff) | |
download | numpy-ce0019c3c0ce3f5afe6eaf6326cd13093d0644e2.tar.gz |
BUG: ticket #1071, fix loadtxt to handle tab delimited data with missing
values in the last column and add test for same.
Diffstat (limited to 'numpy/lib/tests/test_io.py')
-rw-r--r-- | numpy/lib/tests/test_io.py | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py index 53068838a..4894f8939 100644 --- a/numpy/lib/tests/test_io.py +++ b/numpy/lib/tests/test_io.py @@ -417,10 +417,8 @@ class TestLoadTxt(TestCase): "Test using an explicit dtype with an object" from datetime import date import time - data = """ - 1; 2001-01-01 - 2; 2002-01-31 - """ + data = asbytes(""" 1; 2001-01-01 + 2; 2002-01-31 """) ndtype = [('idx', int), ('code', np.object)] func = lambda s: strptime(s.strip(), "%Y-%m-%d") converters = {1: func} @@ -457,6 +455,16 @@ class TestLoadTxt(TestCase): finally: os.unlink(name) + def test_empty_field_after_tab(self): + c = StringIO() + c.write(asbytes('1 \t2 \t3\tstart \n4\t5\t6\t \n7\t8\t9.5\t')) + c.seek(0) + dt = { 'names': ('x', 'y', 'z', 'comment'), + 'formats': ('<i4', '<i4', '<f4', '|S8')} + x = np.loadtxt(c, dtype=dt, delimiter='\t') + a = np.array([asbytes('start '), asbytes(' '), asbytes('')]) + assert_array_equal(x['comment'], a) + def test_structure_unpack(self): txt = StringIO(asbytes("M 21 72\nF 35 58")) dt = { 'names': ('a', 'b', 'c'), 'formats': ('|S1', '<i4', '<f4')} @@ -802,10 +810,8 @@ M 33 21.99 "Test using an explicit dtype with an object" from datetime import date import time - data = asbytes(""" - 1; 2001-01-01 - 2; 2002-01-31 - """) + data = asbytes(""" 1; 2001-01-01 + 2; 2002-01-31 """) ndtype = [('idx', int), ('code', np.object)] func = lambda s: strptime(s.strip(), "%Y-%m-%d") converters = {1: func} |