Skip to content

Commit fc5aef3

Browse files
author
Martin Durant
committed
start
1 parent 610db34 commit fc5aef3

File tree

2 files changed

+37
-19
lines changed

2 files changed

+37
-19
lines changed

zarr/core.py

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1535,25 +1535,31 @@ def _set_selection(self, indexer, value, fields=None):
15351535
check_array_shape('value', value, sel_shape)
15361536

15371537
# iterate over chunks in range
1538-
for chunk_coords, chunk_selection, out_selection in indexer:
1538+
if not hasattr(self.store, "setitems") or self._synchronizer is not None:
1539+
# iterative approach
1540+
for chunk_coords, chunk_selection, out_selection in indexer:
15391541

1540-
# extract data to store
1541-
if sel_shape == ():
1542-
chunk_value = value
1543-
elif is_scalar(value, self._dtype):
1544-
chunk_value = value
1545-
else:
1546-
chunk_value = value[out_selection]
1547-
# handle missing singleton dimensions
1548-
if indexer.drop_axes:
1549-
item = [slice(None)] * self.ndim
1550-
for a in indexer.drop_axes:
1551-
item[a] = np.newaxis
1552-
item = tuple(item)
1553-
chunk_value = chunk_value[item]
1554-
1555-
# put data
1556-
self._chunk_setitem(chunk_coords, chunk_selection, chunk_value, fields=fields)
1542+
# extract data to store
1543+
if sel_shape == ():
1544+
chunk_value = value
1545+
elif is_scalar(value, self._dtype):
1546+
chunk_value = value
1547+
else:
1548+
chunk_value = value[out_selection]
1549+
# handle missing singleton dimensions
1550+
if indexer.drop_axes:
1551+
item = [slice(None)] * self.ndim
1552+
for a in indexer.drop_axes:
1553+
item[a] = np.newaxis
1554+
item = tuple(item)
1555+
chunk_value = chunk_value[item]
1556+
1557+
# put data
1558+
self._chunk_setitem(chunk_coords, chunk_selection, chunk_value, fields=fields)
1559+
else:
1560+
lchunk_coords, lchunk_selection, lout_selection = zip(*indexer)
1561+
self._chunk_setitems(lchunk_coords, lchunk_selection, out, lout_selection,
1562+
fields=fields)
15571563

15581564
def _process_chunk(self, out, cdata, chunk_selection, drop_axes,
15591565
out_is_ndarray, fields, out_selection):

zarr/storage.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1054,14 +1054,20 @@ def __setitem__(self, key, value):
10541054
raise ReadOnlyError()
10551055
key = self._normalize_key(key)
10561056
path = self.dir_path(key)
1057-
value = ensure_contiguous_ndarray(value)
10581057
try:
10591058
if self.fs.isdir(path):
10601059
self.fs.rm(path, recursive=True)
10611060
self.map[key] = value
1061+
self.fs.invalidate_cache(self.fs._parent(path))
10621062
except self.exceptions as e:
10631063
raise KeyError(key) from e
10641064

1065+
def setitems(self, values):
1066+
if self.mode == 'r':
1067+
raise ReadOnlyError()
1068+
values2 = {self._normalize_key(k): v for k, v in values.items()}
1069+
self.map.setitems(values2)
1070+
10651071
def __delitem__(self, key):
10661072
if self.mode == 'r':
10671073
raise ReadOnlyError()
@@ -1072,6 +1078,12 @@ def __delitem__(self, key):
10721078
else:
10731079
del self.map[key]
10741080

1081+
def delitems(self, keys):
1082+
if self.mode == 'r':
1083+
raise ReadOnlyError()
1084+
keys = [self._normalize_key(k) for k in keys]
1085+
self.map.delitems(keys)
1086+
10751087
def __contains__(self, key):
10761088
key = self._normalize_key(key)
10771089
return key in self.map

0 commit comments

Comments
 (0)