summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
Diffstat (limited to 'numpy')
-rw-r--r--numpy/lib/_iotools.py9
-rw-r--r--numpy/lib/tests/test_io.py11
2 files changed, 18 insertions, 2 deletions
diff --git a/numpy/lib/_iotools.py b/numpy/lib/_iotools.py
index 595c01d29..644d83d1c 100644
--- a/numpy/lib/_iotools.py
+++ b/numpy/lib/_iotools.py
@@ -468,6 +468,11 @@ class StringConverter:
for val in missing_values:
self.missing_values.add(val)
else:
- self.missing_values = [] # Update the type
- self.type = self._getsubdtype(func('0'))
+ self.missing_values = []
+ # Update the type
+ try:
+ tester = func('0')
+ except ValueError:
+ tester = None
+ self.type = self._getsubdtype(tester)
diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py
index 2995d6709..da91d8a8d 100644
--- a/numpy/lib/tests/test_io.py
+++ b/numpy/lib/tests/test_io.py
@@ -535,6 +535,17 @@ M 33 21.99
dtype=[('A', '|S4'), ('C', int), ('D', float)])
assert_equal(test, control)
+ def test_converters_cornercases(self):
+ "Test the conversion to datetime."
+ from datetime import datetime
+ converter = {'date':lambda s: datetime.strptime(s,'%Y-%m-%d %H:%M:%SZ')}
+ data = StringIO.StringIO('2009-02-03 12:00:00Z, 72214.0')
+ test = np.ndfromtxt(data, delimiter=',', dtype=None,
+ names=['date','stid'], converters=converter)
+ control = np.array((datetime(2009,02,03,12,0), 72214.),
+ dtype=[('date', np.object_), ('stid', float)])
+ assert_equal(test, control)
+
def test_unused_converter(self):
"Test whether unused converters are forgotten"