Beispiel #1
0
def load(store: StoreLike):
    """Load data from an array or group into memory.

    Parameters
    ----------
    store : MutableMapping or string
        Store or path to directory in file system or name of zip file.

    Returns
    -------
    out
        If the store contains an array, out will be a numpy array. If the store contains
        a group, out will be a dict-like object where keys are array names and values
        are numpy arrays.

    See Also
    --------
    save, savez

    Notes
    -----
    If loading data from a group of arrays, data will not be immediately loaded into
    memory. Rather, arrays will be loaded into memory as they are requested.

    """
    # handle polymorphic store arg
    _store = normalize_store_arg(store)
    if contains_array(_store, path=None):
        return Array(store=_store, path=None)[...]
    elif contains_group(_store, path=None):
        grp = Group(store=_store, path=None)
        return LazyLoader(grp)
Beispiel #2
0
 def test_group_init_errors_2(self):
     store, chunk_store = self.create_store()
     init_array(store, shape=1000, chunks=100, chunk_store=chunk_store)
     # array blocks group
     with pytest.raises(ValueError):
         Group(store, chunk_store=chunk_store)
     store.close()
 def test_group_init_errors_1(self):
     store, chunk_store = self.create_store()
     # group metadata not initialized
     with pytest.raises(ValueError):
         Group(store, chunk_store=chunk_store)
     if hasattr(store, 'close'):
         store.close()
Beispiel #4
0
 def create_group(self, store=None, path=None, read_only=False,
                  chunk_store=None, synchronizer=None):
     # can be overridden in sub-classes
     if store is None:
         store, chunk_store = self.create_store()
     init_group(store, path=path, chunk_store=chunk_store)
     g = Group(store, path=path, read_only=read_only,
               chunk_store=chunk_store, synchronizer=synchronizer)
     return g
Beispiel #5
0
def test_group_init_from_dict(chunk_dict):
    if chunk_dict:
        store, chunk_store = dict(), dict()
    else:
        store, chunk_store = dict(), None
    init_group(store, path=None, chunk_store=chunk_store)
    g = Group(store, path=None, read_only=False, chunk_store=chunk_store)
    assert store is not g.store
    assert isinstance(g.store, KVStore)
    if chunk_store is None:
        assert g.store is g.chunk_store
    else:
        assert chunk_store is not g.chunk_store
Beispiel #6
0
 def create_group(self,
                  store=None,
                  path=None,
                  read_only=False,
                  chunk_store=None,
                  synchronizer=None):
     if store is None:
         store, chunk_store = self.create_store()
     init_group(store, path=path, chunk_store=chunk_store)
     synchronizer = ThreadSynchronizer()
     g = Group(store,
               path=path,
               read_only=read_only,
               chunk_store=chunk_store,
               synchronizer=synchronizer)
     return g
Beispiel #7
0
 def create_group(self,
                  store=None,
                  path=None,
                  read_only=False,
                  chunk_store=None,
                  synchronizer=None):
     if store is None:
         store, chunk_store = self.create_store()
     init_group(store, path=path, chunk_store=chunk_store)
     sync_path = tempfile.mkdtemp()
     atexit.register(atexit_rmtree, sync_path)
     synchronizer = ProcessSynchronizer(sync_path)
     g = Group(store,
               path=path,
               read_only=read_only,
               synchronizer=synchronizer,
               chunk_store=chunk_store)
     return g
Beispiel #8
0
def load(store: StoreLike, zarr_version=None, path=None):
    """Load data from an array or group into memory.

    Parameters
    ----------
    store : MutableMapping or string
        Store or path to directory in file system or name of zip file.
    zarr_version : {2, 3, None}, optional
        The zarr protocol version to use when loading. The default value of
        None will attempt to infer the version from `store` if possible,
        otherwise it will fall back to 2.
    path : str or None, optional
        The path within the store from which to load.

    Returns
    -------
    out
        If the store contains an array, out will be a numpy array. If the store contains
        a group, out will be a dict-like object where keys are array names and values
        are numpy arrays.

    See Also
    --------
    save, savez

    Notes
    -----
    If loading data from a group of arrays, data will not be immediately loaded into
    memory. Rather, arrays will be loaded into memory as they are requested.

    """
    # handle polymorphic store arg
    _store = normalize_store_arg(store, zarr_version=zarr_version)
    path = _check_and_update_path(_store, path)
    if contains_array(_store, path=path):
        return Array(store=_store, path=path)[...]
    elif contains_group(_store, path=path):
        grp = Group(store=_store, path=path)
        return LazyLoader(grp)
Beispiel #9
0
 def test_group_init_errors_1(self):
     store, chunk_store = self.create_store()
     # group metadata not initialized
     with assert_raises(ValueError):
         Group(store, chunk_store=chunk_store)
Beispiel #10
0
 def test_group_init_errors_2(self):
     store, chunk_store = self.create_store()
     init_array(store, shape=1000, chunks=100, chunk_store=chunk_store)
     # array blocks group
     with assert_raises(KeyError):
         Group(store, chunk_store=chunk_store)