diff options
author | pierregm <pierregm@localhost> | 2009-02-05 04:31:51 +0000 |
---|---|---|
committer | pierregm <pierregm@localhost> | 2009-02-05 04:31:51 +0000 |
commit | 911e94dd0a64adae9fb2057fb0210e512a9b7d4a (patch) | |
tree | c41d7f3027db2d581547f09168f2363cac618be9 /numpy/lib/tests | |
parent | 12750f7b0f6a5aa2cb318848de8e09076eb30fa2 (diff) | |
download | numpy-911e94dd0a64adae9fb2057fb0210e512a9b7d4a.tar.gz |
* genfromtxt : Fixed when a dtype involving objects is explicitly given. Raise a NotImplementedError if the dtype is nested.
* _iotools : make sure StringConverter gets properly initiated when a function returning a np.object is used as input parameter.
Diffstat (limited to 'numpy/lib/tests')
-rw-r--r-- | numpy/lib/tests/test__iotools.py | 17 | ||||
-rw-r--r-- | numpy/lib/tests/test_io.py | 29 |
2 files changed, 45 insertions, 1 deletions
diff --git a/numpy/lib/tests/test__iotools.py b/numpy/lib/tests/test__iotools.py index 61b069659..bb1483186 100644 --- a/numpy/lib/tests/test__iotools.py +++ b/numpy/lib/tests/test__iotools.py @@ -2,7 +2,8 @@ import StringIO import numpy as np -from numpy.lib._iotools import LineSplitter, NameValidator, StringConverter +from numpy.lib._iotools import LineSplitter, NameValidator, StringConverter,\ + has_nested_fields from numpy.testing import * class TestLineSplitter(TestCase): @@ -142,3 +143,17 @@ class TestStringConverter(TestCase): test = convert('') assert_equal(test, date(2000, 01, 01)) + +#------------------------------------------------------------------------------- + +class TestMiscFunctions(TestCase): + # + def test_has_nested_dtype(self): + "Test has_nested_dtype" + ndtype = np.dtype(np.float) + assert_equal(has_nested_fields(ndtype), False) + ndtype = np.dtype([('A', '|S3'), ('B', float)]) + assert_equal(has_nested_fields(ndtype), False) + ndtype = np.dtype([('A', int), ('B', [('BA', float), ('BB', '|S1')])]) + assert_equal(has_nested_fields(ndtype), True) + diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py index da91d8a8d..8c1bfbfb5 100644 --- a/numpy/lib/tests/test_io.py +++ b/numpy/lib/tests/test_io.py @@ -573,6 +573,35 @@ M 33 21.99 assert_equal(test, control) + def test_dtype_with_object(self): + "Test using an explicit dtype qith 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: date(*(time.strptime(s.strip(), "%Y-%m-%d")[:3])) + converters = {1: func} + test = np.genfromtxt(StringIO.StringIO(data), delimiter=";", dtype=ndtype, + converters=converters) + control = np.array([(1, date(2001,1,1)), (2, date(2002,1,31))], + dtype=ndtype) + assert_equal(test, control) + # + ndtype = [('nest', [('idx', int), ('code', np.object)])] + try: + test = np.genfromtxt(StringIO.StringIO(data), delimiter=";", + dtype=ndtype, converters=converters) + except NotImplementedError: + pass + else: + errmsg = "Nested dtype involving objects should be supported." + raise AssertionError(errmsg) + + + def test_spacedelimiter(self): "Test space delimiter" data = StringIO.StringIO("1 2 3 4 5\n6 7 8 9 10") |