Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Array to respect FSStore's key_separator #718

Merged
merged 5 commits into from
Apr 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion zarr/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1950,7 +1950,11 @@ def _process_for_setitem(self, ckey, chunk_selection, value, fields=None):
return self._encode_chunk(chunk)

def _chunk_key(self, chunk_coords):
return self._key_prefix + '.'.join(map(str, chunk_coords))
if hasattr(self._store, 'key_separator'):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A heads up that #716 deprecates key_separator in favor store._dimension_separator. Looking at this usage, I imagine wrapping stores like LRUCacheStore and ConsolidatedMetadataStore are going to need to set `_dimension_separator as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, thanks for letting me know. Should we hold off on this PR until #716 is in and then revisit?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nah, let's get this out as a point release. Just a warning that this "API" will change. It's all kismet.

Copy link
Contributor

@d-v-b d-v-b Apr 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The behavior of _chunk_key should not be changed here. Instead, the behavior of FSStore.getitems should be changed to properly remap the keys. See https://github.com/zarr-developers/zarr-python/pull/709/files#diff-565e487a2f60258b6baa2e4db8ef175cc16b8a949651834bd43d0a9f21e07358R1054

separator = self._store.key_separator
else:
separator = '.'
return self._key_prefix + separator.join(map(str, chunk_coords))

def _decode_chunk(self, cdata, start=None, nitems=None, expected_shape=None):
# decompress
Expand Down
45 changes: 39 additions & 6 deletions zarr/tests/test_hierarchy.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
from zarr.core import Array
from zarr.creation import open_array
from zarr.hierarchy import Group, group, open_group
from zarr.storage import (ABSStore, DBMStore, DirectoryStore, LMDBStore,
LRUStoreCache, MemoryStore, NestedDirectoryStore,
SQLiteStore, ZipStore, array_meta_key, atexit_rmglob,
atexit_rmtree, group_meta_key, init_array,
init_group)
from zarr.storage import (ABSStore, DBMStore, DirectoryStore, FSStore,
LMDBStore, LRUStoreCache, MemoryStore,
NestedDirectoryStore, SQLiteStore, ZipStore,
array_meta_key, atexit_rmglob, atexit_rmtree,
group_meta_key, init_array, init_group)
from zarr.util import InfoReporter
from zarr.tests.util import skip_test_env_var
from zarr.tests.util import skip_test_env_var, have_fsspec


# noinspection PyStatementEffect
Expand Down Expand Up @@ -971,6 +971,39 @@ def create_store():
return store, None


@pytest.mark.skipif(have_fsspec is False, reason="needs fsspec")
class TestGroupWithFSStore(TestGroup):

@staticmethod
def create_store():
path = tempfile.mkdtemp()
atexit.register(atexit_rmtree, path)
store = FSStore(path)
return store, None

def test_round_trip_nd(self):
data = np.arange(1000).reshape(10, 10, 10)
name = 'raw'

store, _ = self.create_store()
f = open_group(store, mode='w')
f.create_dataset(name, data=data, chunks=(5, 5, 5),
compressor=None)
h = open_group(store, mode='r')
np.testing.assert_array_equal(h[name][:], data)


@pytest.mark.skipif(have_fsspec is False, reason="needs fsspec")
class TestGroupWithNestedFSStore(TestGroupWithFSStore):

@staticmethod
def create_store():
path = tempfile.mkdtemp()
atexit.register(atexit_rmtree, path)
store = FSStore(path, key_separator='/', auto_mkdir=True)
return store, None


class TestGroupWithZipStore(TestGroup):

@staticmethod
Expand Down