@@ -129,24 +129,22 @@ 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+ res = obj .astype (dtype ) if dtype is not None else obj
134+ if copy is False and res is not obj :
135+ raise ValueError ("Unable to avoid copy" )
136+ return obj .copy () if copy else obj
137+
132138 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 )
139+ raise NotImplementedError (
140+ "copy=False is not possible when converting a non-dask object to dask"
141+ )
142+
143+ # copy=None to be uniform across dask < 2024.12 and >= 2024.12
144+ # see https://github.com/dask/dask/pull/11524/
145+ obj = np .asarray (obj , dtype = dtype , copy = True )
146+ return da .from_array (obj )
147+
150148
151149from dask .array import (
152150 # Element wise aliases
0 commit comments