Skip to content

Commit

Permalink
Merge pull request #211 from ev-br/asarray_copy_dask
Browse files Browse the repository at this point in the history
BUG: dask.array: asarray(..., copy=None) copies in dask==2024.12
  • Loading branch information
ev-br authored Dec 12, 2024
2 parents ee25aae + ce4e55d commit 940a198
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
4 changes: 3 additions & 1 deletion array_api_compat/dask/array/_aliases.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@ def asarray(
return da.array(obj, dtype=dtype)
else:
if not isinstance(obj, da.Array) or dtype is not None and obj.dtype != dtype:
obj = np.asarray(obj, dtype=dtype)
# copy=True to be uniform across dask < 2024.12 and >= 2024.12
# see https://github.com/dask/dask/pull/11524/
obj = np.array(obj, dtype=dtype, copy=True)
return da.from_array(obj)
return obj

Expand Down
3 changes: 3 additions & 0 deletions dask-skips.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# slow and not implemented in dask
array_api_tests/test_linalg.py::test_matrix_power

# hangs on 2024.12
array_api_tests/test_creation_functions.py::test_eye
5 changes: 4 additions & 1 deletion tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,11 @@ def test_asarray_copy(library):
b = asarray(a, copy=None)
assert is_lib_func(b)
a[0] = 0.0
if library == 'cupy':
if library in ('cupy', 'dask.array'):
# A copy is required for libraries where the default device is not CPU
# dask changed behaviour of copy=None in 2024.12 to copy;
# this wrapper ensures the same behaviour in older versions too.
# https://github.com/dask/dask/pull/11524/
assert all(b[0] == 1.0)
else:
assert all(b[0] == 0.0)

0 comments on commit 940a198

Please sign in to comment.