diff options
author | pierregm <pierregm@localhost> | 2009-05-28 22:12:18 +0000 |
---|---|---|
committer | pierregm <pierregm@localhost> | 2009-05-28 22:12:18 +0000 |
commit | 68bedef931f7a689ac5558e3a3e01f58c2e0e850 (patch) | |
tree | 6dc9f071028af9897f5293ef7b2d1cb7f314056a /numpy/lib/tests/test_io.py | |
parent | a2bf56aaf98ea150079ee5d05da21b18de68252a (diff) | |
download | numpy-68bedef931f7a689ac5558e3a3e01f58c2e0e850.tar.gz |
lib._iotools :
* add the flatten_base keyword to flatten_dtype
lib.io.genfromtxt
* Use flatten_dtype(...,flatten_base=True) to deal with fields w/ shape
lib.io.loadtxt
* fixed for the case when one of the fields is object
Diffstat (limited to 'numpy/lib/tests/test_io.py')
-rw-r--r-- | numpy/lib/tests/test_io.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py index d9bf03e01..e5a73a86a 100644 --- a/numpy/lib/tests/test_io.py +++ b/numpy/lib/tests/test_io.py @@ -370,6 +370,25 @@ class TestLoadTxt(TestCase): converters={1: lambda s: int(s, 16)}) assert_array_equal(data, [33, 66]) + def test_dtype_with_object(self): + "Test using an explicit dtype with an object" + from datetime import date + import time + data = """ + 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} + test = np.loadtxt(StringIO.StringIO(data), delimiter=";", dtype=ndtype, + converters=converters) + control = np.array([(1, datetime(2001,1,1)), (2, datetime(2002,1,31))], + dtype=ndtype) + assert_equal(test, control) + + + class Testfromregex(TestCase): def test_record(self): c = StringIO.StringIO() @@ -717,6 +736,16 @@ M 33 21.99 assert_equal(test, control) + def test_shaped_dtype(self): + c = StringIO.StringIO("aaaa 1.0 8.0 1 2 3 4 5 6") + dt = np.dtype([('name', 'S4'), ('x', float), ('y', float), + ('block', int, (2, 3))]) + x = np.ndfromtxt(c, dtype=dt) + a = np.array([('aaaa', 1.0, 8.0, [[1, 2, 3], [4, 5, 6]])], + dtype=dt) + assert_array_equal(x, a) + + def test_withmissing(self): data = StringIO.StringIO('A,B\n0,1\n2,N/A') test = np.mafromtxt(data, dtype=None, delimiter=',', missing='N/A', |