Skip to content

Commit ec1b1a9

Browse files
authored
Merge branch 'main' into custom-metadata
2 parents 6677dda + 0b67093 commit ec1b1a9

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

funlib/persistence/arrays/array.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,13 @@ def __setitem__(self, key, value: np.ndarray):
328328

329329
self._source_data[region_slices] = value
330330

331+
# If the source data is an in-memory numpy array, writing to the numpy
332+
# array does not always result in the dask array reading the new data.
333+
# It seems to be a caching issue. To work around this, we create a new
334+
# dask array from the source data.
335+
if isinstance(self._source_data, np.ndarray):
336+
self.data = da.from_array(self._source_data)
337+
331338
else:
332339
raise RuntimeError(
333340
"This array is not writeable since you have applied a custom callable "

tests/test_array.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import dask.array as da
12
import numpy as np
23
import pytest
3-
import dask.array as da
44

55
from funlib.geometry import Coordinate, Roi
66
from funlib.persistence.arrays import Array
@@ -73,13 +73,14 @@ def test_setitem():
7373

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

76-
a[Roi((0, 0), (2, 5))] = np.arange(0, 10).reshape(2, 5)
77-
assert a[Coordinate((0, 0))] == 0
78-
assert a[Coordinate((0, 1))] == 1
79-
assert a[Coordinate((0, 2))] == 2
80-
assert a[Coordinate((1, 0))] == 5
81-
assert a[Coordinate((1, 1))] == 6
82-
assert a[Coordinate((1, 4))] == 9
76+
data = np.arange(0, 10).reshape(2, 5)
77+
a[Roi((0, 0), (2, 5))] = data
78+
assert a[Coordinate((0, 0))] == a._source_data[0, 0] == 0
79+
assert a[Coordinate((0, 1))] == a._source_data[0, 1] == 1
80+
assert a[Coordinate((0, 2))] == a._source_data[0, 2] == 2
81+
assert a[Coordinate((1, 0))] == a._source_data[1, 0] == 5
82+
assert a[Coordinate((1, 1))] == a._source_data[1, 1] == 6
83+
assert a[Coordinate((1, 4))] == a._source_data[1, 4] == 9
8384

8485
# set entirely with numpy array and channels
8586

0 commit comments

Comments
 (0)