@@ -129,24 +129,21 @@ 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 :
134+ obj = obj .astype (dtype )
135+ return obj .copy () if copy else obj
136+
132137 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+
150147
151148from dask .array import (
152149 # Element wise aliases
0 commit comments