summaryrefslogtreecommitdiff
path: root/numpy/lib/tests/test_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/tests/test_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/tests/test_recfunctions.py')
-rw-r--r--numpy/lib/tests/test_recfunctions.py9
1 files changed, 9 insertions, 0 deletions
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')]