diff options
author | Aaron Meurer <asmeurer@gmail.com> | 2021-03-31 17:38:46 -0600 |
---|---|---|
committer | Aaron Meurer <asmeurer@gmail.com> | 2021-03-31 17:38:46 -0600 |
commit | fb5c69775f516f06fcf6e79e0762f09e6e8cb907 (patch) | |
tree | 860cdfc4e290e62259c04fc2e050d621067a8eb4 /numpy/_array_api | |
parent | 9fe4fc7ff7f477fc4aaad850f8d1841beb2924bc (diff) | |
download | numpy-fb5c69775f516f06fcf6e79e0762f09e6e8cb907.tar.gz |
Give a better error message in the array API asarray for out of bounds integers
Without this the error message would be a confusing message about object
arrays not being supported.
Diffstat (limited to 'numpy/_array_api')
-rw-r--r-- | numpy/_array_api/_creation_functions.py | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/numpy/_array_api/_creation_functions.py b/numpy/_array_api/_creation_functions.py index e9ef983fd..107f3c313 100644 --- a/numpy/_array_api/_creation_functions.py +++ b/numpy/_array_api/_creation_functions.py @@ -26,6 +26,10 @@ def asarray(obj: Union[float, NestedSequence[bool|int|float], SupportsDLPack, Su raise NotImplementedError("The copy keyword argument to asarray is not yet implemented") if isinstance(obj, ndarray) and (dtype is None or obj.dtype == dtype): return obj + if isinstance(obj, int) and (obj > 2**64 or obj < -2**63): + # Give a better error message in this case. NumPy would convert this + # to an object array. + raise OverflowError("Integer out of bounds for array dtypes") res = np.asarray(obj, dtype=dtype) if res.dtype not in _all_dtypes: raise TypeError(f"The array_api namespace does not support the dtype '{res.dtype}'") |