[Numpy-svn] r6338 - in trunk/numpy/lib: . tests

numpy-svn@scip... numpy-svn@scip...
Tue Feb 3 11:11:48 CST 2009


Author: pierregm
Date: 2009-02-03 11:11:44 -0600 (Tue, 03 Feb 2009)
New Revision: 6338

Modified:
   trunk/numpy/lib/_iotools.py
   trunk/numpy/lib/tests/test_io.py
Log:
* Make sure that StringConverter.update sets the type to object if it can't define it.

Modified: trunk/numpy/lib/_iotools.py
===================================================================
--- trunk/numpy/lib/_iotools.py	2009-02-02 05:20:17 UTC (rev 6337)
+++ trunk/numpy/lib/_iotools.py	2009-02-03 17:11:44 UTC (rev 6338)
@@ -468,6 +468,11 @@
                 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)
 

Modified: trunk/numpy/lib/tests/test_io.py
===================================================================
--- trunk/numpy/lib/tests/test_io.py	2009-02-02 05:20:17 UTC (rev 6337)
+++ trunk/numpy/lib/tests/test_io.py	2009-02-03 17:11:44 UTC (rev 6338)
@@ -535,7 +535,18 @@
             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"
         data = StringIO.StringIO("1 21\n  3 42\n")



More information about the Numpy-svn mailing list