diff options
author | Aaron Meurer <asmeurer@gmail.com> | 2021-03-02 16:57:03 -0700 |
---|---|---|
committer | Aaron Meurer <asmeurer@gmail.com> | 2021-03-02 16:57:03 -0700 |
commit | 58c2a996afd13f729ec5d2aed77151c8e799548b (patch) | |
tree | bb9d6c997e6b8c9badf061a63f0d2da02bf4ba4b /numpy | |
parent | 7132764661b01e2f15a66d7c39d74ad4b2d434a9 (diff) | |
download | numpy-58c2a996afd13f729ec5d2aed77151c8e799548b.tar.gz |
Make sure the array API ndarray object cannot wrap an array scalar
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/_array_api/_array_object.py | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/numpy/_array_api/_array_object.py b/numpy/_array_api/_array_object.py index 32a7bc9a8..b78405860 100644 --- a/numpy/_array_api/_array_object.py +++ b/numpy/_array_api/_array_object.py @@ -19,6 +19,8 @@ from enum import IntEnum from ._types import Optional, PyCapsule, Tuple, Union, array from ._creation_functions import asarray +import numpy as np + class ndarray: # Use a custom constructor instead of __init__, as manually initializing # this class is not supported API. @@ -34,6 +36,10 @@ class ndarray: """ obj = super().__new__(cls) + # Note: The spec does not have array scalars, only shape () arrays. + if isinstance(x, np.generic): + # x[...] converts an array scalar to a shape () array. + x = x[...] obj._array = x return obj |