summaryrefslogtreecommitdiff
path: root/numpy/_array_api/_creation_functions.py
diff options
context:
space:
mode:
authorAaron Meurer <asmeurer@gmail.com>2021-02-23 18:54:02 -0700
committerAaron Meurer <asmeurer@gmail.com>2021-02-23 18:54:02 -0700
commita42f71ac8ac559d0ef770bdfd2f62bd1be4848d5 (patch)
treea9a9d47b4cbb64fbe2976ea6b6dacbbb3ffbb231 /numpy/_array_api/_creation_functions.py
parent853a18de30219a0d25709caac0410de6dfeb4e95 (diff)
downloadnumpy-a42f71ac8ac559d0ef770bdfd2f62bd1be4848d5.tar.gz
Only allow supported dtypes in the array_api namespace asarray()
Diffstat (limited to 'numpy/_array_api/_creation_functions.py')
-rw-r--r--numpy/_array_api/_creation_functions.py7
1 files changed, 6 insertions, 1 deletions
diff --git a/numpy/_array_api/_creation_functions.py b/numpy/_array_api/_creation_functions.py
index bd607234d..06d9e6dad 100644
--- a/numpy/_array_api/_creation_functions.py
+++ b/numpy/_array_api/_creation_functions.py
@@ -11,13 +11,18 @@ def asarray(obj: Union[float, NestedSequence[bool|int|float], SupportsDLPack, Su
See its docstring for more information.
"""
+ from ._array_object import ndarray
+ from . import _dtypes
if device is not None:
# Note: Device support is not yet implemented on ndarray
raise NotImplementedError("Device support is not yet implemented")
if copy is not None:
# Note: copy is not yet implemented in np.asarray
raise NotImplementedError("The copy keyword argument to asarray is not yet implemented")
- return np.asarray(obj, dtype=dtype)
+ res = np.asarray(obj, dtype=dtype)
+ if res.dtype not in _dtypes._all_dtypes:
+ raise TypeError(f"The array_api namespace does not support the dtype {res.dtype}")
+ return ndarray._new(res)
def arange(start: Union[int, float], /, *, stop: Optional[Union[int, float]] = None, step: Union[int, float] = 1, dtype: Optional[dtype] = None, device: Optional[device] = None) -> array:
"""