Skip to content

Commit 87b2d0d

Browse files
committed
adds logic so _chunk_getitem is called with FSStore if indexer is expected to be empty
1 parent 480d21a commit 87b2d0d

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

zarr/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1020,7 +1020,7 @@ def _get_selection(self, indexer, out=None, fields=None):
10201020
check_array_shape('out', out, out_shape)
10211021

10221022
# iterate over chunks
1023-
if not hasattr(self.chunk_store, "getitems"):
1023+
if not hasattr(self.chunk_store, "getitems") or not all(map(lambda x: x != 0, self.shape)):
10241024
# sequentially get one key at a time from storage
10251025
for chunk_coords, chunk_selection, out_selection in indexer:
10261026

zarr/tests/test_core.py

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
from zarr.n5 import N5Store, n5_keywords
2121
from zarr.storage import (ABSStore, DBMStore, DirectoryStore, LMDBStore,
2222
LRUStoreCache, NestedDirectoryStore, SQLiteStore,
23-
atexit_rmglob, atexit_rmtree, init_array, init_group)
23+
atexit_rmglob, atexit_rmtree, init_array, init_group,
24+
FSStore)
2425
from zarr.util import buffer_size
2526
from zarr.tests.util import skip_test_env_var
2627

@@ -2366,3 +2367,54 @@ def create_array(read_only=False, **kwargs):
23662367
def test_store_has_bytes_values(self):
23672368
# skip as the cache has no control over how the store provides values
23682369
pass
2370+
2371+
2372+
class TestArrayWithFSStore(TestArray):
2373+
2374+
@staticmethod
2375+
def create_array(read_only=False, **kwargs):
2376+
path = mkdtemp()
2377+
atexit.register(shutil.rmtree, path)
2378+
#store = FSStore(f'file:/{path}')
2379+
store = FSStore(path)
2380+
print(store)
2381+
print(store.path)
2382+
cache_metadata = kwargs.pop('cache_metadata', True)
2383+
cache_attrs = kwargs.pop('cache_attrs', True)
2384+
kwargs.setdefault('compressor', Blosc())
2385+
init_array(store, **kwargs)
2386+
return Array(store, read_only=read_only, cache_metadata=cache_metadata,
2387+
cache_attrs=cache_attrs)
2388+
2389+
def test_hexdigest(self):
2390+
# Check basic 1-D array
2391+
z = self.create_array(shape=(1050,), chunks=100, dtype='<i4')
2392+
assert 'f710da18d45d38d4aaf2afd7fb822fdd73d02957' == z.hexdigest()
2393+
if hasattr(z.store, 'close'):
2394+
z.store.close()
2395+
2396+
# Check basic 1-D array with different type
2397+
z = self.create_array(shape=(1050,), chunks=100, dtype='<f4')
2398+
assert '1437428e69754b1e1a38bd7fc9e43669577620db' == z.hexdigest()
2399+
if hasattr(z.store, 'close'):
2400+
z.store.close()
2401+
2402+
# Check basic 2-D array
2403+
z = self.create_array(shape=(20, 35,), chunks=10, dtype='<i4')
2404+
assert '6c530b6b9d73e108cc5ee7b6be3d552cc994bdbe' == z.hexdigest()
2405+
if hasattr(z.store, 'close'):
2406+
z.store.close()
2407+
2408+
# Check basic 1-D array with some data
2409+
z = self.create_array(shape=(1050,), chunks=100, dtype='<i4')
2410+
z[200:400] = np.arange(200, 400, dtype='i4')
2411+
assert '4c0a76fb1222498e09dcd92f7f9221d6cea8b40e' == z.hexdigest()
2412+
if hasattr(z.store, 'close'):
2413+
z.store.close()
2414+
2415+
# Check basic 1-D array with attributes
2416+
z = self.create_array(shape=(1050,), chunks=100, dtype='<i4')
2417+
z.attrs['foo'] = 'bar'
2418+
assert '05b0663ffe1785f38d3a459dec17e57a18f254af' == z.hexdigest()
2419+
if hasattr(z.store, 'close'):
2420+
z.store.close()

0 commit comments

Comments
 (0)