diff options
author | pierregm <pierregm@localhost> | 2009-02-03 17:11:44 +0000 |
---|---|---|
committer | pierregm <pierregm@localhost> | 2009-02-03 17:11:44 +0000 |
commit | 8ab9363953bd9e77bf1bf84c931b426422b90558 (patch) | |
tree | cbd42f59969b389d0b254e7f9d0e95e553a3641f | |
parent | f278427bb52fdfdc524d1da4032777ca5290e49e (diff) | |
download | numpy-8ab9363953bd9e77bf1bf84c931b426422b90558.tar.gz |
* Make sure that StringConverter.update sets the type to object if it can't define it.
-rw-r--r-- | numpy/lib/_iotools.py | 9 | ||||
-rw-r--r-- | numpy/lib/tests/test_io.py | 11 |
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" |