summaryrefslogtreecommitdiff
path: root/numpy/typing
diff options
context:
space:
mode:
authorSebastian Berg <sebastianb@nvidia.com>2022-09-20 12:29:38 +0200
committerSebastian Berg <sebastianb@nvidia.com>2022-09-21 15:04:57 +0200
commit519ce63b8ef9e3af0688936b3b822a8cbcc123f7 (patch)
treedb0957d81a9d5e0358b20572ad03b3b272fca424 /numpy/typing
parent2524a53ba30c1207770a27a513eb18a33837a145 (diff)
downloadnumpy-519ce63b8ef9e3af0688936b3b822a8cbcc123f7.tar.gz
ENH: Allow creating structured void scalars by passing dtype
Adds an optional `dtype=` kwarg to `np.void`. If given (and not None), this kwarg effectively turns it into: res = np.array(data, dtype=dtype)[()] Thanks for Marten's review and Bas' help with the typing. Reviewed-by: Marten van Kerkwijk <mhvk@astro.utoronto.ca> Co-authored-by: Bas van Beek <43369155+BvB93@users.noreply.github.com>
Diffstat (limited to 'numpy/typing')
-rw-r--r--numpy/typing/tests/data/fail/scalars.pyi5
-rw-r--r--numpy/typing/tests/data/pass/scalars.py2
2 files changed, 5 insertions, 2 deletions
diff --git a/numpy/typing/tests/data/fail/scalars.pyi b/numpy/typing/tests/data/fail/scalars.pyi
index 964470538..74a86bbb3 100644
--- a/numpy/typing/tests/data/fail/scalars.pyi
+++ b/numpy/typing/tests/data/fail/scalars.pyi
@@ -47,7 +47,8 @@ np.uint16(A()) # E: incompatible type
np.uint32(A()) # E: incompatible type
np.uint64(A()) # E: incompatible type
-np.void("test") # E: incompatible type
+np.void("test") # E: No overload variant
+np.void("test", dtype=None) # E: No overload variant
np.generic(1) # E: Cannot instantiate abstract class
np.number(1) # E: Cannot instantiate abstract class
@@ -62,7 +63,7 @@ np.uint64(value=0) # E: Unexpected keyword argument
np.complex128(value=0.0j) # E: Unexpected keyword argument
np.str_(value='bob') # E: No overload variant
np.bytes_(value=b'test') # E: No overload variant
-np.void(value=b'test') # E: Unexpected keyword argument
+np.void(value=b'test') # E: No overload variant
np.bool_(value=True) # E: Unexpected keyword argument
np.datetime64(value="2019") # E: No overload variant
np.timedelta64(value=0) # E: Unexpected keyword argument
diff --git a/numpy/typing/tests/data/pass/scalars.py b/numpy/typing/tests/data/pass/scalars.py
index 684d41fad..aef9c3584 100644
--- a/numpy/typing/tests/data/pass/scalars.py
+++ b/numpy/typing/tests/data/pass/scalars.py
@@ -113,6 +113,8 @@ np.void(True)
np.void(np.bool_(True))
np.void(b"test")
np.void(np.bytes_("test"))
+np.void(object(), [("a", "O"), ("b", "O")])
+np.void(object(), dtype=[("a", "O"), ("b", "O")])
# Protocols
i8 = np.int64()