Skip to content

Commit f401deb

Browse files
committed
Merge branch 'main' into real_world_s3_tests
2 parents 5c7f86b + 05ff036 commit f401deb

2 files changed

Lines changed: 60 additions & 43 deletions

File tree

activestorage/active_tools.py

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55
instead we're providing tools to hack instances of it
66
"""
77
import numpy as np
8-
from zarr.core import Array
8+
import zarr
9+
10+
from packaging import version
911

12+
from zarr.core import Array
1013
# import other zarr gubbins used in the methods we override
1114
from zarr.indexing import (
1215
OrthogonalIndexer,
@@ -171,18 +174,32 @@ def as_get_selection(self, indexer, out=None,
171174
chunks_info = []
172175
chunks_locs = []
173176

177+
# note: Zarr API has changed with zarr=2.15
178+
# hasattr(self.chunk_store, "getitems") = True for zarr >= 2.15
179+
zarr_version = zarr.__version__
180+
zarr_api_change_version = "2.15"
181+
if version.parse(zarr_version) < version.parse(zarr_api_change_version):
182+
att_getitems = not hasattr(self.chunk_store, "getitems")
183+
elif version.parse(zarr_version) >= version.parse(zarr_api_change_version):
184+
att_getitems = hasattr(self.chunk_store, "getitems")
174185
# iterate over chunks
175-
if not hasattr(self.chunk_store, "getitems") or \
176-
any(map(lambda x: x == 0, self.shape)):
186+
if att_getitems or any(map(lambda x: x == 0, self.shape)):
177187
# sequentially get one key at a time from storage
178188
for chunk_coords, chunk_selection, out_selection in indexer:
179189

180-
# load chunk selection into output array
181-
pci = self._chunk_getitem(chunk_coords, chunk_selection, out, out_selection,
182-
drop_axes=indexer.drop_axes, fields=fields)
183-
184-
chunks_info.append(pci)
185-
chunks_locs.append(chunk_coords)
190+
if version.parse(zarr_version) < version.parse(zarr_api_change_version):
191+
# load chunk selection into output array
192+
pci = self._chunk_getitem(chunk_coords, chunk_selection, out, out_selection,
193+
drop_axes=indexer.drop_axes, fields=fields)
194+
chunks_info.append(pci)
195+
chunks_locs.append(chunk_coords)
196+
elif version.parse(zarr_version) >= version.parse(zarr_api_change_version):
197+
chunk_coords = [chunk_coords]
198+
# load chunk selection into output array
199+
pci = self._chunk_getitems(chunk_coords, chunk_selection, out, out_selection,
200+
drop_axes=indexer.drop_axes, fields=fields)
201+
chunks_info.append(pci)
202+
chunks_locs.append(chunk_coords[0])
186203
else:
187204
# allow storage to get multiple items at once
188205
lchunk_coords, lchunk_selection, lout_selection = zip(*indexer)

0 commit comments

Comments
 (0)