def create_array(self, read_only=False, **kwargs): store = KVStore(dict()) cache_metadata = kwargs.pop('cache_metadata', True) cache_attrs = kwargs.pop('cache_attrs', True) write_empty_chunks = kwargs.pop('write_empty_chunks', True) init_array(store, **kwargs) return Array(store, synchronizer=ThreadSynchronizer(), read_only=read_only, cache_metadata=cache_metadata, cache_attrs=cache_attrs, write_empty_chunks=write_empty_chunks)
def _ensure_store(store: Any): """ We want to make sure internally that zarr stores are always a class with a specific interface derived from ``BaseStore``, which is slightly different than ``MutableMapping``. We'll do this conversion in a few places automatically """ from zarr.storage import KVStore # avoid circular import if store is None: return None elif isinstance(store, BaseStore): if not store._store_version == 2: raise ValueError( f"cannot initialize a v2 store with a v{store._store_version} store" ) return store elif isinstance(store, MutableMapping): return KVStore(store) else: for attr in [ "keys", "values", "get", "__setitem__", "__getitem__", "__delitem__", "__contains__", ]: if not hasattr(store, attr): break else: return KVStore(store) raise ValueError( "Starting with Zarr 2.11.0, stores must be subclasses of " "BaseStore, if your store exposes the MutableMapping interface " f"wrap it in Zarr.storage.KVStore. Got {store}")
def test_group(): # test the group() convenience function # basic usage g = group() assert isinstance(g, Group) assert '' == g.path assert '/' == g.name # usage with custom store store = KVStore(dict()) g = group(store=store) assert isinstance(g, Group) assert store is g.store # overwrite behaviour store = KVStore(dict()) init_array(store, shape=100, chunks=10) with pytest.raises(ValueError): group(store) g = group(store, overwrite=True) assert isinstance(g, Group) assert store is g.store
def test_storage(self, store_from_dict): if store_from_dict: store = dict() else: store = KVStore(dict()) a = Attributes(store=store, key='attrs') assert isinstance(a.store, KVStore) assert 'foo' not in a assert 'bar' not in a assert dict() == a.asdict() a['foo'] = 'bar' a['baz'] = 42 assert 'attrs' in store assert isinstance(store['attrs'], bytes) d = json.loads(str(store['attrs'], 'ascii')) assert dict(foo='bar', baz=42) == d
def create_store(): # can be overridden in sub-classes return KVStore(dict()), None
def create_store(): return KVStore(dict()), KVStore(dict())
def test_mismatched_store_versions(self): # cannot copy between stores of mixed Zarr versions dest = KVStore(dict()) with pytest.raises(ValueError): copy_store(self.source, dest)