Skip to content

Commit 449ed26

Browse files
authored
Update Array to respect FSStore's key_separator (#718)
* BUG: respect key_separator for FSStore * TST: add test case for nested FSStore * TST: switch from zarr.open to open_group * TST: avoid FSStore test method duplication * skip FSStore tests unless fsspec is available
1 parent 17728e8 commit 449ed26

File tree

2 files changed

+44
-7
lines changed

2 files changed

+44
-7
lines changed

zarr/core.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1950,7 +1950,11 @@ def _process_for_setitem(self, ckey, chunk_selection, value, fields=None):
19501950
return self._encode_chunk(chunk)
19511951

19521952
def _chunk_key(self, chunk_coords):
1953-
return self._key_prefix + '.'.join(map(str, chunk_coords))
1953+
if hasattr(self._store, 'key_separator'):
1954+
separator = self._store.key_separator
1955+
else:
1956+
separator = '.'
1957+
return self._key_prefix + separator.join(map(str, chunk_coords))
19541958

19551959
def _decode_chunk(self, cdata, start=None, nitems=None, expected_shape=None):
19561960
# decompress

zarr/tests/test_hierarchy.py

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@
2121
from zarr.core import Array
2222
from zarr.creation import open_array
2323
from zarr.hierarchy import Group, group, open_group
24-
from zarr.storage import (ABSStore, DBMStore, DirectoryStore, LMDBStore,
25-
LRUStoreCache, MemoryStore, NestedDirectoryStore,
26-
SQLiteStore, ZipStore, array_meta_key, atexit_rmglob,
27-
atexit_rmtree, group_meta_key, init_array,
28-
init_group)
24+
from zarr.storage import (ABSStore, DBMStore, DirectoryStore, FSStore,
25+
LMDBStore, LRUStoreCache, MemoryStore,
26+
NestedDirectoryStore, SQLiteStore, ZipStore,
27+
array_meta_key, atexit_rmglob, atexit_rmtree,
28+
group_meta_key, init_array, init_group)
2929
from zarr.util import InfoReporter
30-
from zarr.tests.util import skip_test_env_var
30+
from zarr.tests.util import skip_test_env_var, have_fsspec
3131

3232

3333
# noinspection PyStatementEffect
@@ -971,6 +971,39 @@ def create_store():
971971
return store, None
972972

973973

974+
@pytest.mark.skipif(have_fsspec is False, reason="needs fsspec")
975+
class TestGroupWithFSStore(TestGroup):
976+
977+
@staticmethod
978+
def create_store():
979+
path = tempfile.mkdtemp()
980+
atexit.register(atexit_rmtree, path)
981+
store = FSStore(path)
982+
return store, None
983+
984+
def test_round_trip_nd(self):
985+
data = np.arange(1000).reshape(10, 10, 10)
986+
name = 'raw'
987+
988+
store, _ = self.create_store()
989+
f = open_group(store, mode='w')
990+
f.create_dataset(name, data=data, chunks=(5, 5, 5),
991+
compressor=None)
992+
h = open_group(store, mode='r')
993+
np.testing.assert_array_equal(h[name][:], data)
994+
995+
996+
@pytest.mark.skipif(have_fsspec is False, reason="needs fsspec")
997+
class TestGroupWithNestedFSStore(TestGroupWithFSStore):
998+
999+
@staticmethod
1000+
def create_store():
1001+
path = tempfile.mkdtemp()
1002+
atexit.register(atexit_rmtree, path)
1003+
store = FSStore(path, key_separator='/', auto_mkdir=True)
1004+
return store, None
1005+
1006+
9741007
class TestGroupWithZipStore(TestGroup):
9751008

9761009
@staticmethod

0 commit comments

Comments
 (0)