-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BUG: astype(..., copy=True) doesn't copy on dask #234
Conversation
oops, snuck some misc changes in. Going to revert, sorry! |
1cb10db
to
fef8607
Compare
cc @crusaderky @ev-br for review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See also: #235
@@ -39,7 +39,14 @@ | |||
|
|||
isdtype = get_xp(np)(_aliases.isdtype) | |||
unstack = get_xp(da)(_aliases.unstack) | |||
astype = _aliases.astype | |||
|
|||
def astype(x: Array, dtype: Dtype, /, *, copy: bool = True) -> Array: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks,
I just raised Notimplemented for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please ignore it. astype(x, dtype, device=device(x)
must work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated, PTAL.
tests/test_common.py
Outdated
|
||
@pytest.mark.parametrize("library", wrapped_libraries) | ||
def test_astype_copy(library): | ||
# array-api-tests currently doesn't check copy=True | ||
# makes a copy when dtypes are the same | ||
# so we check that here | ||
xp = import_(library, wrapper=True) | ||
a = xp.asarray([1]) | ||
b = xp.astype(a, a.dtype, copy=True) | ||
|
||
a[0] = 10 | ||
|
||
assert b[0] == 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move this test to array-api-tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WIP PR here:
data-apis/array-api-tests#335
Co-Authored-By: Guido Imperiale <6213168+crusaderky@users.noreply.github.com>
@ev-br this looks ready to be merged to me |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The sequence of x.astype, then x.copy looks like making two copies to a non-expert; that said I'm ready to believe it's a right dask-specific pattern, and the PR is okay'd by the subject matter expert. Let's roll with this then. Thank you @lithomas1 , @crusaderky
It does make two copies of the dask collection - which is a thin python object. The dask graph wrapped internally is the same. |
dask.array.astype doesn't respect copy=True, so we should copy manually.