Closed
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
8 changes: 4 additions & 4 deletions docs/tutorial.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -176,7 +176,7 @@ print some diagnostics, e.g.::
Read-only : False
Compressor : Blosc(cname='zstd', clevel=3, shuffle=BITSHUFFLE,
: blocksize=0)
Store type : builtins.dict
Store type : zarr.storage.DictStore
No. bytes : 400000000 (381.5M)
No. bytes stored : 3379344 (3.2M)
Storage ratio : 118.4
Expand DownExpand Up@@ -268,7 +268,7 @@ Here is an example using a delta filter with the Blosc compressor::
Read-only : False
Filter [0] : Delta(dtype='<i4')
Compressor : Blosc(cname='zstd', clevel=1, shuffle=SHUFFLE, blocksize=0)
Store type : builtins.dict
Store type : zarr.storage.DictStore
No. bytes : 400000000 (381.5M)
No. bytes stored : 648605 (633.4K)
Storage ratio : 616.7
Expand DownExpand Up@@ -1198,7 +1198,7 @@ ratios, depending on the correlation structure within the data. E.g.::
Order : C
Read-only : False
Compressor : Blosc(cname='lz4', clevel=5, shuffle=SHUFFLE, blocksize=0)
Store type : builtins.dict
Store type : zarr.storage.DictStore
No. bytes : 400000000 (381.5M)
No. bytes stored : 6696010 (6.4M)
Storage ratio : 59.7
Expand All@@ -1212,7 +1212,7 @@ ratios, depending on the correlation structure within the data. E.g.::
Order : F
Read-only : False
Compressor : Blosc(cname='lz4', clevel=5, shuffle=SHUFFLE, blocksize=0)
Store type : builtins.dict
Store type : zarr.storage.DictStore
No. bytes : 400000000 (381.5M)
No. bytes stored : 4684636 (4.5M)
Storage ratio : 85.4
Expand Down
13 changes: 6 additions & 7 deletions zarr/core.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -108,6 +108,9 @@ def __init__(self, store, path=None, read_only=False, chunk_store=None,
# N.B., expect at this point store is fully initialized with all
# configuration metadata fully specified and normalized

if isinstance(store, dict):
raise TypeError("Please use Zarr's DictStore instead")

self._store = store
self._chunk_store = chunk_store
self._path = normalize_storage_path(path)
Expand DownExpand Up@@ -1778,10 +1781,6 @@ def _encode_chunk(self, chunk):
else:
cdata = chunk

# ensure in-memory data is immutable and easy to compare
if isinstance(self.chunk_store, dict):
cdata = ensure_bytes(cdata)

return cdata

def __repr__(self):
Expand DownExpand Up@@ -1812,10 +1811,10 @@ def info(self):
Order : C
Read-only : False
Compressor : Blosc(cname='lz4', clevel=5, shuffle=SHUFFLE, blocksize=0)
Store type : builtins.dict
Store type : zarr.storage.DictStore
No. bytes : 4000000 (3.8M)
No. bytes stored : ...
Storage ratio : ...
No. bytes stored : 320
Storage ratio : 12500.0
Chunks initialized : 0/10

"""
Expand Down
6 changes: 3 additions & 3 deletions zarr/creation.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,7 +7,7 @@


from zarr.core import Array
from zarr.storage import (DirectoryStore, init_array, contains_array, contains_group,
from zarr.storage import (DictStore, DirectoryStore, init_array, contains_array, contains_group,
default_compressor, normalize_storage_path, ZipStore)
from numcodecs.registry import codec_registry
from zarr.errors import err_contains_array, err_contains_group, err_array_not_found
Expand DownExpand Up@@ -98,7 +98,7 @@ def create(shape, chunks=True, dtype=None, compressor='default',
Example with some filters, and also storing chunks separately from metadata::

>>> from numcodecs import Quantize, Adler32
>>> store, chunk_store = dict(), dict()
>>> store, chunk_store = DictStore(), DictStore()
>>> z = zarr.create((10000, 10000), chunks=(1000, 1000), dtype='f8',
... filters=[Quantize(digits=2, dtype='f8'), Adler32()],
... store=store, chunk_store=chunk_store)
Expand All@@ -125,7 +125,7 @@ def create(shape, chunks=True, dtype=None, compressor='default',
return z


def normalize_store_arg(store, clobber=False, default=dict):
def normalize_store_arg(store, clobber=False, default=DictStore):
if store is None:
return default()
elif isinstance(store, str):
Expand Down
3 changes: 3 additions & 0 deletions zarr/hierarchy.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -91,6 +91,9 @@ class Group(MutableMapping):

def __init__(self, store, path=None, read_only=False, chunk_store=None,
cache_attrs=True, synchronizer=None):
if isinstance(store, dict):
raise TypeError("Please use Zarr's DictStore instead")

self._store = store
self._chunk_store = chunk_store
self._path = normalize_storage_path(path)
Expand Down
5 changes: 2 additions & 3 deletions zarr/storage.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -476,12 +476,11 @@ class DictStore(MutableMapping):
>>> type(g.store)
<class 'zarr.storage.DictStore'>

Note that the default class when creating an array is the built-in
:class:`dict` class, i.e.::
Also this is the default class when creating an array. E.g.::

>>> z = zarr.zeros(100)
>>> type(z.store)
<class 'dict'>
<class 'zarr.storage.DictStore'>

Notes
-----
Expand Down
62 changes: 37 additions & 25 deletions zarr/tests/test_core.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,7 +15,7 @@
import pytest


from zarr.storage import (DirectoryStore, init_array, init_group, NestedDirectoryStore,
from zarr.storage import (DictStore, DirectoryStore, init_array, init_group, NestedDirectoryStore,
DBMStore, LMDBStore, SQLiteStore, atexit_rmtree, atexit_rmglob,
LRUStoreCache)
from zarr.core import Array
Expand All@@ -41,7 +41,7 @@ class TestArray(unittest.TestCase):
def test_array_init(self):

# normal initialization
store = dict()
store = DictStore()
init_array(store, shape=100, chunks=10)
a = Array(store)
assert isinstance(a, Array)
Expand All@@ -54,7 +54,7 @@ def test_array_init(self):
assert "8fecb7a17ea1493d9c1430d04437b4f5b0b34985" == a.hexdigest()

# initialize at path
store = dict()
store = DictStore()
init_array(store, shape=100, chunks=10, path='foo/bar')
a = Array(store, path='foo/bar')
assert isinstance(a, Array)
Expand All@@ -67,18 +67,18 @@ def test_array_init(self):
assert "8fecb7a17ea1493d9c1430d04437b4f5b0b34985" == a.hexdigest()

# store not initialized
store = dict()
store = DictStore()
with pytest.raises(ValueError):
Array(store)

# group is in the way
store = dict()
store = DictStore()
init_group(store, path='baz')
with pytest.raises(ValueError):
Array(store, path='baz')

def create_array(self, read_only=False, **kwargs):
store = dict()
store = DictStore()
kwargs.setdefault('compressor', Zlib(level=1))
cache_metadata = kwargs.pop('cache_metadata', True)
cache_attrs = kwargs.pop('cache_attrs', True)
Expand DownExpand Up@@ -1255,7 +1255,7 @@ class TestArrayWithPath(TestArray):

@staticmethod
def create_array(read_only=False, **kwargs):
store = dict()
store = DictStore()
cache_metadata = kwargs.pop('cache_metadata', True)
cache_attrs = kwargs.pop('cache_attrs', True)
init_array(store, path='foo/bar', **kwargs)
Expand DownExpand Up@@ -1299,18 +1299,14 @@ def test_nbytes_stored(self):
if k.startswith('foo/bar/'))
assert expect_nbytes_stored == z.nbytes_stored

# mess with store
z.store[z._key_prefix + 'foo'] = list(range(10))
assert -1 == z.nbytes_stored


class TestArrayWithChunkStore(TestArray):

@staticmethod
def create_array(read_only=False, **kwargs):
store = dict()
store = DictStore()
# separate chunk store
chunk_store = dict()
chunk_store = DictStore()
cache_metadata = kwargs.pop('cache_metadata', True)
cache_attrs = kwargs.pop('cache_attrs', True)
init_array(store, chunk_store=chunk_store, **kwargs)
Expand DownExpand Up@@ -1353,10 +1349,6 @@ def test_nbytes_stored(self):
for v in z.chunk_store.values())
assert expect_nbytes_stored == z.nbytes_stored

# mess with store
z.chunk_store[z._key_prefix + 'foo'] = list(range(10))
assert -1 == z.nbytes_stored


class TestArrayWithDirectoryStore(TestArray):

Expand DownExpand Up@@ -1516,7 +1508,7 @@ def test_nbytes_stored(self):
class TestArrayWithNoCompressor(TestArray):

def create_array(self, read_only=False, **kwargs):
store = dict()
store = DictStore()
kwargs.setdefault('compressor', None)
cache_metadata = kwargs.pop('cache_metadata', True)
cache_attrs = kwargs.pop('cache_attrs', True)
Expand DownExpand Up@@ -1551,7 +1543,7 @@ def test_hexdigest(self):
class TestArrayWithBZ2Compressor(TestArray):

def create_array(self, read_only=False, **kwargs):
store = dict()
store = DictStore()
compressor = BZ2(level=1)
kwargs.setdefault('compressor', compressor)
cache_metadata = kwargs.pop('cache_metadata', True)
Expand DownExpand Up@@ -1587,7 +1579,7 @@ def test_hexdigest(self):
class TestArrayWithBloscCompressor(TestArray):

def create_array(self, read_only=False, **kwargs):
store = dict()
store = DictStore()
compressor = Blosc(cname='zstd', clevel=1, shuffle=1)
kwargs.setdefault('compressor', compressor)
cache_metadata = kwargs.pop('cache_metadata', True)
Expand DownExpand Up@@ -1630,7 +1622,7 @@ def test_hexdigest(self):
class TestArrayWithLZMACompressor(TestArray):

def create_array(self, read_only=False, **kwargs):
store = dict()
store = DictStore()
compressor = LZMA(preset=1)
kwargs.setdefault('compressor', compressor)
cache_metadata = kwargs.pop('cache_metadata', True)
Expand DownExpand Up@@ -1667,7 +1659,7 @@ class TestArrayWithFilters(TestArray):

@staticmethod
def create_array(read_only=False, **kwargs):
store = dict()
store = DictStore()
dtype = kwargs.get('dtype', None)
filters = [
Delta(dtype=dtype),
Expand DownExpand Up@@ -1710,7 +1702,7 @@ def test_astype_no_filters(self):
dtype = np.dtype(np.int8)
astype = np.dtype(np.float32)

store = dict()
store = DictStore()
init_array(store, shape=shape, chunks=10, dtype=dtype)

data = np.arange(np.prod(shape), dtype=dtype).reshape(shape)
Expand DownExpand Up@@ -1830,11 +1822,31 @@ def test_nbytes_stored(self):
assert -1 == z.nbytes_stored


class TestArrayWithCustomChunkStore(TestArray):

@staticmethod
def create_array(read_only=False, **kwargs):
store = CustomMapping()
kwargs["chunk_store"] = CustomMapping()
kwargs.setdefault('compressor', Zlib(1))
cache_metadata = kwargs.pop('cache_metadata', True)
cache_attrs = kwargs.pop('cache_attrs', True)
init_array(store, **kwargs)
return Array(store, read_only=read_only, cache_metadata=cache_metadata,
cache_attrs=cache_attrs)

def test_nbytes_stored(self):
z = self.create_array(shape=1000, chunks=100)
assert -1 == z.nbytes_stored
z[:] = 42
assert -1 == z.nbytes_stored


class TestArrayNoCache(TestArray):

@staticmethod
def create_array(read_only=False, **kwargs):
store = dict()
store = DictStore()
kwargs.setdefault('compressor', Zlib(level=1))
cache_metadata = kwargs.pop('cache_metadata', True)
cache_attrs = kwargs.pop('cache_attrs', True)
Expand DownExpand Up@@ -1906,7 +1918,7 @@ class TestArrayWithStoreCache(TestArray):

@staticmethod
def create_array(read_only=False, **kwargs):
store = LRUStoreCache(dict(), max_size=None)
store = LRUStoreCache(DictStore(), max_size=None)
kwargs.setdefault('compressor', Zlib(level=1))
cache_metadata = kwargs.pop('cache_metadata', True)
cache_attrs = kwargs.pop('cache_attrs', True)
Expand Down
10 changes: 5 additions & 5 deletions zarr/tests/test_hierarchy.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -41,7 +41,7 @@ class TestGroup(unittest.TestCase):
@staticmethod
def create_store():
# can be overridden in sub-classes
return dict(), None
return DictStore(), None

def create_group(self, store=None, path=None, read_only=False,
chunk_store=None, synchronizer=None):
Expand DownExpand Up@@ -948,7 +948,7 @@ class TestGroupWithChunkStore(TestGroup):

@staticmethod
def create_store():
return dict(), dict()
return DictStore(), DictStore()

def test_chunk_store(self):
# setup
Expand DownExpand Up@@ -979,7 +979,7 @@ class TestGroupWithStoreCache(TestGroup):

@staticmethod
def create_store():
store = LRUStoreCache(dict(), max_size=None)
store = LRUStoreCache(DictStore(), max_size=None)
return store, None


Expand All@@ -993,13 +993,13 @@ def test_group():
assert '/' == g.name

# usage with custom store
store = dict()
store = DictStore()
g = group(store=store)
assert isinstance(g, Group)
assert store is g.store

# overwrite behaviour
store = dict()
store = DictStore()
init_array(store, shape=100, chunks=10)
with pytest.raises(ValueError):
group(store)
Expand Down
2 changes: 1 addition & 1 deletion zarr/tests/test_info.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,7 +9,7 @@
def test_info():

# setup
g = zarr.group(store=dict(), chunk_store=dict(),
g = zarr.group(store=zarr.DictStore(), chunk_store=zarr.DictStore(),
synchronizer=zarr.ThreadSynchronizer())
g.create_group('foo')
z = g.zeros('bar', shape=10, filters=[numcodecs.Adler32()])
Expand Down
4 changes: 2 additions & 2 deletions zarr/tests/test_sync.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -19,7 +19,7 @@
from zarr.sync import ThreadSynchronizer, ProcessSynchronizer
from zarr.core import Array
from zarr.attrs import Attributes
from zarr.storage import init_array, DirectoryStore, init_group, atexit_rmtree
from zarr.storage import init_array, DictStore, DirectoryStore, init_group, atexit_rmtree
from zarr.hierarchy import Group


Expand DownExpand Up@@ -100,7 +100,7 @@ def test_parallel_append(self):
class TestArrayWithThreadSynchronizer(TestArray, MixinArraySyncTests):

def create_array(self, read_only=False, **kwargs):
store = dict()
store = DictStore()
cache_metadata = kwargs.pop('cache_metadata', True)
cache_attrs = kwargs.pop('cache_attrs', True)
init_array(store, **kwargs)
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content
Closed
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
8 changes: 4 additions & 4 deletions docs/tutorial.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -176,7 +176,7 @@ print some diagnostics, e.g.::
Read-only : False
Compressor : Blosc(cname='zstd', clevel=3, shuffle=BITSHUFFLE,
: blocksize=0)
Store type : builtins.dict
Store type : zarr.storage.DictStore
No. bytes : 400000000 (381.5M)
No. bytes stored : 3379344 (3.2M)
Storage ratio : 118.4
Expand DownExpand Up@@ -268,7 +268,7 @@ Here is an example using a delta filter with the Blosc compressor::
Read-only : False
Filter [0] : Delta(dtype='<i4')
Compressor : Blosc(cname='zstd', clevel=1, shuffle=SHUFFLE, blocksize=0)
Store type : builtins.dict
Store type : zarr.storage.DictStore
No. bytes : 400000000 (381.5M)
No. bytes stored : 648605 (633.4K)
Storage ratio : 616.7
Expand DownExpand Up@@ -1198,7 +1198,7 @@ ratios, depending on the correlation structure within the data. E.g.::
Order : C
Read-only : False
Compressor : Blosc(cname='lz4', clevel=5, shuffle=SHUFFLE, blocksize=0)
Store type : builtins.dict
Store type : zarr.storage.DictStore
No. bytes : 400000000 (381.5M)
No. bytes stored : 6696010 (6.4M)
Storage ratio : 59.7
Expand All@@ -1212,7 +1212,7 @@ ratios, depending on the correlation structure within the data. E.g.::
Order : F
Read-only : False
Compressor : Blosc(cname='lz4', clevel=5, shuffle=SHUFFLE, blocksize=0)
Store type : builtins.dict
Store type : zarr.storage.DictStore
No. bytes : 400000000 (381.5M)
No. bytes stored : 4684636 (4.5M)
Storage ratio : 85.4
Expand Down
13 changes: 6 additions & 7 deletions zarr/core.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -108,6 +108,9 @@ def __init__(self, store, path=None, read_only=False, chunk_store=None,
# N.B., expect at this point store is fully initialized with all
# configuration metadata fully specified and normalized

if isinstance(store, dict):
raise TypeError("Please use Zarr's DictStore instead")

self._store = store
self._chunk_store = chunk_store
self._path = normalize_storage_path(path)
Expand DownExpand Up@@ -1778,10 +1781,6 @@ def _encode_chunk(self, chunk):
else:
cdata = chunk

# ensure in-memory data is immutable and easy to compare
if isinstance(self.chunk_store, dict):
cdata = ensure_bytes(cdata)

return cdata

def __repr__(self):
Expand DownExpand Up@@ -1812,10 +1811,10 @@ def info(self):
Order : C
Read-only : False
Compressor : Blosc(cname='lz4', clevel=5, shuffle=SHUFFLE, blocksize=0)
Store type : builtins.dict
Store type : zarr.storage.DictStore
No. bytes : 4000000 (3.8M)
No. bytes stored : ...
Storage ratio : ...
No. bytes stored : 320
Storage ratio : 12500.0
Chunks initialized : 0/10

"""
Expand Down
6 changes: 3 additions & 3 deletions zarr/creation.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,7 +7,7 @@


from zarr.core import Array
from zarr.storage import (DirectoryStore, init_array, contains_array, contains_group,
from zarr.storage import (DictStore, DirectoryStore, init_array, contains_array, contains_group,
default_compressor, normalize_storage_path, ZipStore)
from numcodecs.registry import codec_registry
from zarr.errors import err_contains_array, err_contains_group, err_array_not_found
Expand DownExpand Up@@ -98,7 +98,7 @@ def create(shape, chunks=True, dtype=None, compressor='default',
Example with some filters, and also storing chunks separately from metadata::

>>> from numcodecs import Quantize, Adler32
>>> store, chunk_store = dict(), dict()
>>> store, chunk_store = DictStore(), DictStore()
>>> z = zarr.create((10000, 10000), chunks=(1000, 1000), dtype='f8',
... filters=[Quantize(digits=2, dtype='f8'), Adler32()],
... store=store, chunk_store=chunk_store)
Expand All@@ -125,7 +125,7 @@ def create(shape, chunks=True, dtype=None, compressor='default',
return z


def normalize_store_arg(store, clobber=False, default=dict):
def normalize_store_arg(store, clobber=False, default=DictStore):
if store is None:
return default()
elif isinstance(store, str):
Expand Down
3 changes: 3 additions & 0 deletions zarr/hierarchy.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -91,6 +91,9 @@ class Group(MutableMapping):

def __init__(self, store, path=None, read_only=False, chunk_store=None,
cache_attrs=True, synchronizer=None):
if isinstance(store, dict):
raise TypeError("Please use Zarr's DictStore instead")

self._store = store
self._chunk_store = chunk_store
self._path = normalize_storage_path(path)
Expand Down
5 changes: 2 additions & 3 deletions zarr/storage.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -476,12 +476,11 @@ class DictStore(MutableMapping):
>>> type(g.store)
<class 'zarr.storage.DictStore'>

Note that the default class when creating an array is the built-in
:class:`dict` class, i.e.::
Also this is the default class when creating an array. E.g.::

>>> z = zarr.zeros(100)
>>> type(z.store)
<class 'dict'>
<class 'zarr.storage.DictStore'>

Notes
-----
Expand Down
62 changes: 37 additions & 25 deletions zarr/tests/test_core.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,7 +15,7 @@
import pytest


from zarr.storage import (DirectoryStore, init_array, init_group, NestedDirectoryStore,
from zarr.storage import (DictStore, DirectoryStore, init_array, init_group, NestedDirectoryStore,
DBMStore, LMDBStore, SQLiteStore, atexit_rmtree, atexit_rmglob,
LRUStoreCache)
from zarr.core import Array
Expand All@@ -41,7 +41,7 @@ class TestArray(unittest.TestCase):
def test_array_init(self):

# normal initialization
store = dict()
store = DictStore()
init_array(store, shape=100, chunks=10)
a = Array(store)
assert isinstance(a, Array)
Expand All@@ -54,7 +54,7 @@ def test_array_init(self):
assert "8fecb7a17ea1493d9c1430d04437b4f5b0b34985" == a.hexdigest()

# initialize at path
store = dict()
store = DictStore()
init_array(store, shape=100, chunks=10, path='foo/bar')
a = Array(store, path='foo/bar')
assert isinstance(a, Array)
Expand All@@ -67,18 +67,18 @@ def test_array_init(self):
assert "8fecb7a17ea1493d9c1430d04437b4f5b0b34985" == a.hexdigest()

# store not initialized
store = dict()
store = DictStore()
with pytest.raises(ValueError):
Array(store)

# group is in the way
store = dict()
store = DictStore()
init_group(store, path='baz')
with pytest.raises(ValueError):
Array(store, path='baz')

def create_array(self, read_only=False, **kwargs):
store = dict()
store = DictStore()
kwargs.setdefault('compressor', Zlib(level=1))
cache_metadata = kwargs.pop('cache_metadata', True)
cache_attrs = kwargs.pop('cache_attrs', True)
Expand DownExpand Up@@ -1255,7 +1255,7 @@ class TestArrayWithPath(TestArray):

@staticmethod
def create_array(read_only=False, **kwargs):
store = dict()
store = DictStore()
cache_metadata = kwargs.pop('cache_metadata', True)
cache_attrs = kwargs.pop('cache_attrs', True)
init_array(store, path='foo/bar', **kwargs)
Expand DownExpand Up@@ -1299,18 +1299,14 @@ def test_nbytes_stored(self):
if k.startswith('foo/bar/'))
assert expect_nbytes_stored == z.nbytes_stored

# mess with store
z.store[z._key_prefix + 'foo'] = list(range(10))
assert -1 == z.nbytes_stored


class TestArrayWithChunkStore(TestArray):

@staticmethod
def create_array(read_only=False, **kwargs):
store = dict()
store = DictStore()
# separate chunk store
chunk_store = dict()
chunk_store = DictStore()
cache_metadata = kwargs.pop('cache_metadata', True)
cache_attrs = kwargs.pop('cache_attrs', True)
init_array(store, chunk_store=chunk_store, **kwargs)
Expand DownExpand Up@@ -1353,10 +1349,6 @@ def test_nbytes_stored(self):
for v in z.chunk_store.values())
assert expect_nbytes_stored == z.nbytes_stored

# mess with store
z.chunk_store[z._key_prefix + 'foo'] = list(range(10))
assert -1 == z.nbytes_stored


class TestArrayWithDirectoryStore(TestArray):

Expand DownExpand Up@@ -1516,7 +1508,7 @@ def test_nbytes_stored(self):
class TestArrayWithNoCompressor(TestArray):

def create_array(self, read_only=False, **kwargs):
store = dict()
store = DictStore()
kwargs.setdefault('compressor', None)
cache_metadata = kwargs.pop('cache_metadata', True)
cache_attrs = kwargs.pop('cache_attrs', True)
Expand DownExpand Up@@ -1551,7 +1543,7 @@ def test_hexdigest(self):
class TestArrayWithBZ2Compressor(TestArray):

def create_array(self, read_only=False, **kwargs):
store = dict()
store = DictStore()
compressor = BZ2(level=1)
kwargs.setdefault('compressor', compressor)
cache_metadata = kwargs.pop('cache_metadata', True)
Expand DownExpand Up@@ -1587,7 +1579,7 @@ def test_hexdigest(self):
class TestArrayWithBloscCompressor(TestArray):

def create_array(self, read_only=False, **kwargs):
store = dict()
store = DictStore()
compressor = Blosc(cname='zstd', clevel=1, shuffle=1)
kwargs.setdefault('compressor', compressor)
cache_metadata = kwargs.pop('cache_metadata', True)
Expand DownExpand Up@@ -1630,7 +1622,7 @@ def test_hexdigest(self):
class TestArrayWithLZMACompressor(TestArray):

def create_array(self, read_only=False, **kwargs):
store = dict()
store = DictStore()
compressor = LZMA(preset=1)
kwargs.setdefault('compressor', compressor)
cache_metadata = kwargs.pop('cache_metadata', True)
Expand DownExpand Up@@ -1667,7 +1659,7 @@ class TestArrayWithFilters(TestArray):

@staticmethod
def create_array(read_only=False, **kwargs):
store = dict()
store = DictStore()
dtype = kwargs.get('dtype', None)
filters = [
Delta(dtype=dtype),
Expand DownExpand Up@@ -1710,7 +1702,7 @@ def test_astype_no_filters(self):
dtype = np.dtype(np.int8)
astype = np.dtype(np.float32)

store = dict()
store = DictStore()
init_array(store, shape=shape, chunks=10, dtype=dtype)

data = np.arange(np.prod(shape), dtype=dtype).reshape(shape)
Expand DownExpand Up@@ -1830,11 +1822,31 @@ def test_nbytes_stored(self):
assert -1 == z.nbytes_stored


class TestArrayWithCustomChunkStore(TestArray):

@staticmethod
def create_array(read_only=False, **kwargs):
store = CustomMapping()
kwargs["chunk_store"] = CustomMapping()
kwargs.setdefault('compressor', Zlib(1))
cache_metadata = kwargs.pop('cache_metadata', True)
cache_attrs = kwargs.pop('cache_attrs', True)
init_array(store, **kwargs)
return Array(store, read_only=read_only, cache_metadata=cache_metadata,
cache_attrs=cache_attrs)

def test_nbytes_stored(self):
z = self.create_array(shape=1000, chunks=100)
assert -1 == z.nbytes_stored
z[:] = 42
assert -1 == z.nbytes_stored


class TestArrayNoCache(TestArray):

@staticmethod
def create_array(read_only=False, **kwargs):
store = dict()
store = DictStore()
kwargs.setdefault('compressor', Zlib(level=1))
cache_metadata = kwargs.pop('cache_metadata', True)
cache_attrs = kwargs.pop('cache_attrs', True)
Expand DownExpand Up@@ -1906,7 +1918,7 @@ class TestArrayWithStoreCache(TestArray):

@staticmethod
def create_array(read_only=False, **kwargs):
store = LRUStoreCache(dict(), max_size=None)
store = LRUStoreCache(DictStore(), max_size=None)
kwargs.setdefault('compressor', Zlib(level=1))
cache_metadata = kwargs.pop('cache_metadata', True)
cache_attrs = kwargs.pop('cache_attrs', True)
Expand Down
10 changes: 5 additions & 5 deletions zarr/tests/test_hierarchy.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -41,7 +41,7 @@ class TestGroup(unittest.TestCase):
@staticmethod
def create_store():
# can be overridden in sub-classes
return dict(), None
return DictStore(), None

def create_group(self, store=None, path=None, read_only=False,
chunk_store=None, synchronizer=None):
Expand DownExpand Up@@ -948,7 +948,7 @@ class TestGroupWithChunkStore(TestGroup):

@staticmethod
def create_store():
return dict(), dict()
return DictStore(), DictStore()

def test_chunk_store(self):
# setup
Expand DownExpand Up@@ -979,7 +979,7 @@ class TestGroupWithStoreCache(TestGroup):

@staticmethod
def create_store():
store = LRUStoreCache(dict(), max_size=None)
store = LRUStoreCache(DictStore(), max_size=None)
return store, None


Expand All@@ -993,13 +993,13 @@ def test_group():
assert '/' == g.name

# usage with custom store
store = dict()
store = DictStore()
g = group(store=store)
assert isinstance(g, Group)
assert store is g.store

# overwrite behaviour
store = dict()
store = DictStore()
init_array(store, shape=100, chunks=10)
with pytest.raises(ValueError):
group(store)
Expand Down
2 changes: 1 addition & 1 deletion zarr/tests/test_info.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,7 +9,7 @@
def test_info():

# setup
g = zarr.group(store=dict(), chunk_store=dict(),
g = zarr.group(store=zarr.DictStore(), chunk_store=zarr.DictStore(),
synchronizer=zarr.ThreadSynchronizer())
g.create_group('foo')
z = g.zeros('bar', shape=10, filters=[numcodecs.Adler32()])
Expand Down
4 changes: 2 additions & 2 deletions zarr/tests/test_sync.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -19,7 +19,7 @@
from zarr.sync import ThreadSynchronizer, ProcessSynchronizer
from zarr.core import Array
from zarr.attrs import Attributes
from zarr.storage import init_array, DirectoryStore, init_group, atexit_rmtree
from zarr.storage import init_array, DictStore, DirectoryStore, init_group, atexit_rmtree
from zarr.hierarchy import Group


Expand DownExpand Up@@ -100,7 +100,7 @@ def test_parallel_append(self):
class TestArrayWithThreadSynchronizer(TestArray, MixinArraySyncTests):

def create_array(self, read_only=False, **kwargs):
store = dict()
store = DictStore()
cache_metadata = kwargs.pop('cache_metadata', True)
cache_attrs = kwargs.pop('cache_attrs', True)
init_array(store, **kwargs)
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Closed
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
8 changes: 4 additions & 4 deletions docs/tutorial.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -176,7 +176,7 @@ print some diagnostics, e.g.::
Read-only : False
Compressor : Blosc(cname='zstd', clevel=3, shuffle=BITSHUFFLE,
: blocksize=0)
Store type : builtins.dict
Store type : zarr.storage.DictStore
No. bytes : 400000000 (381.5M)
No. bytes stored : 3379344 (3.2M)
Storage ratio : 118.4
Expand DownExpand Up@@ -268,7 +268,7 @@ Here is an example using a delta filter with the Blosc compressor::
Read-only : False
Filter [0] : Delta(dtype='<i4')
Compressor : Blosc(cname='zstd', clevel=1, shuffle=SHUFFLE, blocksize=0)
Store type : builtins.dict
Store type : zarr.storage.DictStore
No. bytes : 400000000 (381.5M)
No. bytes stored : 648605 (633.4K)
Storage ratio : 616.7
Expand DownExpand Up@@ -1198,7 +1198,7 @@ ratios, depending on the correlation structure within the data. E.g.::
Order : C
Read-only : False
Compressor : Blosc(cname='lz4', clevel=5, shuffle=SHUFFLE, blocksize=0)
Store type : builtins.dict
Store type : zarr.storage.DictStore
No. bytes : 400000000 (381.5M)
No. bytes stored : 6696010 (6.4M)
Storage ratio : 59.7
Expand All@@ -1212,7 +1212,7 @@ ratios, depending on the correlation structure within the data. E.g.::
Order : F
Read-only : False
Compressor : Blosc(cname='lz4', clevel=5, shuffle=SHUFFLE, blocksize=0)
Store type : builtins.dict
Store type : zarr.storage.DictStore
No. bytes : 400000000 (381.5M)
No. bytes stored : 4684636 (4.5M)
Storage ratio : 85.4
Expand Down
13 changes: 6 additions & 7 deletions zarr/core.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -108,6 +108,9 @@ def __init__(self, store, path=None, read_only=False, chunk_store=None,
# N.B., expect at this point store is fully initialized with all
# configuration metadata fully specified and normalized

if isinstance(store, dict):
raise TypeError("Please use Zarr's DictStore instead")

self._store = store
self._chunk_store = chunk_store
self._path = normalize_storage_path(path)
Expand DownExpand Up@@ -1778,10 +1781,6 @@ def _encode_chunk(self, chunk):
else:
cdata = chunk

# ensure in-memory data is immutable and easy to compare
if isinstance(self.chunk_store, dict):
cdata = ensure_bytes(cdata)

return cdata

def __repr__(self):
Expand DownExpand Up@@ -1812,10 +1811,10 @@ def info(self):
Order : C
Read-only : False
Compressor : Blosc(cname='lz4', clevel=5, shuffle=SHUFFLE, blocksize=0)
Store type : builtins.dict
Store type : zarr.storage.DictStore
No. bytes : 4000000 (3.8M)
No. bytes stored : ...
Storage ratio : ...
No. bytes stored : 320
Storage ratio : 12500.0
Chunks initialized : 0/10

"""
Expand Down
6 changes: 3 additions & 3 deletions zarr/creation.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,7 +7,7 @@


from zarr.core import Array
from zarr.storage import (DirectoryStore, init_array, contains_array, contains_group,
from zarr.storage import (DictStore, DirectoryStore, init_array, contains_array, contains_group,
default_compressor, normalize_storage_path, ZipStore)
from numcodecs.registry import codec_registry
from zarr.errors import err_contains_array, err_contains_group, err_array_not_found
Expand DownExpand Up@@ -98,7 +98,7 @@ def create(shape, chunks=True, dtype=None, compressor='default',
Example with some filters, and also storing chunks separately from metadata::

>>> from numcodecs import Quantize, Adler32
>>> store, chunk_store = dict(), dict()
>>> store, chunk_store = DictStore(), DictStore()
>>> z = zarr.create((10000, 10000), chunks=(1000, 1000), dtype='f8',
... filters=[Quantize(digits=2, dtype='f8'), Adler32()],
... store=store, chunk_store=chunk_store)
Expand All@@ -125,7 +125,7 @@ def create(shape, chunks=True, dtype=None, compressor='default',
return z


def normalize_store_arg(store, clobber=False, default=dict):
def normalize_store_arg(store, clobber=False, default=DictStore):
if store is None:
return default()
elif isinstance(store, str):
Expand Down
3 changes: 3 additions & 0 deletions zarr/hierarchy.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -91,6 +91,9 @@ class Group(MutableMapping):

def __init__(self, store, path=None, read_only=False, chunk_store=None,
cache_attrs=True, synchronizer=None):
if isinstance(store, dict):
raise TypeError("Please use Zarr's DictStore instead")

self._store = store
self._chunk_store = chunk_store
self._path = normalize_storage_path(path)
Expand Down
5 changes: 2 additions & 3 deletions zarr/storage.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -476,12 +476,11 @@ class DictStore(MutableMapping):
>>> type(g.store)
<class 'zarr.storage.DictStore'>

Note that the default class when creating an array is the built-in
:class:`dict` class, i.e.::
Also this is the default class when creating an array. E.g.::

>>> z = zarr.zeros(100)
>>> type(z.store)
<class 'dict'>
<class 'zarr.storage.DictStore'>

Notes
-----
Expand Down
62 changes: 37 additions & 25 deletions zarr/tests/test_core.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,7 +15,7 @@
import pytest


from zarr.storage import (DirectoryStore, init_array, init_group, NestedDirectoryStore,
from zarr.storage import (DictStore, DirectoryStore, init_array, init_group, NestedDirectoryStore,
DBMStore, LMDBStore, SQLiteStore, atexit_rmtree, atexit_rmglob,
LRUStoreCache)
from zarr.core import Array
Expand All@@ -41,7 +41,7 @@ class TestArray(unittest.TestCase):
def test_array_init(self):

# normal initialization
store = dict()
store = DictStore()
init_array(store, shape=100, chunks=10)
a = Array(store)
assert isinstance(a, Array)
Expand All@@ -54,7 +54,7 @@ def test_array_init(self):
assert "8fecb7a17ea1493d9c1430d04437b4f5b0b34985" == a.hexdigest()

# initialize at path
store = dict()
store = DictStore()
init_array(store, shape=100, chunks=10, path='foo/bar')
a = Array(store, path='foo/bar')
assert isinstance(a, Array)
Expand All@@ -67,18 +67,18 @@ def test_array_init(self):
assert "8fecb7a17ea1493d9c1430d04437b4f5b0b34985" == a.hexdigest()

# store not initialized
store = dict()
store = DictStore()
with pytest.raises(ValueError):
Array(store)

# group is in the way
store = dict()
store = DictStore()
init_group(store, path='baz')
with pytest.raises(ValueError):
Array(store, path='baz')

def create_array(self, read_only=False, **kwargs):
store = dict()
store = DictStore()
kwargs.setdefault('compressor', Zlib(level=1))
cache_metadata = kwargs.pop('cache_metadata', True)
cache_attrs = kwargs.pop('cache_attrs', True)
Expand DownExpand Up@@ -1255,7 +1255,7 @@ class TestArrayWithPath(TestArray):

@staticmethod
def create_array(read_only=False, **kwargs):
store = dict()
store = DictStore()
cache_metadata = kwargs.pop('cache_metadata', True)
cache_attrs = kwargs.pop('cache_attrs', True)
init_array(store, path='foo/bar', **kwargs)
Expand DownExpand Up@@ -1299,18 +1299,14 @@ def test_nbytes_stored(self):
if k.startswith('foo/bar/'))
assert expect_nbytes_stored == z.nbytes_stored

# mess with store
z.store[z._key_prefix + 'foo'] = list(range(10))
assert -1 == z.nbytes_stored


class TestArrayWithChunkStore(TestArray):

@staticmethod
def create_array(read_only=False, **kwargs):
store = dict()
store = DictStore()
# separate chunk store
chunk_store = dict()
chunk_store = DictStore()
cache_metadata = kwargs.pop('cache_metadata', True)
cache_attrs = kwargs.pop('cache_attrs', True)
init_array(store, chunk_store=chunk_store, **kwargs)
Expand DownExpand Up@@ -1353,10 +1349,6 @@ def test_nbytes_stored(self):
for v in z.chunk_store.values())
assert expect_nbytes_stored == z.nbytes_stored

# mess with store
z.chunk_store[z._key_prefix + 'foo'] = list(range(10))
assert -1 == z.nbytes_stored


class TestArrayWithDirectoryStore(TestArray):

Expand DownExpand Up@@ -1516,7 +1508,7 @@ def test_nbytes_stored(self):
class TestArrayWithNoCompressor(TestArray):

def create_array(self, read_only=False, **kwargs):
store = dict()
store = DictStore()
kwargs.setdefault('compressor', None)
cache_metadata = kwargs.pop('cache_metadata', True)
cache_attrs = kwargs.pop('cache_attrs', True)
Expand DownExpand Up@@ -1551,7 +1543,7 @@ def test_hexdigest(self):
class TestArrayWithBZ2Compressor(TestArray):

def create_array(self, read_only=False, **kwargs):
store = dict()
store = DictStore()
compressor = BZ2(level=1)
kwargs.setdefault('compressor', compressor)
cache_metadata = kwargs.pop('cache_metadata', True)
Expand DownExpand Up@@ -1587,7 +1579,7 @@ def test_hexdigest(self):
class TestArrayWithBloscCompressor(TestArray):

def create_array(self, read_only=False, **kwargs):
store = dict()
store = DictStore()
compressor = Blosc(cname='zstd', clevel=1, shuffle=1)
kwargs.setdefault('compressor', compressor)
cache_metadata = kwargs.pop('cache_metadata', True)
Expand DownExpand Up@@ -1630,7 +1622,7 @@ def test_hexdigest(self):
class TestArrayWithLZMACompressor(TestArray):

def create_array(self, read_only=False, **kwargs):
store = dict()
store = DictStore()
compressor = LZMA(preset=1)
kwargs.setdefault('compressor', compressor)
cache_metadata = kwargs.pop('cache_metadata', True)
Expand DownExpand Up@@ -1667,7 +1659,7 @@ class TestArrayWithFilters(TestArray):

@staticmethod
def create_array(read_only=False, **kwargs):
store = dict()
store = DictStore()
dtype = kwargs.get('dtype', None)
filters = [
Delta(dtype=dtype),
Expand DownExpand Up@@ -1710,7 +1702,7 @@ def test_astype_no_filters(self):
dtype = np.dtype(np.int8)
astype = np.dtype(np.float32)

store = dict()
store = DictStore()
init_array(store, shape=shape, chunks=10, dtype=dtype)

data = np.arange(np.prod(shape), dtype=dtype).reshape(shape)
Expand DownExpand Up@@ -1830,11 +1822,31 @@ def test_nbytes_stored(self):
assert -1 == z.nbytes_stored


class TestArrayWithCustomChunkStore(TestArray):

@staticmethod
def create_array(read_only=False, **kwargs):
store = CustomMapping()
kwargs["chunk_store"] = CustomMapping()
kwargs.setdefault('compressor', Zlib(1))
cache_metadata = kwargs.pop('cache_metadata', True)
cache_attrs = kwargs.pop('cache_attrs', True)
init_array(store, **kwargs)
return Array(store, read_only=read_only, cache_metadata=cache_metadata,
cache_attrs=cache_attrs)

def test_nbytes_stored(self):
z = self.create_array(shape=1000, chunks=100)
assert -1 == z.nbytes_stored
z[:] = 42
assert -1 == z.nbytes_stored


class TestArrayNoCache(TestArray):

@staticmethod
def create_array(read_only=False, **kwargs):
store = dict()
store = DictStore()
kwargs.setdefault('compressor', Zlib(level=1))
cache_metadata = kwargs.pop('cache_metadata', True)
cache_attrs = kwargs.pop('cache_attrs', True)
Expand DownExpand Up@@ -1906,7 +1918,7 @@ class TestArrayWithStoreCache(TestArray):

@staticmethod
def create_array(read_only=False, **kwargs):
store = LRUStoreCache(dict(), max_size=None)
store = LRUStoreCache(DictStore(), max_size=None)
kwargs.setdefault('compressor', Zlib(level=1))
cache_metadata = kwargs.pop('cache_metadata', True)
cache_attrs = kwargs.pop('cache_attrs', True)
Expand Down
10 changes: 5 additions & 5 deletions zarr/tests/test_hierarchy.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -41,7 +41,7 @@ class TestGroup(unittest.TestCase):
@staticmethod
def create_store():
# can be overridden in sub-classes
return dict(), None
return DictStore(), None

def create_group(self, store=None, path=None, read_only=False,
chunk_store=None, synchronizer=None):
Expand DownExpand Up@@ -948,7 +948,7 @@ class TestGroupWithChunkStore(TestGroup):

@staticmethod
def create_store():
return dict(), dict()
return DictStore(), DictStore()

def test_chunk_store(self):
# setup
Expand DownExpand Up@@ -979,7 +979,7 @@ class TestGroupWithStoreCache(TestGroup):

@staticmethod
def create_store():
store = LRUStoreCache(dict(), max_size=None)
store = LRUStoreCache(DictStore(), max_size=None)
return store, None


Expand All@@ -993,13 +993,13 @@ def test_group():
assert '/' == g.name

# usage with custom store
store = dict()
store = DictStore()
g = group(store=store)
assert isinstance(g, Group)
assert store is g.store

# overwrite behaviour
store = dict()
store = DictStore()
init_array(store, shape=100, chunks=10)
with pytest.raises(ValueError):
group(store)
Expand Down
2 changes: 1 addition & 1 deletion zarr/tests/test_info.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,7 +9,7 @@
def test_info():

# setup
g = zarr.group(store=dict(), chunk_store=dict(),
g = zarr.group(store=zarr.DictStore(), chunk_store=zarr.DictStore(),
synchronizer=zarr.ThreadSynchronizer())
g.create_group('foo')
z = g.zeros('bar', shape=10, filters=[numcodecs.Adler32()])
Expand Down
4 changes: 2 additions & 2 deletions zarr/tests/test_sync.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -19,7 +19,7 @@
from zarr.sync import ThreadSynchronizer, ProcessSynchronizer
from zarr.core import Array
from zarr.attrs import Attributes
from zarr.storage import init_array, DirectoryStore, init_group, atexit_rmtree
from zarr.storage import init_array, DictStore, DirectoryStore, init_group, atexit_rmtree
from zarr.hierarchy import Group


Expand DownExpand Up@@ -100,7 +100,7 @@ def test_parallel_append(self):
class TestArrayWithThreadSynchronizer(TestArray, MixinArraySyncTests):

def create_array(self, read_only=False, **kwargs):
store = dict()
store = DictStore()
cache_metadata = kwargs.pop('cache_metadata', True)
cache_attrs = kwargs.pop('cache_attrs', True)
init_array(store, **kwargs)
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Closed
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
8 changes: 4 additions & 4 deletions docs/tutorial.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -176,7 +176,7 @@ print some diagnostics, e.g.::
Read-only : False
Compressor : Blosc(cname='zstd', clevel=3, shuffle=BITSHUFFLE,
: blocksize=0)
Store type : builtins.dict
Store type : zarr.storage.DictStore
No. bytes : 400000000 (381.5M)
No. bytes stored : 3379344 (3.2M)
Storage ratio : 118.4
Expand DownExpand Up@@ -268,7 +268,7 @@ Here is an example using a delta filter with the Blosc compressor::
Read-only : False
Filter [0] : Delta(dtype='<i4')
Compressor : Blosc(cname='zstd', clevel=1, shuffle=SHUFFLE, blocksize=0)
Store type : builtins.dict
Store type : zarr.storage.DictStore
No. bytes : 400000000 (381.5M)
No. bytes stored : 648605 (633.4K)
Storage ratio : 616.7
Expand DownExpand Up@@ -1198,7 +1198,7 @@ ratios, depending on the correlation structure within the data. E.g.::
Order : C
Read-only : False
Compressor : Blosc(cname='lz4', clevel=5, shuffle=SHUFFLE, blocksize=0)
Store type : builtins.dict
Store type : zarr.storage.DictStore
No. bytes : 400000000 (381.5M)
No. bytes stored : 6696010 (6.4M)
Storage ratio : 59.7
Expand All@@ -1212,7 +1212,7 @@ ratios, depending on the correlation structure within the data. E.g.::
Order : F
Read-only : False
Compressor : Blosc(cname='lz4', clevel=5, shuffle=SHUFFLE, blocksize=0)
Store type : builtins.dict
Store type : zarr.storage.DictStore
No. bytes : 400000000 (381.5M)
No. bytes stored : 4684636 (4.5M)
Storage ratio : 85.4
Expand Down
13 changes: 6 additions & 7 deletions zarr/core.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -108,6 +108,9 @@ def __init__(self, store, path=None, read_only=False, chunk_store=None,
# N.B., expect at this point store is fully initialized with all
# configuration metadata fully specified and normalized

if isinstance(store, dict):
raise TypeError("Please use Zarr's DictStore instead")

self._store = store
self._chunk_store = chunk_store
self._path = normalize_storage_path(path)
Expand DownExpand Up@@ -1778,10 +1781,6 @@ def _encode_chunk(self, chunk):
else:
cdata = chunk

# ensure in-memory data is immutable and easy to compare
if isinstance(self.chunk_store, dict):
cdata = ensure_bytes(cdata)

return cdata

def __repr__(self):
Expand DownExpand Up@@ -1812,10 +1811,10 @@ def info(self):
Order : C
Read-only : False
Compressor : Blosc(cname='lz4', clevel=5, shuffle=SHUFFLE, blocksize=0)
Store type : builtins.dict
Store type : zarr.storage.DictStore
No. bytes : 4000000 (3.8M)
No. bytes stored : ...
Storage ratio : ...
No. bytes stored : 320
Storage ratio : 12500.0
Chunks initialized : 0/10

"""
Expand Down
6 changes: 3 additions & 3 deletions zarr/creation.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,7 +7,7 @@


from zarr.core import Array
from zarr.storage import (DirectoryStore, init_array, contains_array, contains_group,
from zarr.storage import (DictStore, DirectoryStore, init_array, contains_array, contains_group,
default_compressor, normalize_storage_path, ZipStore)
from numcodecs.registry import codec_registry
from zarr.errors import err_contains_array, err_contains_group, err_array_not_found
Expand DownExpand Up@@ -98,7 +98,7 @@ def create(shape, chunks=True, dtype=None, compressor='default',
Example with some filters, and also storing chunks separately from metadata::

>>> from numcodecs import Quantize, Adler32
>>> store, chunk_store = dict(), dict()
>>> store, chunk_store = DictStore(), DictStore()
>>> z = zarr.create((10000, 10000), chunks=(1000, 1000), dtype='f8',
... filters=[Quantize(digits=2, dtype='f8'), Adler32()],
... store=store, chunk_store=chunk_store)
Expand All@@ -125,7 +125,7 @@ def create(shape, chunks=True, dtype=None, compressor='default',
return z


def normalize_store_arg(store, clobber=False, default=dict):
def normalize_store_arg(store, clobber=False, default=DictStore):
if store is None:
return default()
elif isinstance(store, str):
Expand Down
3 changes: 3 additions & 0 deletions zarr/hierarchy.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -91,6 +91,9 @@ class Group(MutableMapping):

def __init__(self, store, path=None, read_only=False, chunk_store=None,
cache_attrs=True, synchronizer=None):
if isinstance(store, dict):
raise TypeError("Please use Zarr's DictStore instead")

self._store = store
self._chunk_store = chunk_store
self._path = normalize_storage_path(path)
Expand Down
5 changes: 2 additions & 3 deletions zarr/storage.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -476,12 +476,11 @@ class DictStore(MutableMapping):
>>> type(g.store)
<class 'zarr.storage.DictStore'>

Note that the default class when creating an array is the built-in
:class:`dict` class, i.e.::
Also this is the default class when creating an array. E.g.::

>>> z = zarr.zeros(100)
>>> type(z.store)
<class 'dict'>
<class 'zarr.storage.DictStore'>

Notes
-----
Expand Down
62 changes: 37 additions & 25 deletions zarr/tests/test_core.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,7 +15,7 @@
import pytest


from zarr.storage import (DirectoryStore, init_array, init_group, NestedDirectoryStore,
from zarr.storage import (DictStore, DirectoryStore, init_array, init_group, NestedDirectoryStore,
DBMStore, LMDBStore, SQLiteStore, atexit_rmtree, atexit_rmglob,
LRUStoreCache)
from zarr.core import Array
Expand All@@ -41,7 +41,7 @@ class TestArray(unittest.TestCase):
def test_array_init(self):

# normal initialization
store = dict()
store = DictStore()
init_array(store, shape=100, chunks=10)
a = Array(store)
assert isinstance(a, Array)
Expand All@@ -54,7 +54,7 @@ def test_array_init(self):
assert "8fecb7a17ea1493d9c1430d04437b4f5b0b34985" == a.hexdigest()

# initialize at path
store = dict()
store = DictStore()
init_array(store, shape=100, chunks=10, path='foo/bar')
a = Array(store, path='foo/bar')
assert isinstance(a, Array)
Expand All@@ -67,18 +67,18 @@ def test_array_init(self):
assert "8fecb7a17ea1493d9c1430d04437b4f5b0b34985" == a.hexdigest()

# store not initialized
store = dict()
store = DictStore()
with pytest.raises(ValueError):
Array(store)

# group is in the way
store = dict()
store = DictStore()
init_group(store, path='baz')
with pytest.raises(ValueError):
Array(store, path='baz')

def create_array(self, read_only=False, **kwargs):
store = dict()
store = DictStore()
kwargs.setdefault('compressor', Zlib(level=1))
cache_metadata = kwargs.pop('cache_metadata', True)
cache_attrs = kwargs.pop('cache_attrs', True)
Expand DownExpand Up@@ -1255,7 +1255,7 @@ class TestArrayWithPath(TestArray):

@staticmethod
def create_array(read_only=False, **kwargs):
store = dict()
store = DictStore()
cache_metadata = kwargs.pop('cache_metadata', True)
cache_attrs = kwargs.pop('cache_attrs', True)
init_array(store, path='foo/bar', **kwargs)
Expand DownExpand Up@@ -1299,18 +1299,14 @@ def test_nbytes_stored(self):
if k.startswith('foo/bar/'))
assert expect_nbytes_stored == z.nbytes_stored

# mess with store
z.store[z._key_prefix + 'foo'] = list(range(10))
assert -1 == z.nbytes_stored


class TestArrayWithChunkStore(TestArray):

@staticmethod
def create_array(read_only=False, **kwargs):
store = dict()
store = DictStore()
# separate chunk store
chunk_store = dict()
chunk_store = DictStore()
cache_metadata = kwargs.pop('cache_metadata', True)
cache_attrs = kwargs.pop('cache_attrs', True)
init_array(store, chunk_store=chunk_store, **kwargs)
Expand DownExpand Up@@ -1353,10 +1349,6 @@ def test_nbytes_stored(self):
for v in z.chunk_store.values())
assert expect_nbytes_stored == z.nbytes_stored

# mess with store
z.chunk_store[z._key_prefix + 'foo'] = list(range(10))
assert -1 == z.nbytes_stored


class TestArrayWithDirectoryStore(TestArray):

Expand DownExpand Up@@ -1516,7 +1508,7 @@ def test_nbytes_stored(self):
class TestArrayWithNoCompressor(TestArray):

def create_array(self, read_only=False, **kwargs):
store = dict()
store = DictStore()
kwargs.setdefault('compressor', None)
cache_metadata = kwargs.pop('cache_metadata', True)
cache_attrs = kwargs.pop('cache_attrs', True)
Expand DownExpand Up@@ -1551,7 +1543,7 @@ def test_hexdigest(self):
class TestArrayWithBZ2Compressor(TestArray):

def create_array(self, read_only=False, **kwargs):
store = dict()
store = DictStore()
compressor = BZ2(level=1)
kwargs.setdefault('compressor', compressor)
cache_metadata = kwargs.pop('cache_metadata', True)
Expand DownExpand Up@@ -1587,7 +1579,7 @@ def test_hexdigest(self):
class TestArrayWithBloscCompressor(TestArray):

def create_array(self, read_only=False, **kwargs):
store = dict()
store = DictStore()
compressor = Blosc(cname='zstd', clevel=1, shuffle=1)
kwargs.setdefault('compressor', compressor)
cache_metadata = kwargs.pop('cache_metadata', True)
Expand DownExpand Up@@ -1630,7 +1622,7 @@ def test_hexdigest(self):
class TestArrayWithLZMACompressor(TestArray):

def create_array(self, read_only=False, **kwargs):
store = dict()
store = DictStore()
compressor = LZMA(preset=1)
kwargs.setdefault('compressor', compressor)
cache_metadata = kwargs.pop('cache_metadata', True)
Expand DownExpand Up@@ -1667,7 +1659,7 @@ class TestArrayWithFilters(TestArray):

@staticmethod
def create_array(read_only=False, **kwargs):
store = dict()
store = DictStore()
dtype = kwargs.get('dtype', None)
filters = [
Delta(dtype=dtype),
Expand DownExpand Up@@ -1710,7 +1702,7 @@ def test_astype_no_filters(self):
dtype = np.dtype(np.int8)
astype = np.dtype(np.float32)

store = dict()
store = DictStore()
init_array(store, shape=shape, chunks=10, dtype=dtype)

data = np.arange(np.prod(shape), dtype=dtype).reshape(shape)
Expand DownExpand Up@@ -1830,11 +1822,31 @@ def test_nbytes_stored(self):
assert -1 == z.nbytes_stored


class TestArrayWithCustomChunkStore(TestArray):

@staticmethod
def create_array(read_only=False, **kwargs):
store = CustomMapping()
kwargs["chunk_store"] = CustomMapping()
kwargs.setdefault('compressor', Zlib(1))
cache_metadata = kwargs.pop('cache_metadata', True)
cache_attrs = kwargs.pop('cache_attrs', True)
init_array(store, **kwargs)
return Array(store, read_only=read_only, cache_metadata=cache_metadata,
cache_attrs=cache_attrs)

def test_nbytes_stored(self):
z = self.create_array(shape=1000, chunks=100)
assert -1 == z.nbytes_stored
z[:] = 42
assert -1 == z.nbytes_stored


class TestArrayNoCache(TestArray):

@staticmethod
def create_array(read_only=False, **kwargs):
store = dict()
store = DictStore()
kwargs.setdefault('compressor', Zlib(level=1))
cache_metadata = kwargs.pop('cache_metadata', True)
cache_attrs = kwargs.pop('cache_attrs', True)
Expand DownExpand Up@@ -1906,7 +1918,7 @@ class TestArrayWithStoreCache(TestArray):

@staticmethod
def create_array(read_only=False, **kwargs):
store = LRUStoreCache(dict(), max_size=None)
store = LRUStoreCache(DictStore(), max_size=None)
kwargs.setdefault('compressor', Zlib(level=1))
cache_metadata = kwargs.pop('cache_metadata', True)
cache_attrs = kwargs.pop('cache_attrs', True)
Expand Down
10 changes: 5 additions & 5 deletions zarr/tests/test_hierarchy.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -41,7 +41,7 @@ class TestGroup(unittest.TestCase):
@staticmethod
def create_store():
# can be overridden in sub-classes
return dict(), None
return DictStore(), None

def create_group(self, store=None, path=None, read_only=False,
chunk_store=None, synchronizer=None):
Expand DownExpand Up@@ -948,7 +948,7 @@ class TestGroupWithChunkStore(TestGroup):

@staticmethod
def create_store():
return dict(), dict()
return DictStore(), DictStore()

def test_chunk_store(self):
# setup
Expand DownExpand Up@@ -979,7 +979,7 @@ class TestGroupWithStoreCache(TestGroup):

@staticmethod
def create_store():
store = LRUStoreCache(dict(), max_size=None)
store = LRUStoreCache(DictStore(), max_size=None)
return store, None


Expand All@@ -993,13 +993,13 @@ def test_group():
assert '/' == g.name

# usage with custom store
store = dict()
store = DictStore()
g = group(store=store)
assert isinstance(g, Group)
assert store is g.store

# overwrite behaviour
store = dict()
store = DictStore()
init_array(store, shape=100, chunks=10)
with pytest.raises(ValueError):
group(store)
Expand Down
2 changes: 1 addition & 1 deletion zarr/tests/test_info.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,7 +9,7 @@
def test_info():

# setup
g = zarr.group(store=dict(), chunk_store=dict(),
g = zarr.group(store=zarr.DictStore(), chunk_store=zarr.DictStore(),
synchronizer=zarr.ThreadSynchronizer())
g.create_group('foo')
z = g.zeros('bar', shape=10, filters=[numcodecs.Adler32()])
Expand Down
4 changes: 2 additions & 2 deletions zarr/tests/test_sync.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -19,7 +19,7 @@
from zarr.sync import ThreadSynchronizer, ProcessSynchronizer
from zarr.core import Array
from zarr.attrs import Attributes
from zarr.storage import init_array, DirectoryStore, init_group, atexit_rmtree
from zarr.storage import init_array, DictStore, DirectoryStore, init_group, atexit_rmtree
from zarr.hierarchy import Group


Expand DownExpand Up@@ -100,7 +100,7 @@ def test_parallel_append(self):
class TestArrayWithThreadSynchronizer(TestArray, MixinArraySyncTests):

def create_array(self, read_only=False, **kwargs):
store = dict()
store = DictStore()
cache_metadata = kwargs.pop('cache_metadata', True)
cache_attrs = kwargs.pop('cache_attrs', True)
init_array(store, **kwargs)
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content
Closed
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
8 changes: 4 additions & 4 deletions docs/tutorial.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -176,7 +176,7 @@ print some diagnostics, e.g.::
Read-only : False
Compressor : Blosc(cname='zstd', clevel=3, shuffle=BITSHUFFLE,
: blocksize=0)
Store type : builtins.dict
Store type : zarr.storage.DictStore
No. bytes : 400000000 (381.5M)
No. bytes stored : 3379344 (3.2M)
Storage ratio : 118.4
Expand DownExpand Up@@ -268,7 +268,7 @@ Here is an example using a delta filter with the Blosc compressor::
Read-only : False
Filter [0] : Delta(dtype='<i4')
Compressor : Blosc(cname='zstd', clevel=1, shuffle=SHUFFLE, blocksize=0)
Store type : builtins.dict
Store type : zarr.storage.DictStore
No. bytes : 400000000 (381.5M)
No. bytes stored : 648605 (633.4K)
Storage ratio : 616.7
Expand DownExpand Up@@ -1198,7 +1198,7 @@ ratios, depending on the correlation structure within the data. E.g.::
Order : C
Read-only : False
Compressor : Blosc(cname='lz4', clevel=5, shuffle=SHUFFLE, blocksize=0)
Store type : builtins.dict
Store type : zarr.storage.DictStore
No. bytes : 400000000 (381.5M)
No. bytes stored : 6696010 (6.4M)
Storage ratio : 59.7
Expand All@@ -1212,7 +1212,7 @@ ratios, depending on the correlation structure within the data. E.g.::
Order : F
Read-only : False
Compressor : Blosc(cname='lz4', clevel=5, shuffle=SHUFFLE, blocksize=0)
Store type : builtins.dict
Store type : zarr.storage.DictStore
No. bytes : 400000000 (381.5M)
No. bytes stored : 4684636 (4.5M)
Storage ratio : 85.4
Expand Down
13 changes: 6 additions & 7 deletions zarr/core.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -108,6 +108,9 @@ def __init__(self, store, path=None, read_only=False, chunk_store=None,
# N.B., expect at this point store is fully initialized with all
# configuration metadata fully specified and normalized

if isinstance(store, dict):
raise TypeError("Please use Zarr's DictStore instead")

self._store = store
self._chunk_store = chunk_store
self._path = normalize_storage_path(path)
Expand DownExpand Up@@ -1778,10 +1781,6 @@ def _encode_chunk(self, chunk):
else:
cdata = chunk

# ensure in-memory data is immutable and easy to compare
if isinstance(self.chunk_store, dict):
cdata = ensure_bytes(cdata)

return cdata

def __repr__(self):
Expand DownExpand Up@@ -1812,10 +1811,10 @@ def info(self):
Order : C
Read-only : False
Compressor : Blosc(cname='lz4', clevel=5, shuffle=SHUFFLE, blocksize=0)
Store type : builtins.dict
Store type : zarr.storage.DictStore
No. bytes : 4000000 (3.8M)
No. bytes stored : ...
Storage ratio : ...
No. bytes stored : 320
Storage ratio : 12500.0
Chunks initialized : 0/10

"""
Expand Down
6 changes: 3 additions & 3 deletions zarr/creation.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,7 +7,7 @@


from zarr.core import Array
from zarr.storage import (DirectoryStore, init_array, contains_array, contains_group,
from zarr.storage import (DictStore, DirectoryStore, init_array, contains_array, contains_group,
default_compressor, normalize_storage_path, ZipStore)
from numcodecs.registry import codec_registry
from zarr.errors import err_contains_array, err_contains_group, err_array_not_found
Expand DownExpand Up@@ -98,7 +98,7 @@ def create(shape, chunks=True, dtype=None, compressor='default',
Example with some filters, and also storing chunks separately from metadata::

>>> from numcodecs import Quantize, Adler32
>>> store, chunk_store = dict(), dict()
>>> store, chunk_store = DictStore(), DictStore()
>>> z = zarr.create((10000, 10000), chunks=(1000, 1000), dtype='f8',
... filters=[Quantize(digits=2, dtype='f8'), Adler32()],
... store=store, chunk_store=chunk_store)
Expand All@@ -125,7 +125,7 @@ def create(shape, chunks=True, dtype=None, compressor='default',
return z


def normalize_store_arg(store, clobber=False, default=dict):
def normalize_store_arg(store, clobber=False, default=DictStore):
if store is None:
return default()
elif isinstance(store, str):
Expand Down
3 changes: 3 additions & 0 deletions zarr/hierarchy.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -91,6 +91,9 @@ class Group(MutableMapping):

def __init__(self, store, path=None, read_only=False, chunk_store=None,
cache_attrs=True, synchronizer=None):
if isinstance(store, dict):
raise TypeError("Please use Zarr's DictStore instead")

self._store = store
self._chunk_store = chunk_store
self._path = normalize_storage_path(path)
Expand Down
5 changes: 2 additions & 3 deletions zarr/storage.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -476,12 +476,11 @@ class DictStore(MutableMapping):
>>> type(g.store)
<class 'zarr.storage.DictStore'>

Note that the default class when creating an array is the built-in
:class:`dict` class, i.e.::
Also this is the default class when creating an array. E.g.::

>>> z = zarr.zeros(100)
>>> type(z.store)
<class 'dict'>
<class 'zarr.storage.DictStore'>

Notes
-----
Expand Down
62 changes: 37 additions & 25 deletions zarr/tests/test_core.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,7 +15,7 @@
import pytest


from zarr.storage import (DirectoryStore, init_array, init_group, NestedDirectoryStore,
from zarr.storage import (DictStore, DirectoryStore, init_array, init_group, NestedDirectoryStore,
DBMStore, LMDBStore, SQLiteStore, atexit_rmtree, atexit_rmglob,
LRUStoreCache)
from zarr.core import Array
Expand All@@ -41,7 +41,7 @@ class TestArray(unittest.TestCase):
def test_array_init(self):

# normal initialization
store = dict()
store = DictStore()
init_array(store, shape=100, chunks=10)
a = Array(store)
assert isinstance(a, Array)
Expand All@@ -54,7 +54,7 @@ def test_array_init(self):
assert "8fecb7a17ea1493d9c1430d04437b4f5b0b34985" == a.hexdigest()

# initialize at path
store = dict()
store = DictStore()
init_array(store, shape=100, chunks=10, path='foo/bar')
a = Array(store, path='foo/bar')
assert isinstance(a, Array)
Expand All@@ -67,18 +67,18 @@ def test_array_init(self):
assert "8fecb7a17ea1493d9c1430d04437b4f5b0b34985" == a.hexdigest()

# store not initialized
store = dict()
store = DictStore()
with pytest.raises(ValueError):
Array(store)

# group is in the way
store = dict()
store = DictStore()
init_group(store, path='baz')
with pytest.raises(ValueError):
Array(store, path='baz')

def create_array(self, read_only=False, **kwargs):
store = dict()
store = DictStore()
kwargs.setdefault('compressor', Zlib(level=1))
cache_metadata = kwargs.pop('cache_metadata', True)
cache_attrs = kwargs.pop('cache_attrs', True)
Expand DownExpand Up@@ -1255,7 +1255,7 @@ class TestArrayWithPath(TestArray):

@staticmethod
def create_array(read_only=False, **kwargs):
store = dict()
store = DictStore()
cache_metadata = kwargs.pop('cache_metadata', True)
cache_attrs = kwargs.pop('cache_attrs', True)
init_array(store, path='foo/bar', **kwargs)
Expand DownExpand Up@@ -1299,18 +1299,14 @@ def test_nbytes_stored(self):
if k.startswith('foo/bar/'))
assert expect_nbytes_stored == z.nbytes_stored

# mess with store
z.store[z._key_prefix + 'foo'] = list(range(10))
assert -1 == z.nbytes_stored


class TestArrayWithChunkStore(TestArray):

@staticmethod
def create_array(read_only=False, **kwargs):
store = dict()
store = DictStore()
# separate chunk store
chunk_store = dict()
chunk_store = DictStore()
cache_metadata = kwargs.pop('cache_metadata', True)
cache_attrs = kwargs.pop('cache_attrs', True)
init_array(store, chunk_store=chunk_store, **kwargs)
Expand DownExpand Up@@ -1353,10 +1349,6 @@ def test_nbytes_stored(self):
for v in z.chunk_store.values())
assert expect_nbytes_stored == z.nbytes_stored

# mess with store
z.chunk_store[z._key_prefix + 'foo'] = list(range(10))
assert -1 == z.nbytes_stored


class TestArrayWithDirectoryStore(TestArray):

Expand DownExpand Up@@ -1516,7 +1508,7 @@ def test_nbytes_stored(self):
class TestArrayWithNoCompressor(TestArray):

def create_array(self, read_only=False, **kwargs):
store = dict()
store = DictStore()
kwargs.setdefault('compressor', None)
cache_metadata = kwargs.pop('cache_metadata', True)
cache_attrs = kwargs.pop('cache_attrs', True)
Expand DownExpand Up@@ -1551,7 +1543,7 @@ def test_hexdigest(self):
class TestArrayWithBZ2Compressor(TestArray):

def create_array(self, read_only=False, **kwargs):
store = dict()
store = DictStore()
compressor = BZ2(level=1)
kwargs.setdefault('compressor', compressor)
cache_metadata = kwargs.pop('cache_metadata', True)
Expand DownExpand Up@@ -1587,7 +1579,7 @@ def test_hexdigest(self):
class TestArrayWithBloscCompressor(TestArray):

def create_array(self, read_only=False, **kwargs):
store = dict()
store = DictStore()
compressor = Blosc(cname='zstd', clevel=1, shuffle=1)
kwargs.setdefault('compressor', compressor)
cache_metadata = kwargs.pop('cache_metadata', True)
Expand DownExpand Up@@ -1630,7 +1622,7 @@ def test_hexdigest(self):
class TestArrayWithLZMACompressor(TestArray):

def create_array(self, read_only=False, **kwargs):
store = dict()
store = DictStore()
compressor = LZMA(preset=1)
kwargs.setdefault('compressor', compressor)
cache_metadata = kwargs.pop('cache_metadata', True)
Expand DownExpand Up@@ -1667,7 +1659,7 @@ class TestArrayWithFilters(TestArray):

@staticmethod
def create_array(read_only=False, **kwargs):
store = dict()
store = DictStore()
dtype = kwargs.get('dtype', None)
filters = [
Delta(dtype=dtype),
Expand DownExpand Up@@ -1710,7 +1702,7 @@ def test_astype_no_filters(self):
dtype = np.dtype(np.int8)
astype = np.dtype(np.float32)

store = dict()
store = DictStore()
init_array(store, shape=shape, chunks=10, dtype=dtype)

data = np.arange(np.prod(shape), dtype=dtype).reshape(shape)
Expand DownExpand Up@@ -1830,11 +1822,31 @@ def test_nbytes_stored(self):
assert -1 == z.nbytes_stored


class TestArrayWithCustomChunkStore(TestArray):

@staticmethod
def create_array(read_only=False, **kwargs):
store = CustomMapping()
kwargs["chunk_store"] = CustomMapping()
kwargs.setdefault('compressor', Zlib(1))
cache_metadata = kwargs.pop('cache_metadata', True)
cache_attrs = kwargs.pop('cache_attrs', True)
init_array(store, **kwargs)
return Array(store, read_only=read_only, cache_metadata=cache_metadata,
cache_attrs=cache_attrs)

def test_nbytes_stored(self):
z = self.create_array(shape=1000, chunks=100)
assert -1 == z.nbytes_stored
z[:] = 42
assert -1 == z.nbytes_stored


class TestArrayNoCache(TestArray):

@staticmethod
def create_array(read_only=False, **kwargs):
store = dict()
store = DictStore()
kwargs.setdefault('compressor', Zlib(level=1))
cache_metadata = kwargs.pop('cache_metadata', True)
cache_attrs = kwargs.pop('cache_attrs', True)
Expand DownExpand Up@@ -1906,7 +1918,7 @@ class TestArrayWithStoreCache(TestArray):

@staticmethod
def create_array(read_only=False, **kwargs):
store = LRUStoreCache(dict(), max_size=None)
store = LRUStoreCache(DictStore(), max_size=None)
kwargs.setdefault('compressor', Zlib(level=1))
cache_metadata = kwargs.pop('cache_metadata', True)
cache_attrs = kwargs.pop('cache_attrs', True)
Expand Down
10 changes: 5 additions & 5 deletions zarr/tests/test_hierarchy.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -41,7 +41,7 @@ class TestGroup(unittest.TestCase):
@staticmethod
def create_store():
# can be overridden in sub-classes
return dict(), None
return DictStore(), None

def create_group(self, store=None, path=None, read_only=False,
chunk_store=None, synchronizer=None):
Expand DownExpand Up@@ -948,7 +948,7 @@ class TestGroupWithChunkStore(TestGroup):

@staticmethod
def create_store():
return dict(), dict()
return DictStore(), DictStore()

def test_chunk_store(self):
# setup
Expand DownExpand Up@@ -979,7 +979,7 @@ class TestGroupWithStoreCache(TestGroup):

@staticmethod
def create_store():
store = LRUStoreCache(dict(), max_size=None)
store = LRUStoreCache(DictStore(), max_size=None)
return store, None


Expand All@@ -993,13 +993,13 @@ def test_group():
assert '/' == g.name

# usage with custom store
store = dict()
store = DictStore()
g = group(store=store)
assert isinstance(g, Group)
assert store is g.store

# overwrite behaviour
store = dict()
store = DictStore()
init_array(store, shape=100, chunks=10)
with pytest.raises(ValueError):
group(store)
Expand Down
2 changes: 1 addition & 1 deletion zarr/tests/test_info.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,7 +9,7 @@
def test_info():

# setup
g = zarr.group(store=dict(), chunk_store=dict(),
g = zarr.group(store=zarr.DictStore(), chunk_store=zarr.DictStore(),
synchronizer=zarr.ThreadSynchronizer())
g.create_group('foo')
z = g.zeros('bar', shape=10, filters=[numcodecs.Adler32()])
Expand Down
4 changes: 2 additions & 2 deletions zarr/tests/test_sync.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -19,7 +19,7 @@
from zarr.sync import ThreadSynchronizer, ProcessSynchronizer
from zarr.core import Array
from zarr.attrs import Attributes
from zarr.storage import init_array, DirectoryStore, init_group, atexit_rmtree
from zarr.storage import init_array, DictStore, DirectoryStore, init_group, atexit_rmtree
from zarr.hierarchy import Group


Expand DownExpand Up@@ -100,7 +100,7 @@ def test_parallel_append(self):
class TestArrayWithThreadSynchronizer(TestArray, MixinArraySyncTests):

def create_array(self, read_only=False, **kwargs):
store = dict()
store = DictStore()
cache_metadata = kwargs.pop('cache_metadata', True)
cache_attrs = kwargs.pop('cache_attrs', True)
init_array(store, **kwargs)
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Closed
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
8 changes: 4 additions & 4 deletions docs/tutorial.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -176,7 +176,7 @@ print some diagnostics, e.g.::
Read-only : False
Compressor : Blosc(cname='zstd', clevel=3, shuffle=BITSHUFFLE,
: blocksize=0)
Store type : builtins.dict
Store type : zarr.storage.DictStore
No. bytes : 400000000 (381.5M)
No. bytes stored : 3379344 (3.2M)
Storage ratio : 118.4
Expand DownExpand Up@@ -268,7 +268,7 @@ Here is an example using a delta filter with the Blosc compressor::
Read-only : False
Filter [0] : Delta(dtype='<i4')
Compressor : Blosc(cname='zstd', clevel=1, shuffle=SHUFFLE, blocksize=0)
Store type : builtins.dict
Store type : zarr.storage.DictStore
No. bytes : 400000000 (381.5M)
No. bytes stored : 648605 (633.4K)
Storage ratio : 616.7
Expand DownExpand Up@@ -1198,7 +1198,7 @@ ratios, depending on the correlation structure within the data. E.g.::
Order : C
Read-only : False
Compressor : Blosc(cname='lz4', clevel=5, shuffle=SHUFFLE, blocksize=0)
Store type : builtins.dict
Store type : zarr.storage.DictStore
No. bytes : 400000000 (381.5M)
No. bytes stored : 6696010 (6.4M)
Storage ratio : 59.7
Expand All@@ -1212,7 +1212,7 @@ ratios, depending on the correlation structure within the data. E.g.::
Order : F
Read-only : False
Compressor : Blosc(cname='lz4', clevel=5, shuffle=SHUFFLE, blocksize=0)
Store type : builtins.dict
Store type : zarr.storage.DictStore
No. bytes : 400000000 (381.5M)
No. bytes stored : 4684636 (4.5M)
Storage ratio : 85.4
Expand Down
13 changes: 6 additions & 7 deletions zarr/core.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -108,6 +108,9 @@ def __init__(self, store, path=None, read_only=False, chunk_store=None,
# N.B., expect at this point store is fully initialized with all
# configuration metadata fully specified and normalized

if isinstance(store, dict):
raise TypeError("Please use Zarr's DictStore instead")

self._store = store
self._chunk_store = chunk_store
self._path = normalize_storage_path(path)
Expand DownExpand Up@@ -1778,10 +1781,6 @@ def _encode_chunk(self, chunk):
else:
cdata = chunk

# ensure in-memory data is immutable and easy to compare
if isinstance(self.chunk_store, dict):
cdata = ensure_bytes(cdata)

return cdata

def __repr__(self):
Expand DownExpand Up@@ -1812,10 +1811,10 @@ def info(self):
Order : C
Read-only : False
Compressor : Blosc(cname='lz4', clevel=5, shuffle=SHUFFLE, blocksize=0)
Store type : builtins.dict
Store type : zarr.storage.DictStore
No. bytes : 4000000 (3.8M)
No. bytes stored : ...
Storage ratio : ...
No. bytes stored : 320
Storage ratio : 12500.0
Chunks initialized : 0/10

"""
Expand Down
6 changes: 3 additions & 3 deletions zarr/creation.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,7 +7,7 @@


from zarr.core import Array
from zarr.storage import (DirectoryStore, init_array, contains_array, contains_group,
from zarr.storage import (DictStore, DirectoryStore, init_array, contains_array, contains_group,
default_compressor, normalize_storage_path, ZipStore)
from numcodecs.registry import codec_registry
from zarr.errors import err_contains_array, err_contains_group, err_array_not_found
Expand DownExpand Up@@ -98,7 +98,7 @@ def create(shape, chunks=True, dtype=None, compressor='default',
Example with some filters, and also storing chunks separately from metadata::

>>> from numcodecs import Quantize, Adler32
>>> store, chunk_store = dict(), dict()
>>> store, chunk_store = DictStore(), DictStore()
>>> z = zarr.create((10000, 10000), chunks=(1000, 1000), dtype='f8',
... filters=[Quantize(digits=2, dtype='f8'), Adler32()],
... store=store, chunk_store=chunk_store)
Expand All@@ -125,7 +125,7 @@ def create(shape, chunks=True, dtype=None, compressor='default',
return z


def normalize_store_arg(store, clobber=False, default=dict):
def normalize_store_arg(store, clobber=False, default=DictStore):
if store is None:
return default()
elif isinstance(store, str):
Expand Down
3 changes: 3 additions & 0 deletions zarr/hierarchy.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -91,6 +91,9 @@ class Group(MutableMapping):

def __init__(self, store, path=None, read_only=False, chunk_store=None,
cache_attrs=True, synchronizer=None):
if isinstance(store, dict):
raise TypeError("Please use Zarr's DictStore instead")

self._store = store
self._chunk_store = chunk_store
self._path = normalize_storage_path(path)
Expand Down
5 changes: 2 additions & 3 deletions zarr/storage.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -476,12 +476,11 @@ class DictStore(MutableMapping):
>>> type(g.store)
<class 'zarr.storage.DictStore'>

Note that the default class when creating an array is the built-in
:class:`dict` class, i.e.::
Also this is the default class when creating an array. E.g.::

>>> z = zarr.zeros(100)
>>> type(z.store)
<class 'dict'>
<class 'zarr.storage.DictStore'>

Notes
-----
Expand Down
62 changes: 37 additions & 25 deletions zarr/tests/test_core.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,7 +15,7 @@
import pytest


from zarr.storage import (DirectoryStore, init_array, init_group, NestedDirectoryStore,
from zarr.storage import (DictStore, DirectoryStore, init_array, init_group, NestedDirectoryStore,
DBMStore, LMDBStore, SQLiteStore, atexit_rmtree, atexit_rmglob,
LRUStoreCache)
from zarr.core import Array
Expand All@@ -41,7 +41,7 @@ class TestArray(unittest.TestCase):
def test_array_init(self):

# normal initialization
store = dict()
store = DictStore()
init_array(store, shape=100, chunks=10)
a = Array(store)
assert isinstance(a, Array)
Expand All@@ -54,7 +54,7 @@ def test_array_init(self):
assert "8fecb7a17ea1493d9c1430d04437b4f5b0b34985" == a.hexdigest()

# initialize at path
store = dict()
store = DictStore()
init_array(store, shape=100, chunks=10, path='foo/bar')
a = Array(store, path='foo/bar')
assert isinstance(a, Array)
Expand All@@ -67,18 +67,18 @@ def test_array_init(self):
assert "8fecb7a17ea1493d9c1430d04437b4f5b0b34985" == a.hexdigest()

# store not initialized
store = dict()
store = DictStore()
with pytest.raises(ValueError):
Array(store)

# group is in the way
store = dict()
store = DictStore()
init_group(store, path='baz')
with pytest.raises(ValueError):
Array(store, path='baz')

def create_array(self, read_only=False, **kwargs):
store = dict()
store = DictStore()
kwargs.setdefault('compressor', Zlib(level=1))
cache_metadata = kwargs.pop('cache_metadata', True)
cache_attrs = kwargs.pop('cache_attrs', True)
Expand DownExpand Up@@ -1255,7 +1255,7 @@ class TestArrayWithPath(TestArray):

@staticmethod
def create_array(read_only=False, **kwargs):
store = dict()
store = DictStore()
cache_metadata = kwargs.pop('cache_metadata', True)
cache_attrs = kwargs.pop('cache_attrs', True)
init_array(store, path='foo/bar', **kwargs)
Expand DownExpand Up@@ -1299,18 +1299,14 @@ def test_nbytes_stored(self):
if k.startswith('foo/bar/'))
assert expect_nbytes_stored == z.nbytes_stored

# mess with store
z.store[z._key_prefix + 'foo'] = list(range(10))
assert -1 == z.nbytes_stored


class TestArrayWithChunkStore(TestArray):

@staticmethod
def create_array(read_only=False, **kwargs):
store = dict()
store = DictStore()
# separate chunk store
chunk_store = dict()
chunk_store = DictStore()
cache_metadata = kwargs.pop('cache_metadata', True)
cache_attrs = kwargs.pop('cache_attrs', True)
init_array(store, chunk_store=chunk_store, **kwargs)
Expand DownExpand Up@@ -1353,10 +1349,6 @@ def test_nbytes_stored(self):
for v in z.chunk_store.values())
assert expect_nbytes_stored == z.nbytes_stored

# mess with store
z.chunk_store[z._key_prefix + 'foo'] = list(range(10))
assert -1 == z.nbytes_stored


class TestArrayWithDirectoryStore(TestArray):

Expand DownExpand Up@@ -1516,7 +1508,7 @@ def test_nbytes_stored(self):
class TestArrayWithNoCompressor(TestArray):

def create_array(self, read_only=False, **kwargs):
store = dict()
store = DictStore()
kwargs.setdefault('compressor', None)
cache_metadata = kwargs.pop('cache_metadata', True)
cache_attrs = kwargs.pop('cache_attrs', True)
Expand DownExpand Up@@ -1551,7 +1543,7 @@ def test_hexdigest(self):
class TestArrayWithBZ2Compressor(TestArray):

def create_array(self, read_only=False, **kwargs):
store = dict()
store = DictStore()
compressor = BZ2(level=1)
kwargs.setdefault('compressor', compressor)
cache_metadata = kwargs.pop('cache_metadata', True)
Expand DownExpand Up@@ -1587,7 +1579,7 @@ def test_hexdigest(self):
class TestArrayWithBloscCompressor(TestArray):

def create_array(self, read_only=False, **kwargs):
store = dict()
store = DictStore()
compressor = Blosc(cname='zstd', clevel=1, shuffle=1)
kwargs.setdefault('compressor', compressor)
cache_metadata = kwargs.pop('cache_metadata', True)
Expand DownExpand Up@@ -1630,7 +1622,7 @@ def test_hexdigest(self):
class TestArrayWithLZMACompressor(TestArray):

def create_array(self, read_only=False, **kwargs):
store = dict()
store = DictStore()
compressor = LZMA(preset=1)
kwargs.setdefault('compressor', compressor)
cache_metadata = kwargs.pop('cache_metadata', True)
Expand DownExpand Up@@ -1667,7 +1659,7 @@ class TestArrayWithFilters(TestArray):

@staticmethod
def create_array(read_only=False, **kwargs):
store = dict()
store = DictStore()
dtype = kwargs.get('dtype', None)
filters = [
Delta(dtype=dtype),
Expand DownExpand Up@@ -1710,7 +1702,7 @@ def test_astype_no_filters(self):
dtype = np.dtype(np.int8)
astype = np.dtype(np.float32)

store = dict()
store = DictStore()
init_array(store, shape=shape, chunks=10, dtype=dtype)

data = np.arange(np.prod(shape), dtype=dtype).reshape(shape)
Expand DownExpand Up@@ -1830,11 +1822,31 @@ def test_nbytes_stored(self):
assert -1 == z.nbytes_stored


class TestArrayWithCustomChunkStore(TestArray):

@staticmethod
def create_array(read_only=False, **kwargs):
store = CustomMapping()
kwargs["chunk_store"] = CustomMapping()
kwargs.setdefault('compressor', Zlib(1))
cache_metadata = kwargs.pop('cache_metadata', True)
cache_attrs = kwargs.pop('cache_attrs', True)
init_array(store, **kwargs)
return Array(store, read_only=read_only, cache_metadata=cache_metadata,
cache_attrs=cache_attrs)

def test_nbytes_stored(self):
z = self.create_array(shape=1000, chunks=100)
assert -1 == z.nbytes_stored
z[:] = 42
assert -1 == z.nbytes_stored


class TestArrayNoCache(TestArray):

@staticmethod
def create_array(read_only=False, **kwargs):
store = dict()
store = DictStore()
kwargs.setdefault('compressor', Zlib(level=1))
cache_metadata = kwargs.pop('cache_metadata', True)
cache_attrs = kwargs.pop('cache_attrs', True)
Expand DownExpand Up@@ -1906,7 +1918,7 @@ class TestArrayWithStoreCache(TestArray):

@staticmethod
def create_array(read_only=False, **kwargs):
store = LRUStoreCache(dict(), max_size=None)
store = LRUStoreCache(DictStore(), max_size=None)
kwargs.setdefault('compressor', Zlib(level=1))
cache_metadata = kwargs.pop('cache_metadata', True)
cache_attrs = kwargs.pop('cache_attrs', True)
Expand Down
10 changes: 5 additions & 5 deletions zarr/tests/test_hierarchy.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -41,7 +41,7 @@ class TestGroup(unittest.TestCase):
@staticmethod
def create_store():
# can be overridden in sub-classes
return dict(), None
return DictStore(), None

def create_group(self, store=None, path=None, read_only=False,
chunk_store=None, synchronizer=None):
Expand DownExpand Up@@ -948,7 +948,7 @@ class TestGroupWithChunkStore(TestGroup):

@staticmethod
def create_store():
return dict(), dict()
return DictStore(), DictStore()

def test_chunk_store(self):
# setup
Expand DownExpand Up@@ -979,7 +979,7 @@ class TestGroupWithStoreCache(TestGroup):

@staticmethod
def create_store():
store = LRUStoreCache(dict(), max_size=None)
store = LRUStoreCache(DictStore(), max_size=None)
return store, None


Expand All@@ -993,13 +993,13 @@ def test_group():
assert '/' == g.name

# usage with custom store
store = dict()
store = DictStore()
g = group(store=store)
assert isinstance(g, Group)
assert store is g.store

# overwrite behaviour
store = dict()
store = DictStore()
init_array(store, shape=100, chunks=10)
with pytest.raises(ValueError):
group(store)
Expand Down
2 changes: 1 addition & 1 deletion zarr/tests/test_info.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,7 +9,7 @@
def test_info():

# setup
g = zarr.group(store=dict(), chunk_store=dict(),
g = zarr.group(store=zarr.DictStore(), chunk_store=zarr.DictStore(),
synchronizer=zarr.ThreadSynchronizer())
g.create_group('foo')
z = g.zeros('bar', shape=10, filters=[numcodecs.Adler32()])
Expand Down
4 changes: 2 additions & 2 deletions zarr/tests/test_sync.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -19,7 +19,7 @@
from zarr.sync import ThreadSynchronizer, ProcessSynchronizer
from zarr.core import Array
from zarr.attrs import Attributes
from zarr.storage import init_array, DirectoryStore, init_group, atexit_rmtree
from zarr.storage import init_array, DictStore, DirectoryStore, init_group, atexit_rmtree
from zarr.hierarchy import Group


Expand DownExpand Up@@ -100,7 +100,7 @@ def test_parallel_append(self):
class TestArrayWithThreadSynchronizer(TestArray, MixinArraySyncTests):

def create_array(self, read_only=False, **kwargs):
store = dict()
store = DictStore()
cache_metadata = kwargs.pop('cache_metadata', True)
cache_attrs = kwargs.pop('cache_attrs', True)
init_array(store, **kwargs)
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Closed
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
8 changes: 4 additions & 4 deletions docs/tutorial.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -176,7 +176,7 @@ print some diagnostics, e.g.::
Read-only : False
Compressor : Blosc(cname='zstd', clevel=3, shuffle=BITSHUFFLE,
: blocksize=0)
Store type : builtins.dict
Store type : zarr.storage.DictStore
No. bytes : 400000000 (381.5M)
No. bytes stored : 3379344 (3.2M)
Storage ratio : 118.4
Expand DownExpand Up@@ -268,7 +268,7 @@ Here is an example using a delta filter with the Blosc compressor::
Read-only : False
Filter [0] : Delta(dtype='<i4')
Compressor : Blosc(cname='zstd', clevel=1, shuffle=SHUFFLE, blocksize=0)
Store type : builtins.dict
Store type : zarr.storage.DictStore
No. bytes : 400000000 (381.5M)
No. bytes stored : 648605 (633.4K)
Storage ratio : 616.7
Expand DownExpand Up@@ -1198,7 +1198,7 @@ ratios, depending on the correlation structure within the data. E.g.::
Order : C
Read-only : False
Compressor : Blosc(cname='lz4', clevel=5, shuffle=SHUFFLE, blocksize=0)
Store type : builtins.dict
Store type : zarr.storage.DictStore
No. bytes : 400000000 (381.5M)
No. bytes stored : 6696010 (6.4M)
Storage ratio : 59.7
Expand All@@ -1212,7 +1212,7 @@ ratios, depending on the correlation structure within the data. E.g.::
Order : F
Read-only : False
Compressor : Blosc(cname='lz4', clevel=5, shuffle=SHUFFLE, blocksize=0)
Store type : builtins.dict
Store type : zarr.storage.DictStore
No. bytes : 400000000 (381.5M)
No. bytes stored : 4684636 (4.5M)
Storage ratio : 85.4
Expand Down
13 changes: 6 additions & 7 deletions zarr/core.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -108,6 +108,9 @@ def __init__(self, store, path=None, read_only=False, chunk_store=None,
# N.B., expect at this point store is fully initialized with all
# configuration metadata fully specified and normalized

if isinstance(store, dict):
raise TypeError("Please use Zarr's DictStore instead")

self._store = store
self._chunk_store = chunk_store
self._path = normalize_storage_path(path)
Expand DownExpand Up@@ -1778,10 +1781,6 @@ def _encode_chunk(self, chunk):
else:
cdata = chunk

# ensure in-memory data is immutable and easy to compare
if isinstance(self.chunk_store, dict):
cdata = ensure_bytes(cdata)

return cdata

def __repr__(self):
Expand DownExpand Up@@ -1812,10 +1811,10 @@ def info(self):
Order : C
Read-only : False
Compressor : Blosc(cname='lz4', clevel=5, shuffle=SHUFFLE, blocksize=0)
Store type : builtins.dict
Store type : zarr.storage.DictStore
No. bytes : 4000000 (3.8M)
No. bytes stored : ...
Storage ratio : ...
No. bytes stored : 320
Storage ratio : 12500.0
Chunks initialized : 0/10

"""
Expand Down
6 changes: 3 additions & 3 deletions zarr/creation.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,7 +7,7 @@


from zarr.core import Array
from zarr.storage import (DirectoryStore, init_array, contains_array, contains_group,
from zarr.storage import (DictStore, DirectoryStore, init_array, contains_array, contains_group,
default_compressor, normalize_storage_path, ZipStore)
from numcodecs.registry import codec_registry
from zarr.errors import err_contains_array, err_contains_group, err_array_not_found
Expand DownExpand Up@@ -98,7 +98,7 @@ def create(shape, chunks=True, dtype=None, compressor='default',
Example with some filters, and also storing chunks separately from metadata::

>>> from numcodecs import Quantize, Adler32
>>> store, chunk_store = dict(), dict()
>>> store, chunk_store = DictStore(), DictStore()
>>> z = zarr.create((10000, 10000), chunks=(1000, 1000), dtype='f8',
... filters=[Quantize(digits=2, dtype='f8'), Adler32()],
... store=store, chunk_store=chunk_store)
Expand All@@ -125,7 +125,7 @@ def create(shape, chunks=True, dtype=None, compressor='default',
return z


def normalize_store_arg(store, clobber=False, default=dict):
def normalize_store_arg(store, clobber=False, default=DictStore):
if store is None:
return default()
elif isinstance(store, str):
Expand Down
3 changes: 3 additions & 0 deletions zarr/hierarchy.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -91,6 +91,9 @@ class Group(MutableMapping):

def __init__(self, store, path=None, read_only=False, chunk_store=None,
cache_attrs=True, synchronizer=None):
if isinstance(store, dict):
raise TypeError("Please use Zarr's DictStore instead")

self._store = store
self._chunk_store = chunk_store
self._path = normalize_storage_path(path)
Expand Down
5 changes: 2 additions & 3 deletions zarr/storage.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -476,12 +476,11 @@ class DictStore(MutableMapping):
>>> type(g.store)
<class 'zarr.storage.DictStore'>

Note that the default class when creating an array is the built-in
:class:`dict` class, i.e.::
Also this is the default class when creating an array. E.g.::

>>> z = zarr.zeros(100)
>>> type(z.store)
<class 'dict'>
<class 'zarr.storage.DictStore'>

Notes
-----
Expand Down
62 changes: 37 additions & 25 deletions zarr/tests/test_core.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,7 +15,7 @@
import pytest


from zarr.storage import (DirectoryStore, init_array, init_group, NestedDirectoryStore,
from zarr.storage import (DictStore, DirectoryStore, init_array, init_group, NestedDirectoryStore,
DBMStore, LMDBStore, SQLiteStore, atexit_rmtree, atexit_rmglob,
LRUStoreCache)
from zarr.core import Array
Expand All@@ -41,7 +41,7 @@ class TestArray(unittest.TestCase):
def test_array_init(self):

# normal initialization
store = dict()
store = DictStore()
init_array(store, shape=100, chunks=10)
a = Array(store)
assert isinstance(a, Array)
Expand All@@ -54,7 +54,7 @@ def test_array_init(self):
assert "8fecb7a17ea1493d9c1430d04437b4f5b0b34985" == a.hexdigest()

# initialize at path
store = dict()
store = DictStore()
init_array(store, shape=100, chunks=10, path='foo/bar')
a = Array(store, path='foo/bar')
assert isinstance(a, Array)
Expand All@@ -67,18 +67,18 @@ def test_array_init(self):
assert "8fecb7a17ea1493d9c1430d04437b4f5b0b34985" == a.hexdigest()

# store not initialized
store = dict()
store = DictStore()
with pytest.raises(ValueError):
Array(store)

# group is in the way
store = dict()
store = DictStore()
init_group(store, path='baz')
with pytest.raises(ValueError):
Array(store, path='baz')

def create_array(self, read_only=False, **kwargs):
store = dict()
store = DictStore()
kwargs.setdefault('compressor', Zlib(level=1))
cache_metadata = kwargs.pop('cache_metadata', True)
cache_attrs = kwargs.pop('cache_attrs', True)
Expand DownExpand Up@@ -1255,7 +1255,7 @@ class TestArrayWithPath(TestArray):

@staticmethod
def create_array(read_only=False, **kwargs):
store = dict()
store = DictStore()
cache_metadata = kwargs.pop('cache_metadata', True)
cache_attrs = kwargs.pop('cache_attrs', True)
init_array(store, path='foo/bar', **kwargs)
Expand DownExpand Up@@ -1299,18 +1299,14 @@ def test_nbytes_stored(self):
if k.startswith('foo/bar/'))
assert expect_nbytes_stored == z.nbytes_stored

# mess with store
z.store[z._key_prefix + 'foo'] = list(range(10))
assert -1 == z.nbytes_stored


class TestArrayWithChunkStore(TestArray):

@staticmethod
def create_array(read_only=False, **kwargs):
store = dict()
store = DictStore()
# separate chunk store
chunk_store = dict()
chunk_store = DictStore()
cache_metadata = kwargs.pop('cache_metadata', True)
cache_attrs = kwargs.pop('cache_attrs', True)
init_array(store, chunk_store=chunk_store, **kwargs)
Expand DownExpand Up@@ -1353,10 +1349,6 @@ def test_nbytes_stored(self):
for v in z.chunk_store.values())
assert expect_nbytes_stored == z.nbytes_stored

# mess with store
z.chunk_store[z._key_prefix + 'foo'] = list(range(10))
assert -1 == z.nbytes_stored


class TestArrayWithDirectoryStore(TestArray):

Expand DownExpand Up@@ -1516,7 +1508,7 @@ def test_nbytes_stored(self):
class TestArrayWithNoCompressor(TestArray):

def create_array(self, read_only=False, **kwargs):
store = dict()
store = DictStore()
kwargs.setdefault('compressor', None)
cache_metadata = kwargs.pop('cache_metadata', True)
cache_attrs = kwargs.pop('cache_attrs', True)
Expand DownExpand Up@@ -1551,7 +1543,7 @@ def test_hexdigest(self):
class TestArrayWithBZ2Compressor(TestArray):

def create_array(self, read_only=False, **kwargs):
store = dict()
store = DictStore()
compressor = BZ2(level=1)
kwargs.setdefault('compressor', compressor)
cache_metadata = kwargs.pop('cache_metadata', True)
Expand DownExpand Up@@ -1587,7 +1579,7 @@ def test_hexdigest(self):
class TestArrayWithBloscCompressor(TestArray):

def create_array(self, read_only=False, **kwargs):
store = dict()
store = DictStore()
compressor = Blosc(cname='zstd', clevel=1, shuffle=1)
kwargs.setdefault('compressor', compressor)
cache_metadata = kwargs.pop('cache_metadata', True)
Expand DownExpand Up@@ -1630,7 +1622,7 @@ def test_hexdigest(self):
class TestArrayWithLZMACompressor(TestArray):

def create_array(self, read_only=False, **kwargs):
store = dict()
store = DictStore()
compressor = LZMA(preset=1)
kwargs.setdefault('compressor', compressor)
cache_metadata = kwargs.pop('cache_metadata', True)
Expand DownExpand Up@@ -1667,7 +1659,7 @@ class TestArrayWithFilters(TestArray):

@staticmethod
def create_array(read_only=False, **kwargs):
store = dict()
store = DictStore()
dtype = kwargs.get('dtype', None)
filters = [
Delta(dtype=dtype),
Expand DownExpand Up@@ -1710,7 +1702,7 @@ def test_astype_no_filters(self):
dtype = np.dtype(np.int8)
astype = np.dtype(np.float32)

store = dict()
store = DictStore()
init_array(store, shape=shape, chunks=10, dtype=dtype)

data = np.arange(np.prod(shape), dtype=dtype).reshape(shape)
Expand DownExpand Up@@ -1830,11 +1822,31 @@ def test_nbytes_stored(self):
assert -1 == z.nbytes_stored


class TestArrayWithCustomChunkStore(TestArray):

@staticmethod
def create_array(read_only=False, **kwargs):
store = CustomMapping()
kwargs["chunk_store"] = CustomMapping()
kwargs.setdefault('compressor', Zlib(1))
cache_metadata = kwargs.pop('cache_metadata', True)
cache_attrs = kwargs.pop('cache_attrs', True)
init_array(store, **kwargs)
return Array(store, read_only=read_only, cache_metadata=cache_metadata,
cache_attrs=cache_attrs)

def test_nbytes_stored(self):
z = self.create_array(shape=1000, chunks=100)
assert -1 == z.nbytes_stored
z[:] = 42
assert -1 == z.nbytes_stored


class TestArrayNoCache(TestArray):

@staticmethod
def create_array(read_only=False, **kwargs):
store = dict()
store = DictStore()
kwargs.setdefault('compressor', Zlib(level=1))
cache_metadata = kwargs.pop('cache_metadata', True)
cache_attrs = kwargs.pop('cache_attrs', True)
Expand DownExpand Up@@ -1906,7 +1918,7 @@ class TestArrayWithStoreCache(TestArray):

@staticmethod
def create_array(read_only=False, **kwargs):
store = LRUStoreCache(dict(), max_size=None)
store = LRUStoreCache(DictStore(), max_size=None)
kwargs.setdefault('compressor', Zlib(level=1))
cache_metadata = kwargs.pop('cache_metadata', True)
cache_attrs = kwargs.pop('cache_attrs', True)
Expand Down
10 changes: 5 additions & 5 deletions zarr/tests/test_hierarchy.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -41,7 +41,7 @@ class TestGroup(unittest.TestCase):
@staticmethod
def create_store():
# can be overridden in sub-classes
return dict(), None
return DictStore(), None

def create_group(self, store=None, path=None, read_only=False,
chunk_store=None, synchronizer=None):
Expand DownExpand Up@@ -948,7 +948,7 @@ class TestGroupWithChunkStore(TestGroup):

@staticmethod
def create_store():
return dict(), dict()
return DictStore(), DictStore()

def test_chunk_store(self):
# setup
Expand DownExpand Up@@ -979,7 +979,7 @@ class TestGroupWithStoreCache(TestGroup):

@staticmethod
def create_store():
store = LRUStoreCache(dict(), max_size=None)
store = LRUStoreCache(DictStore(), max_size=None)
return store, None


Expand All@@ -993,13 +993,13 @@ def test_group():
assert '/' == g.name

# usage with custom store
store = dict()
store = DictStore()
g = group(store=store)
assert isinstance(g, Group)
assert store is g.store

# overwrite behaviour
store = dict()
store = DictStore()
init_array(store, shape=100, chunks=10)
with pytest.raises(ValueError):
group(store)
Expand Down
2 changes: 1 addition & 1 deletion zarr/tests/test_info.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,7 +9,7 @@
def test_info():

# setup
g = zarr.group(store=dict(), chunk_store=dict(),
g = zarr.group(store=zarr.DictStore(), chunk_store=zarr.DictStore(),
synchronizer=zarr.ThreadSynchronizer())
g.create_group('foo')
z = g.zeros('bar', shape=10, filters=[numcodecs.Adler32()])
Expand Down
4 changes: 2 additions & 2 deletions zarr/tests/test_sync.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -19,7 +19,7 @@
from zarr.sync import ThreadSynchronizer, ProcessSynchronizer
from zarr.core import Array
from zarr.attrs import Attributes
from zarr.storage import init_array, DirectoryStore, init_group, atexit_rmtree
from zarr.storage import init_array, DictStore, DirectoryStore, init_group, atexit_rmtree
from zarr.hierarchy import Group


Expand DownExpand Up@@ -100,7 +100,7 @@ def test_parallel_append(self):
class TestArrayWithThreadSynchronizer(TestArray, MixinArraySyncTests):

def create_array(self, read_only=False, **kwargs):
store = dict()
store = DictStore()
cache_metadata = kwargs.pop('cache_metadata', True)
cache_attrs = kwargs.pop('cache_attrs', True)
init_array(store, **kwargs)
Expand Down
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content
Closed
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
8 changes: 4 additions & 4 deletions docs/tutorial.rst
Original file line numberDiff line numberDiff line change
Expand Up@@ -176,7 +176,7 @@ print some diagnostics, e.g.::
Read-only : False
Compressor : Blosc(cname='zstd', clevel=3, shuffle=BITSHUFFLE,
: blocksize=0)
Store type : builtins.dict
Store type : zarr.storage.DictStore
No. bytes : 400000000 (381.5M)
No. bytes stored : 3379344 (3.2M)
Storage ratio : 118.4
Expand DownExpand Up@@ -268,7 +268,7 @@ Here is an example using a delta filter with the Blosc compressor::
Read-only : False
Filter [0] : Delta(dtype='<i4')
Compressor : Blosc(cname='zstd', clevel=1, shuffle=SHUFFLE, blocksize=0)
Store type : builtins.dict
Store type : zarr.storage.DictStore
No. bytes : 400000000 (381.5M)
No. bytes stored : 648605 (633.4K)
Storage ratio : 616.7
Expand DownExpand Up@@ -1198,7 +1198,7 @@ ratios, depending on the correlation structure within the data. E.g.::
Order : C
Read-only : False
Compressor : Blosc(cname='lz4', clevel=5, shuffle=SHUFFLE, blocksize=0)
Store type : builtins.dict
Store type : zarr.storage.DictStore
No. bytes : 400000000 (381.5M)
No. bytes stored : 6696010 (6.4M)
Storage ratio : 59.7
Expand All@@ -1212,7 +1212,7 @@ ratios, depending on the correlation structure within the data. E.g.::
Order : F
Read-only : False
Compressor : Blosc(cname='lz4', clevel=5, shuffle=SHUFFLE, blocksize=0)
Store type : builtins.dict
Store type : zarr.storage.DictStore
No. bytes : 400000000 (381.5M)
No. bytes stored : 4684636 (4.5M)
Storage ratio : 85.4
Expand Down
13 changes: 6 additions & 7 deletions zarr/core.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -108,6 +108,9 @@ def __init__(self, store, path=None, read_only=False, chunk_store=None,
# N.B., expect at this point store is fully initialized with all
# configuration metadata fully specified and normalized

if isinstance(store, dict):
raise TypeError("Please use Zarr's DictStore instead")

self._store = store
self._chunk_store = chunk_store
self._path = normalize_storage_path(path)
Expand DownExpand Up@@ -1778,10 +1781,6 @@ def _encode_chunk(self, chunk):
else:
cdata = chunk

# ensure in-memory data is immutable and easy to compare
if isinstance(self.chunk_store, dict):
cdata = ensure_bytes(cdata)

return cdata

def __repr__(self):
Expand DownExpand Up@@ -1812,10 +1811,10 @@ def info(self):
Order : C
Read-only : False
Compressor : Blosc(cname='lz4', clevel=5, shuffle=SHUFFLE, blocksize=0)
Store type : builtins.dict
Store type : zarr.storage.DictStore
No. bytes : 4000000 (3.8M)
No. bytes stored : ...
Storage ratio : ...
No. bytes stored : 320
Storage ratio : 12500.0
Chunks initialized : 0/10

"""
Expand Down
6 changes: 3 additions & 3 deletions zarr/creation.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,7 +7,7 @@


from zarr.core import Array
from zarr.storage import (DirectoryStore, init_array, contains_array, contains_group,
from zarr.storage import (DictStore, DirectoryStore, init_array, contains_array, contains_group,
default_compressor, normalize_storage_path, ZipStore)
from numcodecs.registry import codec_registry
from zarr.errors import err_contains_array, err_contains_group, err_array_not_found
Expand DownExpand Up@@ -98,7 +98,7 @@ def create(shape, chunks=True, dtype=None, compressor='default',
Example with some filters, and also storing chunks separately from metadata::

>>> from numcodecs import Quantize, Adler32
>>> store, chunk_store = dict(), dict()
>>> store, chunk_store = DictStore(), DictStore()
>>> z = zarr.create((10000, 10000), chunks=(1000, 1000), dtype='f8',
... filters=[Quantize(digits=2, dtype='f8'), Adler32()],
... store=store, chunk_store=chunk_store)
Expand All@@ -125,7 +125,7 @@ def create(shape, chunks=True, dtype=None, compressor='default',
return z


def normalize_store_arg(store, clobber=False, default=dict):
def normalize_store_arg(store, clobber=False, default=DictStore):
if store is None:
return default()
elif isinstance(store, str):
Expand Down
3 changes: 3 additions & 0 deletions zarr/hierarchy.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -91,6 +91,9 @@ class Group(MutableMapping):

def __init__(self, store, path=None, read_only=False, chunk_store=None,
cache_attrs=True, synchronizer=None):
if isinstance(store, dict):
raise TypeError("Please use Zarr's DictStore instead")

self._store = store
self._chunk_store = chunk_store
self._path = normalize_storage_path(path)
Expand Down
5 changes: 2 additions & 3 deletions zarr/storage.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -476,12 +476,11 @@ class DictStore(MutableMapping):
>>> type(g.store)
<class 'zarr.storage.DictStore'>

Note that the default class when creating an array is the built-in
:class:`dict` class, i.e.::
Also this is the default class when creating an array. E.g.::

>>> z = zarr.zeros(100)
>>> type(z.store)
<class 'dict'>
<class 'zarr.storage.DictStore'>

Notes
-----
Expand Down
62 changes: 37 additions & 25 deletions zarr/tests/test_core.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,7 +15,7 @@
import pytest


from zarr.storage import (DirectoryStore, init_array, init_group, NestedDirectoryStore,
from zarr.storage import (DictStore, DirectoryStore, init_array, init_group, NestedDirectoryStore,
DBMStore, LMDBStore, SQLiteStore, atexit_rmtree, atexit_rmglob,
LRUStoreCache)
from zarr.core import Array
Expand All@@ -41,7 +41,7 @@ class TestArray(unittest.TestCase):
def test_array_init(self):

# normal initialization
store = dict()
store = DictStore()
init_array(store, shape=100, chunks=10)
a = Array(store)
assert isinstance(a, Array)
Expand All@@ -54,7 +54,7 @@ def test_array_init(self):
assert "8fecb7a17ea1493d9c1430d04437b4f5b0b34985" == a.hexdigest()

# initialize at path
store = dict()
store = DictStore()
init_array(store, shape=100, chunks=10, path='foo/bar')
a = Array(store, path='foo/bar')
assert isinstance(a, Array)
Expand All@@ -67,18 +67,18 @@ def test_array_init(self):
assert "8fecb7a17ea1493d9c1430d04437b4f5b0b34985" == a.hexdigest()

# store not initialized
store = dict()
store = DictStore()
with pytest.raises(ValueError):
Array(store)

# group is in the way
store = dict()
store = DictStore()
init_group(store, path='baz')
with pytest.raises(ValueError):
Array(store, path='baz')

def create_array(self, read_only=False, **kwargs):
store = dict()
store = DictStore()
kwargs.setdefault('compressor', Zlib(level=1))
cache_metadata = kwargs.pop('cache_metadata', True)
cache_attrs = kwargs.pop('cache_attrs', True)
Expand DownExpand Up@@ -1255,7 +1255,7 @@ class TestArrayWithPath(TestArray):

@staticmethod
def create_array(read_only=False, **kwargs):
store = dict()
store = DictStore()
cache_metadata = kwargs.pop('cache_metadata', True)
cache_attrs = kwargs.pop('cache_attrs', True)
init_array(store, path='foo/bar', **kwargs)
Expand DownExpand Up@@ -1299,18 +1299,14 @@ def test_nbytes_stored(self):
if k.startswith('foo/bar/'))
assert expect_nbytes_stored == z.nbytes_stored

# mess with store
z.store[z._key_prefix + 'foo'] = list(range(10))
assert -1 == z.nbytes_stored


class TestArrayWithChunkStore(TestArray):

@staticmethod
def create_array(read_only=False, **kwargs):
store = dict()
store = DictStore()
# separate chunk store
chunk_store = dict()
chunk_store = DictStore()
cache_metadata = kwargs.pop('cache_metadata', True)
cache_attrs = kwargs.pop('cache_attrs', True)
init_array(store, chunk_store=chunk_store, **kwargs)
Expand DownExpand Up@@ -1353,10 +1349,6 @@ def test_nbytes_stored(self):
for v in z.chunk_store.values())
assert expect_nbytes_stored == z.nbytes_stored

# mess with store
z.chunk_store[z._key_prefix + 'foo'] = list(range(10))
assert -1 == z.nbytes_stored


class TestArrayWithDirectoryStore(TestArray):

Expand DownExpand Up@@ -1516,7 +1508,7 @@ def test_nbytes_stored(self):
class TestArrayWithNoCompressor(TestArray):

def create_array(self, read_only=False, **kwargs):
store = dict()
store = DictStore()
kwargs.setdefault('compressor', None)
cache_metadata = kwargs.pop('cache_metadata', True)
cache_attrs = kwargs.pop('cache_attrs', True)
Expand DownExpand Up@@ -1551,7 +1543,7 @@ def test_hexdigest(self):
class TestArrayWithBZ2Compressor(TestArray):

def create_array(self, read_only=False, **kwargs):
store = dict()
store = DictStore()
compressor = BZ2(level=1)
kwargs.setdefault('compressor', compressor)
cache_metadata = kwargs.pop('cache_metadata', True)
Expand DownExpand Up@@ -1587,7 +1579,7 @@ def test_hexdigest(self):
class TestArrayWithBloscCompressor(TestArray):

def create_array(self, read_only=False, **kwargs):
store = dict()
store = DictStore()
compressor = Blosc(cname='zstd', clevel=1, shuffle=1)
kwargs.setdefault('compressor', compressor)
cache_metadata = kwargs.pop('cache_metadata', True)
Expand DownExpand Up@@ -1630,7 +1622,7 @@ def test_hexdigest(self):
class TestArrayWithLZMACompressor(TestArray):

def create_array(self, read_only=False, **kwargs):
store = dict()
store = DictStore()
compressor = LZMA(preset=1)
kwargs.setdefault('compressor', compressor)
cache_metadata = kwargs.pop('cache_metadata', True)
Expand DownExpand Up@@ -1667,7 +1659,7 @@ class TestArrayWithFilters(TestArray):

@staticmethod
def create_array(read_only=False, **kwargs):
store = dict()
store = DictStore()
dtype = kwargs.get('dtype', None)
filters = [
Delta(dtype=dtype),
Expand DownExpand Up@@ -1710,7 +1702,7 @@ def test_astype_no_filters(self):
dtype = np.dtype(np.int8)
astype = np.dtype(np.float32)

store = dict()
store = DictStore()
init_array(store, shape=shape, chunks=10, dtype=dtype)

data = np.arange(np.prod(shape), dtype=dtype).reshape(shape)
Expand DownExpand Up@@ -1830,11 +1822,31 @@ def test_nbytes_stored(self):
assert -1 == z.nbytes_stored


class TestArrayWithCustomChunkStore(TestArray):

@staticmethod
def create_array(read_only=False, **kwargs):
store = CustomMapping()
kwargs["chunk_store"] = CustomMapping()
kwargs.setdefault('compressor', Zlib(1))
cache_metadata = kwargs.pop('cache_metadata', True)
cache_attrs = kwargs.pop('cache_attrs', True)
init_array(store, **kwargs)
return Array(store, read_only=read_only, cache_metadata=cache_metadata,
cache_attrs=cache_attrs)

def test_nbytes_stored(self):
z = self.create_array(shape=1000, chunks=100)
assert -1 == z.nbytes_stored
z[:] = 42
assert -1 == z.nbytes_stored


class TestArrayNoCache(TestArray):

@staticmethod
def create_array(read_only=False, **kwargs):
store = dict()
store = DictStore()
kwargs.setdefault('compressor', Zlib(level=1))
cache_metadata = kwargs.pop('cache_metadata', True)
cache_attrs = kwargs.pop('cache_attrs', True)
Expand DownExpand Up@@ -1906,7 +1918,7 @@ class TestArrayWithStoreCache(TestArray):

@staticmethod
def create_array(read_only=False, **kwargs):
store = LRUStoreCache(dict(), max_size=None)
store = LRUStoreCache(DictStore(), max_size=None)
kwargs.setdefault('compressor', Zlib(level=1))
cache_metadata = kwargs.pop('cache_metadata', True)
cache_attrs = kwargs.pop('cache_attrs', True)
Expand Down
10 changes: 5 additions & 5 deletions zarr/tests/test_hierarchy.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -41,7 +41,7 @@ class TestGroup(unittest.TestCase):
@staticmethod
def create_store():
# can be overridden in sub-classes
return dict(), None
return DictStore(), None

def create_group(self, store=None, path=None, read_only=False,
chunk_store=None, synchronizer=None):
Expand DownExpand Up@@ -948,7 +948,7 @@ class TestGroupWithChunkStore(TestGroup):

@staticmethod
def create_store():
return dict(), dict()
return DictStore(), DictStore()

def test_chunk_store(self):
# setup
Expand DownExpand Up@@ -979,7 +979,7 @@ class TestGroupWithStoreCache(TestGroup):

@staticmethod
def create_store():
store = LRUStoreCache(dict(), max_size=None)
store = LRUStoreCache(DictStore(), max_size=None)
return store, None


Expand All@@ -993,13 +993,13 @@ def test_group():
assert '/' == g.name

# usage with custom store
store = dict()
store = DictStore()
g = group(store=store)
assert isinstance(g, Group)
assert store is g.store

# overwrite behaviour
store = dict()
store = DictStore()
init_array(store, shape=100, chunks=10)
with pytest.raises(ValueError):
group(store)
Expand Down
2 changes: 1 addition & 1 deletion zarr/tests/test_info.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,7 +9,7 @@
def test_info():

# setup
g = zarr.group(store=dict(), chunk_store=dict(),
g = zarr.group(store=zarr.DictStore(), chunk_store=zarr.DictStore(),
synchronizer=zarr.ThreadSynchronizer())
g.create_group('foo')
z = g.zeros('bar', shape=10, filters=[numcodecs.Adler32()])
Expand Down
4 changes: 2 additions & 2 deletions zarr/tests/test_sync.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -19,7 +19,7 @@
from zarr.sync import ThreadSynchronizer, ProcessSynchronizer
from zarr.core import Array
from zarr.attrs import Attributes
from zarr.storage import init_array, DirectoryStore, init_group, atexit_rmtree
from zarr.storage import init_array, DictStore, DirectoryStore, init_group, atexit_rmtree
from zarr.hierarchy import Group


Expand DownExpand Up@@ -100,7 +100,7 @@ def test_parallel_append(self):
class TestArrayWithThreadSynchronizer(TestArray, MixinArraySyncTests):

def create_array(self, read_only=False, **kwargs):
store = dict()
store = DictStore()
cache_metadata = kwargs.pop('cache_metadata', True)
cache_attrs = kwargs.pop('cache_attrs', True)
init_array(store, **kwargs)
Expand Down