summaryrefslogtreecommitdiff
path: root/numpy/lib/recfunctions.py
diff options
context:
space:
mode:
authorLeonaTaric <92495067+LeonaTaric@users.noreply.github.com>2022-10-19 23:07:39 +0800
committerGitHub <noreply@github.com>2022-10-19 17:07:39 +0200
commita8449b52163f871b75a4873a9543db6612d38ccf (patch)
treebd83ae6595800d1c726a3e3a9d17e64fab7bbe30 /numpy/lib/recfunctions.py
parent527c6e13ae65de08c6d998342b6a836a663c66b4 (diff)
downloadnumpy-a8449b52163f871b75a4873a9543db6612d38ccf.tar.gz
ENH: unstructured_to_structured converts dtype argument (#22442)
Before: >>> field = unstructured_to_structured(np.zeros((20, 2)), dtype=[('x', float), ('y', float)]) # failed >>> field = unstructured_to_structured(np.zeros((20, 2)), dtype=np.dtype([('x', float), ('y', float)])) # success After: >>> field = unstructured_to_structured(np.zeros((20, 2)), dtype=[('x', float), ('y', float)]) # success >>> field = unstructured_to_structured(np.zeros((20, 2)), dtype=np.dtype([('x', float), ('y', float)])) # success Closes gh-22428
Diffstat (limited to 'numpy/lib/recfunctions.py')
-rw-r--r--numpy/lib/recfunctions.py2
1 files changed, 2 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: