From f24c10206e41b73d3ac63e763b3f4e6399c62e4f Mon Sep 17 00:00:00 2001 From: Evgeni Burovski Date: Thu, 5 Dec 2024 12:11:56 +0000 Subject: [PATCH 1/4] BUG: dask.array: asarray(..., copy=None) copies in dask==2024.12 --- tests/test_common.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/test_common.py b/tests/test_common.py index e1cfa9eb..a89ed0e9 100644 --- a/tests/test_common.py +++ b/tests/test_common.py @@ -204,8 +204,10 @@ 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 made a breaking change in 2024.12: copy=None copies + # https://github.com/dask/dask/pull/11524/ assert all(b[0] == 1.0) else: assert all(b[0] == 0.0) From de97b445f179688a9b33615dd256c62fc6699ce6 Mon Sep 17 00:00:00 2001 From: Evgeni Burovski Date: Thu, 5 Dec 2024 19:26:11 +0000 Subject: [PATCH 2/4] BUG: dask: fix asarray(..., copy=None) for array-likes: they copy As of dask >= 2024.12, da.from_array() always copies, while before it did not. Thus copy too, to make array_api_compat.dask.array version-independent. --- array_api_compat/dask/array/_aliases.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/array_api_compat/dask/array/_aliases.py b/array_api_compat/dask/array/_aliases.py index ee2d88c0..df8fede8 100644 --- a/array_api_compat/dask/array/_aliases.py +++ b/array_api_compat/dask/array/_aliases.py @@ -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 From bce5dcc315d6faa5b182e767802fa3fc4ce69701 Mon Sep 17 00:00:00 2001 From: Evgeni Burovski Date: Thu, 5 Dec 2024 21:32:43 +0200 Subject: [PATCH 3/4] TST: dask: skip test_eye instead of xfailing it It seems to hang on CI with dask==2024.12 --- dask-skips.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/dask-skips.txt b/dask-skips.txt index 63a09e4b..f4c0c282 100644 --- a/dask-skips.txt +++ b/dask-skips.txt @@ -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 From ce4e55d1e965030d972b5066e7cba8b6ac167a74 Mon Sep 17 00:00:00 2001 From: Evgeni Burovski Date: Fri, 6 Dec 2024 09:17:56 +0200 Subject: [PATCH 4/4] Update tests/test_common.py Co-authored-by: crusaderky --- tests/test_common.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_common.py b/tests/test_common.py index a89ed0e9..6bf55618 100644 --- a/tests/test_common.py +++ b/tests/test_common.py @@ -206,7 +206,8 @@ def test_asarray_copy(library): a[0] = 0.0 if library in ('cupy', 'dask.array'): # A copy is required for libraries where the default device is not CPU - # dask made a breaking change in 2024.12: copy=None copies + # 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: