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

numpy-svn@scip... numpy-svn@scip...
Mon Mar 2 14:05:48 CST 2009


Author: stefan
Date: 2009-03-02 14:05:32 -0600 (Mon, 02 Mar 2009)
New Revision: 6534

Modified:
   trunk/numpy/lib/io.py
   trunk/numpy/lib/tests/test_io.py
Log:
Correctly handle gzip filenames in loadtxt.

Modified: trunk/numpy/lib/io.py
===================================================================
--- trunk/numpy/lib/io.py	2009-03-02 19:28:17 UTC (rev 6533)
+++ trunk/numpy/lib/io.py	2009-03-02 20:05:32 UTC (rev 6534)
@@ -48,6 +48,9 @@
     def tell(self):
         return self.offset
 
+    if isinstance(f, str):
+        f = gzip.GzipFile(f)
+
     f.seek = new.instancemethod(seek, f)
     f.tell = new.instancemethod(tell, f)
 

Modified: trunk/numpy/lib/tests/test_io.py
===================================================================
--- trunk/numpy/lib/tests/test_io.py	2009-03-02 19:28:17 UTC (rev 6533)
+++ trunk/numpy/lib/tests/test_io.py	2009-03-02 20:05:32 UTC (rev 6534)
@@ -3,6 +3,7 @@
 from numpy.ma.testutils import *
 
 import StringIO
+import gzip
 
 from tempfile import NamedTemporaryFile
 import sys, time
@@ -821,6 +822,13 @@
     f = gzip.GzipFile(fileobj=s, mode="r")
     assert_array_equal(np.load(f), a)
 
+def test_gzip_loadtxt():
+    f = NamedTemporaryFile(suffix='.gz')
+    g = gzip.GzipFile(fileobj=f)
+    g.write('1 2 3\n')
+    g.close()
+    f.seek(0)
+    assert_array_equal(np.loadtxt(f.name), [1, 2, 3])
 
 if __name__ == "__main__":
     run_module_suite()



More information about the Numpy-svn mailing list