@@ -129,24 +129,23 @@ def asarray(
129129 See the corresponding documentation in the array library and/or the array API
130130 specification for more details.
131131 """
132+ if isinstance (obj , da .Array ):
133+ if dtype is not None and dtype != obj .dtype :
134+ if copy is False :
135+ raise ValueError ("Unable to avoid copy" )
136+ obj = obj .astype (dtype )
137+ return obj .copy () if copy else obj
138+
132139 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 )
140+ raise NotImplementedError (
141+ "copy=False is not possible when converting a non-dask object to dask"
142+ )
143+
144+ # copy=None to be uniform across dask < 2024.12 and >= 2024.12
145+ # see https://github.com/dask/dask/pull/11524/
146+ obj = np .asarray (obj , dtype = dtype , copy = True )
147+ return da .from_array (obj )
148+
150149
151150from dask .array import (
152151 # Element wise aliases
0 commit comments