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

numpy-svn at scipy.org numpy-svn at scipy.org
Sun May 2 16:02:14 EDT 2010


Author: stefan
Date: 2010-05-02 15:02:14 -0500 (Sun, 02 May 2010)
New Revision: 8375

Modified:
   trunk/numpy/lib/npyio.py
   trunk/numpy/lib/tests/test_io.py
Log:
BUG: loadtxt should handle universal newlines.

Modified: trunk/numpy/lib/npyio.py
===================================================================
--- trunk/numpy/lib/npyio.py	2010-04-30 07:06:02 UTC (rev 8374)
+++ trunk/numpy/lib/npyio.py	2010-05-02 20:02:14 UTC (rev 8375)
@@ -584,7 +584,7 @@
             import bz2
             fh = bz2.BZ2File(fname)
         else:
-            fh = file(fname)
+            fh = file(fname, 'U')
     elif hasattr(fname, 'readline'):
         fh = fname
     else:

Modified: trunk/numpy/lib/tests/test_io.py
===================================================================
--- trunk/numpy/lib/tests/test_io.py	2010-04-30 07:06:02 UTC (rev 8374)
+++ trunk/numpy/lib/tests/test_io.py	2010-05-02 20:02:14 UTC (rev 8375)
@@ -403,8 +403,18 @@
                            dtype=ndtype)
         assert_equal(test, control)
 
+    def test_universal_newline(self):
+        f, name = mkstemp()
+        os.write(f, asbytes('1 21\r3 42\r'))
+        os.close(f)
 
+        try:
+            data = np.loadtxt(name)
+            assert_array_equal(data, [[1, 21], [3, 42]])
+        finally:
+            os.unlink(name)
 
+
 class Testfromregex(TestCase):
     def test_record(self):
         c = StringIO()




More information about the Numpy-svn mailing list