summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
Diffstat (limited to 'numpy')
-rw-r--r--numpy/lib/recfunctions.py2
-rw-r--r--numpy/lib/tests/test_recfunctions.py9
2 files changed, 11 insertions, 0 deletions
diff --git a/numpy/lib/recfunctions.py b/numpy/lib/recfunctions.py
index 74a8f8969..6afcf1b7f 100644
--- a/numpy/lib/recfunctions.py
+++ b/numpy/lib/recfunctions.py
@@ -1057,6 +1057,8 @@ def unstructured_to_structured(arr, dtype=None, names=None, align=False,
else:
if names is not None:
raise ValueError("don't supply both dtype and names")
+ # if dtype is the args of np.dtype, construct it
+ dtype = np.dtype(dtype)
# sanity check of the input dtype
fields = _get_fields_and_offsets(dtype)
if len(fields) == 0:
diff --git a/numpy/lib/tests/test_recfunctions.py b/numpy/lib/tests/test_recfunctions.py
index 9b2506a7c..d8385f8be 100644
--- a/numpy/lib/tests/test_recfunctions.py
+++ b/numpy/lib/tests/test_recfunctions.py
@@ -318,6 +318,15 @@ class TestRecFunctions:
assert_raises(NotImplementedError, unstructured_to_structured,
np.zeros((3,0), dtype=np.int32))
+ def test_unstructured_to_structured(self):
+ # test if dtype is the args of np.dtype
+ a = np.zeros((20, 2))
+ test_dtype_args = [('x', float), ('y', float)]
+ test_dtype = np.dtype(test_dtype_args)
+ field1 = unstructured_to_structured(a, dtype=test_dtype_args) # now
+ field2 = unstructured_to_structured(a, dtype=test_dtype) # before
+ assert_equal(field1, field2)
+
def test_field_assignment_by_name(self):
a = np.ones(2, dtype=[('a', 'i4'), ('b', 'f8'), ('c', 'u1')])
newdt = [('b', 'f4'), ('c', 'u1')]