Skip to content

Commit

Permalink
Merge branch 'main' into custom-metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
pattonw authored Dec 31, 2024
2 parents 6677dda + 0b67093 commit ec1b1a9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
7 changes: 7 additions & 0 deletions funlib/persistence/arrays/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,13 @@ def __setitem__(self, key, value: np.ndarray):

self._source_data[region_slices] = value

# If the source data is an in-memory numpy array, writing to the numpy
# array does not always result in the dask array reading the new data.
# It seems to be a caching issue. To work around this, we create a new
# dask array from the source data.
if isinstance(self._source_data, np.ndarray):
self.data = da.from_array(self._source_data)

else:
raise RuntimeError(
"This array is not writeable since you have applied a custom callable "
Expand Down
17 changes: 9 additions & 8 deletions tests/test_array.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import dask.array as da
import numpy as np
import pytest
import dask.array as da

from funlib.geometry import Coordinate, Roi
from funlib.persistence.arrays import Array
Expand Down Expand Up @@ -73,13 +73,14 @@ def test_setitem():

a = Array(np.zeros((2, 5)), (0, 0), (1, 1))

a[Roi((0, 0), (2, 5))] = np.arange(0, 10).reshape(2, 5)
assert a[Coordinate((0, 0))] == 0
assert a[Coordinate((0, 1))] == 1
assert a[Coordinate((0, 2))] == 2
assert a[Coordinate((1, 0))] == 5
assert a[Coordinate((1, 1))] == 6
assert a[Coordinate((1, 4))] == 9
data = np.arange(0, 10).reshape(2, 5)
a[Roi((0, 0), (2, 5))] = data
assert a[Coordinate((0, 0))] == a._source_data[0, 0] == 0
assert a[Coordinate((0, 1))] == a._source_data[0, 1] == 1
assert a[Coordinate((0, 2))] == a._source_data[0, 2] == 2
assert a[Coordinate((1, 0))] == a._source_data[1, 0] == 5
assert a[Coordinate((1, 1))] == a._source_data[1, 1] == 6
assert a[Coordinate((1, 4))] == a._source_data[1, 4] == 9

# set entirely with numpy array and channels

Expand Down

0 comments on commit ec1b1a9

Please sign in to comment.