Skip to content
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

Remove limited implementation of __setitem__ from Array #302

Merged
merged 1 commit into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions cubed/core/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import numpy as np
from toolz import map, reduce

from cubed.runtime.pipeline import already_computed
from cubed.runtime.types import Executor
from cubed.storage.zarr import open_if_lazy_zarr_array
from cubed.utils import chunk_memory, convert_to_bytes
Expand Down Expand Up @@ -191,20 +190,6 @@ def __getitem__(self: T_ChunkedArray, key, /) -> T_ChunkedArray:

return index(self, key)

def __setitem__(self, key, value):
if isinstance(value, CoreArray) and value.ndim != 0:
raise NotImplementedError(
"Calling __setitem__ on an array with more than 0 dimensions is not supported."
)

nodes = {n: d for (n, d) in self.plan.dag.nodes(data=True)}
if not already_computed(nodes[self.name]):
raise NotImplementedError(
"Calling __setitem__ on an array that has not been computed is not supported."
)

self.zarray.__setitem__(key, value)

def __repr__(self):
return f"cubed.core.CoreArray<{self.name}, shape={self.shape}, dtype={self.dtype}, chunks={self.chunks}>"

Expand Down
22 changes: 0 additions & 22 deletions cubed/tests/test_array_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,28 +277,6 @@ def test_index_slice_unsupported_step(spec):
a[::-1]


@pytest.mark.xfail(reason="not currently compatible with lazy zarr arrays")
def test_setitem(spec):
a = xp.asarray([[1, 2, 3], [4, 5, 6], [7, 8, 9]], chunks=(2, 2), spec=spec)
b = xp.ones(())
a[1, 2] = b
assert_array_equal(a.compute(), np.array([[1, 2, 3], [4, 5, 1], [7, 8, 9]]))


def test_setitem_fails_not_0d(spec):
a = xp.asarray([[1, 2, 3], [4, 5, 6], [7, 8, 9]], chunks=(2, 2), spec=spec)
b = xp.asarray([[4, 5, 6], [7, 8, 9], [1, 2, 3]], chunks=(2, 2), spec=spec)
with pytest.raises(NotImplementedError):
a[:] = b


def test_setitem_fails_not_computed(spec):
a = xp.arange(12, chunks=(4,), spec=spec)
b = xp.ones(())
with pytest.raises(NotImplementedError):
a[1] = b


@pytest.mark.parametrize("axis", [0, 1])
def test_take(spec, axis):
a = xp.asarray(
Expand Down