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

numpy-svn at scipy.org numpy-svn at scipy.org
Thu Apr 3 10:17:13 EDT 2008


Author: dhuard
Date: 2008-04-03 09:17:08 -0500 (Thu, 03 Apr 2008)
New Revision: 4957

Modified:
   trunk/numpy/lib/io.py
   trunk/numpy/lib/tests/test_io.py
Log:
added 1D tests for loadtxt and savetxt. Fixed a bug

Modified: trunk/numpy/lib/io.py
===================================================================
--- trunk/numpy/lib/io.py	2008-04-03 14:06:33 UTC (rev 4956)
+++ trunk/numpy/lib/io.py	2008-04-03 14:17:08 UTC (rev 4957)
@@ -353,7 +353,7 @@
 
     X = np.asarray(X)
     origShape = None
-    if len(X.shape)==1 and not hasattr(X.dtype, 'names'):
+    if len(X.shape)==1 and X.dtype.names is None:
         origShape = X.shape
         X.shape = len(X), 1
     for row in X:

Modified: trunk/numpy/lib/tests/test_io.py
===================================================================
--- trunk/numpy/lib/tests/test_io.py	2008-04-03 14:06:33 UTC (rev 4956)
+++ trunk/numpy/lib/tests/test_io.py	2008-04-03 14:17:08 UTC (rev 4957)
@@ -16,6 +16,13 @@
         c.seek(0)
         assert(c.readlines(), ['1 2\n', '3 4\n'])
         
+    def test_1D(self):
+        a = np.array([1,2,3,4], int)
+        c = StringIO.StringIO()
+        np.savetxt(c, a, fmt='%d')
+        c.seek(0)
+        assert(c.readlines(), ['1\n', '2\n', '3\n', '4\n'])
+    
     def test_record(self):
         a = np.array([(1, 2), (3, 4)], dtype=[('x', '<i4'), ('y', '<i4')])
         c = StringIO.StringIO()
@@ -48,5 +55,13 @@
         a = np.array([[1,2],[3,4]], float)
         assert_array_equal(x, a)
         
+    def test_1D(self):
+        c = StringIO.StringIO()
+        c.write('1\n2\n3\n4\n')
+        c.seek(0)
+        x = np.loadtxt(c, dtype=int)
+        a = np.array([1,2,3,4], int)
+        assert_array_equal(x, a)
+    
 if __name__ == "__main__":
     NumpyTest().run()




More information about the Numpy-svn mailing list