@@ -129,24 +129,21 @@ def asarray(
129
129
See the corresponding documentation in the array library and/or the array API
130
130
specification for more details.
131
131
"""
132
+ if isinstance (obj , da .Array ):
133
+ if dtype is not None :
134
+ obj = obj .astype (dtype )
135
+ return obj .copy () if copy else obj
136
+
132
137
if copy is False :
133
- # copy=False is not yet implemented in dask
134
- raise NotImplementedError ("copy=False is not yet implemented" )
135
- elif copy is True :
136
- if isinstance (obj , da .Array ) and dtype is None :
137
- return obj .copy ()
138
- # Go through numpy, since dask copy is no-op by default
139
- obj = np .array (obj , dtype = dtype , copy = True )
140
- return da .array (obj , dtype = dtype )
141
- else :
142
- if not isinstance (obj , da .Array ) or dtype is not None and obj .dtype != dtype :
143
- # copy=True to be uniform across dask < 2024.12 and >= 2024.12
144
- # see https://github.com/dask/dask/pull/11524/
145
- obj = np .array (obj , dtype = dtype , copy = True )
146
- return da .from_array (obj )
147
- return obj
148
-
149
- return da .asarray (obj , dtype = dtype , ** kwargs )
138
+ raise NotImplementedError (
139
+ "copy=False is not possible when converting a non-dask object to dask"
140
+ )
141
+
142
+ # copy=None to be uniform across dask < 2024.12 and >= 2024.12
143
+ # see https://github.com/dask/dask/pull/11524/
144
+ obj = np .asarray (obj , dtype = dtype , copy = True )
145
+ return da .from_array (obj )
146
+
150
147
151
148
from dask .array import (
152
149
# Element wise aliases
0 commit comments