diff options
author | pierregm <pierregm@localhost> | 2009-01-22 05:37:36 +0000 |
---|---|---|
committer | pierregm <pierregm@localhost> | 2009-01-22 05:37:36 +0000 |
commit | 7adaad411b9896f7dd8100cb75e80a313c082d2c (patch) | |
tree | f00a2ac09ba5a43e572419416683cac8332069db /numpy/lib/tests/test_io.py | |
parent | 8bd6c70d47e16fd81c8e3aefd4b2ec6dd90f38d6 (diff) | |
download | numpy-7adaad411b9896f7dd8100cb75e80a313c082d2c.tar.gz |
* genfromtxt : if names is True, accept a line starting with a comment character as header.
Diffstat (limited to 'numpy/lib/tests/test_io.py')
-rw-r--r-- | numpy/lib/tests/test_io.py | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py index 58eb7f129..f0f2a0619 100644 --- a/numpy/lib/tests/test_io.py +++ b/numpy/lib/tests/test_io.py @@ -483,6 +483,30 @@ class TestFromTxt(TestCase): assert_equal(test, control) + def test_commented_header(self): + "Check that names can be retrieved even if the line is commented out." + data = StringIO.StringIO(""" +#gender age weight +M 21 72.100000 +F 35 58.330000 +M 33 21.99 + """) + # The # is part of the first name and should be deleted automatically. + test = np.genfromtxt(data, names=True, dtype=None) + ctrl = np.array([('M', 21, 72.1), ('F', 35, 58.33), ('M', 33, 21.99)], + dtype=[('gender','|S1'), ('age', int), ('weight', float)]) + assert_equal(test, ctrl) + # Ditto, but we should get rid of the first element + data = StringIO.StringIO(""" +# gender age weight +M 21 72.100000 +F 35 58.330000 +M 33 21.99 + """) + test = np.genfromtxt(data, names=True, dtype=None) + assert_equal(test, ctrl) + + def test_autonames_and_usecols(self): "Tests names and usecols" data = StringIO.StringIO('A B C D\n aaaa 121 45 9.1') @@ -707,7 +731,7 @@ class TestFromTxt(TestCase): dtype=[('a', np.int), ('b', np.int)]) self.failUnless(isinstance(test, np.recarray)) assert_equal(test, control) - + |