Skip to content

Commit 27117b7

Browse files
author
Martin Durant
committed
Implement hook to getitems, if it exists
1 parent cc1c5aa commit 27117b7

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

zarr/core.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,11 +1021,16 @@ def _get_selection(self, indexer, out=None, fields=None):
10211021
check_array_shape('out', out, out_shape)
10221022

10231023
# iterate over chunks
1024-
for chunk_coords, chunk_selection, out_selection in indexer:
1024+
if not hasattr(self.store, "getitems"):
1025+
for chunk_coords, chunk_selection, out_selection in indexer:
10251026

1026-
# load chunk selection into output array
1027-
self._chunk_getitem(chunk_coords, chunk_selection, out, out_selection,
1028-
drop_axes=indexer.drop_axes, fields=fields)
1027+
# load chunk selection into output array
1028+
self._chunk_getitem(chunk_coords, chunk_selection, out, out_selection,
1029+
drop_axes=indexer.drop_axes, fields=fields)
1030+
else:
1031+
lchunk_coords, lchunk_selection, lout_selection = zip(*indexer)
1032+
self._chunk_getitems(lchunk_coords, lchunk_selection, out, lout_selection,
1033+
drop_axes=indexer.drop_axes, fields=fields)
10291034

10301035
if out.shape:
10311036
return out
@@ -1550,7 +1555,7 @@ def _set_selection(self, indexer, value, fields=None):
15501555
self._chunk_setitem(chunk_coords, chunk_selection, chunk_value, fields=fields)
15511556

15521557
def _process_chunk(self, out, cdata, chunk_selection, drop_axes,
1553-
out_is_ndarray):
1558+
out_is_ndarray, fields, out_selection):
15541559
if (out_is_ndarray and
15551560
not fields and
15561561
is_contiguous_selection(out_selection) and
@@ -1614,6 +1619,11 @@ def _chunk_getitem(self, chunk_coords, chunk_selection, out, out_selection,
16141619
TODO
16151620
16161621
"""
1622+
out_is_ndarray = True
1623+
try:
1624+
out = ensure_ndarray(out)
1625+
except TypeError:
1626+
out_is_ndarray = False
16171627

16181628
assert len(chunk_coords) == len(self._cdata_shape)
16191629

@@ -1635,7 +1645,7 @@ def _chunk_getitem(self, chunk_coords, chunk_selection, out, out_selection,
16351645

16361646
else:
16371647
self._process_chunk(out, cdata, chunk_selection, drop_axes,
1638-
out_is_ndarray)
1648+
out_is_ndarray, fields, out_selection)
16391649

16401650
def _chunk_getitems(self, lchunk_coords, lchunk_selection, out, lout_selection,
16411651
drop_axes=None, fields=None):
@@ -1650,7 +1660,7 @@ def _chunk_getitems(self, lchunk_coords, lchunk_selection, out, lout_selection,
16501660
for ckey, chunk_select, out_select in zip(ckeys, lchunk_selection, lout_selection):
16511661
if ckey in cdatas:
16521662
self._process_chunk(out, cdatas[ckey], chunk_select, drop_axes,
1653-
out_is_ndarray)
1663+
out_is_ndarray, fields, out_select)
16541664
else:
16551665
# check exception type
16561666
if self._fill_value is not None:

0 commit comments

Comments
 (0)