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

numpy-svn@scip... numpy-svn@scip...
Fri Apr 4 15:13:27 CDT 2008


Author: dhuard
Date: 2008-04-04 15:13:24 -0500 (Fri, 04 Apr 2008)
New Revision: 4962

Modified:
   trunk/numpy/lib/io.py
   trunk/numpy/lib/tests/test_io.py
Log:
Modified io._getconv to allow loading values stored as float as integers arrays. Added test to check the behavior as suggested in the comment from b. southey in 
ticket #623

Modified: trunk/numpy/lib/io.py
===================================================================
--- trunk/numpy/lib/io.py	2008-04-04 06:37:45 UTC (rev 4961)
+++ trunk/numpy/lib/io.py	2008-04-04 20:13:24 UTC (rev 4962)
@@ -203,7 +203,7 @@
     if issubclass(typ, np.bool_):
         return lambda x: bool(int(x))
     if issubclass(typ, np.integer):
-        return int
+        return lambda x: int(float(x))
     elif issubclass(typ, np.floating):
         return float
     elif issubclass(typ, np.complex):

Modified: trunk/numpy/lib/tests/test_io.py
===================================================================
--- trunk/numpy/lib/tests/test_io.py	2008-04-04 06:37:45 UTC (rev 4961)
+++ trunk/numpy/lib/tests/test_io.py	2008-04-04 20:13:24 UTC (rev 4962)
@@ -41,6 +41,16 @@
         a = np.array([(1, 2), (3, 4)], dtype=[('x', '<i4'), ('y', '<i4')])
         assert_array_equal(x, a)
         
+        d = StringIO.StringIO()
+        d.write('M 64.0 75.0\nF 25.0 60.0')
+        d.seek(0)
+
+        mydescriptor = {'names': ('gender','age','weight'), 'formats': ('S1',
+                                'i4', 'f4')}
+        b = np.array([('M',    64.0, 75.0),('F', 25.0, 60.0)], dtype=mydescriptor)
+        y = np.loadtxt(d, dtype=mydescriptor)
+        assert_array_equal(y, b)
+        
     def test_array(self):
         c = StringIO.StringIO()
         c.write('1 2\n3 4')



More information about the Numpy-svn mailing list