Skip to content

Commit adbb6ef

Browse files
authored
Merge pull request #234 from lithomas1/dask-astype-copy
BUG: astype(..., copy=True) doesn't copy on dask
2 parents 5ef0e18 + 691c27b commit adbb6ef

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

array_api_compat/dask/array/_aliases.py

+16-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,22 @@
3939

4040
isdtype = get_xp(np)(_aliases.isdtype)
4141
unstack = get_xp(da)(_aliases.unstack)
42-
astype = _aliases.astype
42+
43+
def astype(
44+
x: Array,
45+
dtype: Dtype,
46+
/,
47+
*,
48+
copy: bool = True,
49+
device: Device | None = None
50+
) -> Array:
51+
# TODO: respect device keyword?
52+
if not copy and dtype == x.dtype:
53+
return x
54+
# dask astype doesn't respect copy=True,
55+
# so call copy manually afterwards
56+
x = x.astype(dtype)
57+
return x.copy() if copy else x
4358

4459
# Common aliases
4560

0 commit comments

Comments
 (0)