TST: revisit test for asarray copy= parameter#325
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR updates the asarray(..., copy=…) behavior and its tests to always raise ValueError on unsupported no-copy conversions and simplifies test assertions.
- Switch Dask’s non-copy conversion error from
NotImplementedErrortoValueError. - Align and simplify tests across all libraries to expect
ValueErrorwhencopy=Falseis unsupported. - Replace
all(...)assertions with direct element checks.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tests/test_common.py | Removed conditional branches, unified exception expectations to ValueError, and simplified assertions. |
| array_api_compat/dask/array/_aliases.py | Changed the exception raised for copy=False on non‐Dask objects from NotImplementedError to ValueError. |
Comments suppressed due to low confidence (1)
tests/test_common.py:355
- [nitpick] This comment is just above the array.array test—consider moving or duplicating it to the
if library == 'dask.array'block to make the test intent clearer.
# dask changed behaviour of copy=None in 2024.12 to copy;
| if copy is False: | ||
| raise NotImplementedError( | ||
| raise ValueError( | ||
| "Unable to avoid copy when converting a non-dask object to dask" |
There was a problem hiding this comment.
[nitpick] Consider unifying the exception message style with the dtype‐change branch (e.g. both starting 'Unable to avoid copy when ...') for consistency.
| "Unable to avoid copy when converting a non-dask object to dask" | |
| "Unable to avoid copy when converting a non-dask object to dask array" |
ev-br
left a comment
There was a problem hiding this comment.
Thanks Guido. Let's give it a shot, and test it locally together with other fixes.
| a = array.array("f", [1.0]) | ||
| if library in ("cupy", "dask.array"): | ||
| with pytest.raises(ValueError): | ||
| asarray(a, copy=False) |
There was a problem hiding this comment.
Can't say I'm happy about the need for branching here. It is what it is though
There was a problem hiding this comment.
You're not happy that cupy can't create a GPU array as a view of host memory? 😕
ValueErrorinstead ofNotImplementedErrorwhen it failsasarray(..., copy=False).asarrayandto_device#314