diff options
author | pierregm <pierregm@localhost> | 2010-05-16 23:05:30 +0000 |
---|---|---|
committer | pierregm <pierregm@localhost> | 2010-05-16 23:05:30 +0000 |
commit | 97a38c4a4233fb133b2f2fa8b4fad9e65657f572 (patch) | |
tree | 70a91968a539cfbae47c8d6553fa75886c69ccf9 /numpy/lib/tests/test_io.py | |
parent | ccf308399107ec304b7e0d36692f9d929b6d3416 (diff) | |
download | numpy-97a38c4a4233fb133b2f2fa8b4fad9e65657f572.tar.gz |
* add a `replace_space` option to NameValidator
* Force a file to be opened in 'U' mode (bug #1473)
Diffstat (limited to 'numpy/lib/tests/test_io.py')
-rw-r--r-- | numpy/lib/tests/test_io.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py index 73d3c3599..d7becc284 100644 --- a/numpy/lib/tests/test_io.py +++ b/numpy/lib/tests/test_io.py @@ -1062,6 +1062,30 @@ M 33 21.99 dtype=[('f0', '|S10'), ('f1', float), ('f2', '|S5')]) assert_equal(mtest, ctrl) + def test_replace_space(self): + "Test the 'replace_space' option" + txt = "A.A, B (B), C:C\n1, 2, 3.14" + # Test default: replace ' ' by '_' and delete non-alphanum chars + test = np.genfromtxt(StringIO(txt), + delimiter=",", names=True, dtype=None) + ctrl_dtype = [("AA", int), ("B_B", int), ("CC", float)] + ctrl = np.array((1, 2, 3.14), dtype=ctrl_dtype) + assert_equal(test, ctrl) + # Test: no replace, no delete + test = np.genfromtxt(StringIO(txt), + delimiter=",", names=True, dtype=None, + replace_space='', deletechars='') + ctrl_dtype = [("A.A", int), ("B (B)", int), ("C:C", float)] + ctrl = np.array((1, 2, 3.14), dtype=ctrl_dtype) + assert_equal(test, ctrl) + # Test: no delete (spaces are replaced by _) + test = np.genfromtxt(StringIO(txt), + delimiter=",", names=True, dtype=None, + deletechars='') + ctrl_dtype = [("A.A", int), ("B_(B)", int), ("C:C", float)] + ctrl = np.array((1, 2, 3.14), dtype=ctrl_dtype) + assert_equal(test, ctrl) + def test_incomplete_names(self): "Test w/ incomplete names" data = "A,,C\n0,1,2\n3,4,5" |