Skip to content

Commit 391b08b

Browse files
committed
Fix asarray(copy=True)
Fixes #5.
1 parent fd798e1 commit 391b08b

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

numpy_array_api_compat/_aliases.py

+7
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,13 @@ def asarray(
164164
if copy in (False, np._CopyMode.IF_NEEDED):
165165
# copy=False is not yet implemented in np.asarray
166166
raise NotImplementedError("copy=False is not yet implemented")
167+
if isinstance(obj, np.ndarray):
168+
if dtype is not None and obj.dtype != dtype:
169+
copy = True
170+
if copy in (True, np._CopyMode.ALWAYS):
171+
return np.array(obj, copy=True, dtype=dtype)
172+
return obj
173+
167174
return np.asarray(obj, dtype=dtype)
168175

169176
def arange(

0 commit comments

Comments
 (0)