summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErik M. Bray <embray@stsci.edu>2014-10-31 11:05:13 -0400
committerErik M. Bray <embray@stsci.edu>2014-10-31 11:05:13 -0400
commitb89849b1213e3384dfd72838672f5869321768db (patch)
tree111a19e5e72f11b89d56e816f8cbf6f39fba98ec
parentc63e1f470cf84a928499b2570a091f801cb67ba2 (diff)
downloadnumpy-b89849b1213e3384dfd72838672f5869321768db.tar.gz
Fix issue with fromarrays not correctly determining a format string for unicode data (in the process eliminate some unnecessary cruft)
-rw-r--r--numpy/core/records.py10
-rw-r--r--numpy/core/tests/test_records.py9
2 files changed, 12 insertions, 7 deletions
diff --git a/numpy/core/records.py b/numpy/core/records.py
index 677257629..bf4d835ea 100644
--- a/numpy/core/records.py
+++ b/numpy/core/records.py
@@ -71,7 +71,6 @@ _byteorderconv = {'b':'>',
# are equally allowed
numfmt = nt.typeDict
-_typestr = nt._typestr
def find_duplicate(list):
"""Find duplication in a list, return a list of duplicated elements"""
@@ -527,15 +526,12 @@ def fromarrays(arrayList, dtype=None, shape=None, formats=None,
if formats is None and dtype is None:
# go through each object in the list to see if it is an ndarray
# and determine the formats.
- formats = ''
+ formats = []
for obj in arrayList:
if not isinstance(obj, ndarray):
raise ValueError("item in the array list must be an ndarray.")
- formats += _typestr[obj.dtype.type]
- if issubclass(obj.dtype.type, nt.flexible):
- formats += repr(obj.itemsize)
- formats += ','
- formats = formats[:-1]
+ formats.append(obj.dtype.str)
+ formats = ','.join(formats)
if dtype is not None:
descr = sb.dtype(dtype)
diff --git a/numpy/core/tests/test_records.py b/numpy/core/tests/test_records.py
index 8c9ce5c70..355e5480a 100644
--- a/numpy/core/tests/test_records.py
+++ b/numpy/core/tests/test_records.py
@@ -1,5 +1,6 @@
from __future__ import division, absolute_import, print_function
+import sys
from os import path
import numpy as np
from numpy.testing import *
@@ -15,6 +16,14 @@ class TestFromrecords(TestCase):
r = np.rec.fromrecords([[456, 'dbe', 1.2], [2, 'de', 1.3]],
names='col1,col2,col3')
assert_equal(r[0].item(), (456, 'dbe', 1.2))
+ assert_equal(r['col1'].dtype.kind, 'i')
+ if sys.version_info[0] >= 3:
+ assert_equal(r['col2'].dtype.kind, 'U')
+ assert_equal(r['col2'].dtype.itemsize, 12)
+ else:
+ assert_equal(r['col2'].dtype.kind, 'S')
+ assert_equal(r['col2'].dtype.itemsize, 3)
+ assert_equal(r['col3'].dtype.kind, 'f')
def test_method_array(self):
r = np.rec.array(asbytes('abcdefg') * 100, formats='i2,a3,i4', shape=3, byteorder='big')