Skip to content

Commit d577d46

Browse files
committed
Fix bug in numpy.array_api.asarray with copy=True
Original NumPy Commit: 4f2b67adcdb626cc9a2e5ffb548db26c37bdc811
1 parent 673cd73 commit d577d46

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

array_api_strict/_creation_functions.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ def asarray(
4848
from ._array_object import Array, CPU_DEVICE
4949

5050
_check_valid_dtype(dtype)
51+
_np_dtype = None
52+
if dtype is not None:
53+
_np_dtype = dtype._np_dtype
5154
if device not in [CPU_DEVICE, None]:
5255
raise ValueError(f"Unsupported device {device!r}")
5356
if copy in (False, np._CopyMode.IF_NEEDED):
@@ -57,15 +60,13 @@ def asarray(
5760
if dtype is not None and obj.dtype != dtype:
5861
copy = True
5962
if copy in (True, np._CopyMode.ALWAYS):
60-
return Array._new(np.array(obj._array, copy=True, dtype=dtype))
63+
return Array._new(np.array(obj._array, copy=True, dtype=_np_dtype))
6164
return obj
6265
if dtype is None and isinstance(obj, int) and (obj > 2 ** 64 or obj < -(2 ** 63)):
6366
# Give a better error message in this case. NumPy would convert this
6467
# to an object array. TODO: This won't handle large integers in lists.
6568
raise OverflowError("Integer out of bounds for array dtypes")
66-
if dtype is not None:
67-
dtype = dtype._np_dtype
68-
res = np.asarray(obj, dtype=dtype)
69+
res = np.asarray(obj, dtype=_np_dtype)
6970
return Array._new(res)
7071

7172

0 commit comments

Comments
 (0)