Skip to content

Commit

Permalink
Remove limited implementation of __setitem__ from Array
Browse files Browse the repository at this point in the history
  • Loading branch information
tomwhite committed Sep 5, 2023
1 parent a753b92 commit d23b5b3
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 37 deletions.
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

0 comments on commit d23b5b3

Please sign in to comment.