From 02e56831c77856f065e54bb1c8f0060f29a03450 Mon Sep 17 00:00:00 2001 From: Matthias Bussonnier Date: Thu, 22 Oct 2020 10:32:03 -0700 Subject: [PATCH 1/3] Checking that the store is an instance of dict seem incorrect. Indeed MemoryStore is an instance of mutable mapping that have the same property as dict, but woudl not be seen as as instance of dict. --- zarr/core.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/zarr/core.py b/zarr/core.py index 8727a5deb5..651775e3a3 100644 --- a/zarr/core.py +++ b/zarr/core.py @@ -5,6 +5,7 @@ import operator import re from functools import reduce +from collections.abc import MutableMapping import numpy as np from numcodecs.compat import ensure_bytes, ensure_ndarray @@ -1821,7 +1822,7 @@ def _encode_chunk(self, chunk): cdata = chunk # ensure in-memory data is immutable and easy to compare - if isinstance(self.chunk_store, dict): + if isinstance(self.chunk_store, MutableMapping): cdata = ensure_bytes(cdata) return cdata From 4a39c97306f732c2026de3dde1b98a8a793b4c56 Mon Sep 17 00:00:00 2001 From: Matthias Bussonnier Date: Thu, 22 Oct 2020 12:09:16 -0700 Subject: [PATCH 2/3] Doctest seem to be stricter now, updating tostring() to tobytes() --- docs/tutorial.rst | 8 +++++--- zarr/storage.py | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/docs/tutorial.rst b/docs/tutorial.rst index ebc5db7165..0327cb248a 100644 --- a/docs/tutorial.rst +++ b/docs/tutorial.rst @@ -797,12 +797,14 @@ Here is an example using S3Map to read an array created previously:: Compressor : Blosc(cname='lz4', clevel=5, shuffle=SHUFFLE, blocksize=0) Store type : fsspec.mapping.FSMap No. bytes : 21 + No. bytes stored : 382 + Storage ratio : 0.1 Chunks initialized : 3/3 >>> z[:] array([b'H', b'e', b'l', b'l', b'o', b' ', b'f', b'r', b'o', b'm', b' ', b't', b'h', b'e', b' ', b'c', b'l', b'o', b'u', b'd', b'!'], dtype='|S1') - >>> z[:].tostring() + >>> z[:].tobytes() b'Hello from the cloud!' Zarr now also has a builtin storage backend for Azure Blob Storage. @@ -841,11 +843,11 @@ store. E.g.:: >>> z = root['foo/bar/baz'] >>> from timeit import timeit >>> # first data access is relatively slow, retrieved from store - ... timeit('print(z[:].tostring())', number=1, globals=globals()) # doctest: +SKIP + ... timeit('print(z[:].tobytes())', number=1, globals=globals()) # doctest: +SKIP b'Hello from the cloud!' 0.1081731989979744 >>> # second data access is faster, uses cache - ... timeit('print(z[:].tostring())', number=1, globals=globals()) # doctest: +SKIP + ... timeit('print(z[:].tobytes())', number=1, globals=globals()) # doctest: +SKIP b'Hello from the cloud!' 0.0009490990014455747 diff --git a/zarr/storage.py b/zarr/storage.py index 89f85f8eec..90dbc7dae6 100644 --- a/zarr/storage.py +++ b/zarr/storage.py @@ -1972,11 +1972,11 @@ class LRUStoreCache(MutableMapping): >>> z = root['foo/bar/baz'] # doctest: +REMOTE_DATA >>> from timeit import timeit >>> # first data access is relatively slow, retrieved from store - ... timeit('print(z[:].tostring())', number=1, globals=globals()) # doctest: +SKIP + ... timeit('print(z[:].tobytes())', number=1, globals=globals()) # doctest: +SKIP b'Hello from the cloud!' 0.1081731989979744 >>> # second data access is faster, uses cache - ... timeit('print(z[:].tostring())', number=1, globals=globals()) # doctest: +SKIP + ... timeit('print(z[:].tobytes())', number=1, globals=globals()) # doctest: +SKIP b'Hello from the cloud!' 0.0009490990014455747 From d6000a92e6e6ceeabb97489a1f2becb7f0639019 Mon Sep 17 00:00:00 2001 From: Matthias Bussonnier Date: Thu, 22 Oct 2020 15:10:42 -0700 Subject: [PATCH 3/3] Update docs/tutorial.rst --- docs/tutorial.rst | 2 -- 1 file changed, 2 deletions(-) diff --git a/docs/tutorial.rst b/docs/tutorial.rst index 0327cb248a..adb34e7999 100644 --- a/docs/tutorial.rst +++ b/docs/tutorial.rst @@ -797,8 +797,6 @@ Here is an example using S3Map to read an array created previously:: Compressor : Blosc(cname='lz4', clevel=5, shuffle=SHUFFLE, blocksize=0) Store type : fsspec.mapping.FSMap No. bytes : 21 - No. bytes stored : 382 - Storage ratio : 0.1 Chunks initialized : 3/3 >>> z[:] array([b'H', b'e', b'l', b'l', b'o', b' ', b'f', b'r', b'o', b'm', b' ',