[Numpy-svn] r6345 - trunk/numpy/lib

numpy-svn at scipy.org numpy-svn at scipy.org
Fri Feb 6 01:26:06 EST 2009


Author: oliphant
Date: 2009-02-06 00:25:50 -0600 (Fri, 06 Feb 2009)
New Revision: 6345

Modified:
   trunk/numpy/lib/io.py
Log:
Avoid re-creating the sequence when there is only one field in the regular expression.

Modified: trunk/numpy/lib/io.py
===================================================================
--- trunk/numpy/lib/io.py	2009-02-06 00:51:41 UTC (rev 6344)
+++ trunk/numpy/lib/io.py	2009-02-06 06:25:50 UTC (rev 6345)
@@ -604,10 +604,15 @@
 
     seq = regexp.findall(file.read())
     if seq and not isinstance(seq[0], tuple):
-        # make sure np.array doesn't interpret strings as binary data
-        # by always producing a list of tuples
-        seq = [(x,) for x in seq]
-    output = np.array(seq, dtype=dtype)
+        # Only one group is in the regexp.
+        # Create the new array as a single data-type and then
+        #   re-interpret as a single-field structured array. 
+        newdtype = np.dtype(dtype[dtype.names[0]])
+        output = np.array(seq, dtype=newdtype)
+        output.dtype = dtype
+    else:
+        output = np.array(seq, dtype=dtype)
+
     return output
 
 




More information about the Numpy-svn mailing list