[Numpy-svn] r6345 - trunk/numpy/lib
Fri Feb 6 00:26:06 CST 2009
Date: 2009-02-06 00:25:50 -0600 (Fri, 06 Feb 2009)
New Revision: 6345
Avoid re-creating the sequence when there is only one field in the regular expression.
--- 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, 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])
+ output = np.array(seq, dtype=newdtype)
+ output.dtype = dtype
+ output = np.array(seq, dtype=dtype)
More information about the Numpy-svn