summaryrefslogtreecommitdiff
path: root/numpy/lib/tests/test_io.py
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/lib/tests/test_io.py')
-rw-r--r--numpy/lib/tests/test_io.py29
1 files changed, 29 insertions, 0 deletions
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")