summaryrefslogtreecommitdiff
path: root/numpy/lib/io.py
diff options
context:
space:
mode:
authorTravis Oliphant <oliphant@enthought.com>2009-02-06 06:25:50 +0000
committerTravis Oliphant <oliphant@enthought.com>2009-02-06 06:25:50 +0000
commit0b0c3a1b68c76b14c5b8d7291df730f8fe618843 (patch)
tree41e9973e99747cf61abc3718b90c6efa80c0b5fb /numpy/lib/io.py
parent71320b2952f2bb3c221d24fbb5560cc439269ff6 (diff)
downloadnumpy-0b0c3a1b68c76b14c5b8d7291df730f8fe618843.tar.gz
Avoid re-creating the sequence when there is only one field in the regular expression.
Diffstat (limited to 'numpy/lib/io.py')
-rw-r--r--numpy/lib/io.py13
1 files changed, 9 insertions, 4 deletions
diff --git a/numpy/lib/io.py b/numpy/lib/io.py
index be1e03d4c..4ff2a3945 100644
--- a/numpy/lib/io.py
+++ b/numpy/lib/io.py
@@ -604,10 +604,15 @@ def fromregex(file, regexp, dtype):
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