Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Implement Zarr V3 protocol #898

Merged
merged 121 commits into from
Mar 23, 2022
Merged
Show file tree
Hide file tree
Changes from 110 commits
Commits
Show all changes
121 commits
Select commit Hold shift + click to select a range
64bbbd8
add v3 store classes
grlee77 Nov 16, 2021
85b8e23
add TODO comment to meta.py
grlee77 Nov 17, 2021
5fee6fb
Merge remote-tracking branch 'upstream/master' into v3-store-part1
grlee77 Nov 17, 2021
983d190
fix flake8 errors
grlee77 Nov 30, 2021
4057088
Merge remote-tracking branch 'upstream/master' into v3-store-part1
grlee77 Nov 30, 2021
9ed6181
follow zarr v3 spec when dealing with extension data types
grlee77 Dec 15, 2021
662e310
fixes to v3 dtype handling
grlee77 Dec 15, 2021
9950a4d
Merge remote-tracking branch 'upstream/master' into v3-store-part1
grlee77 Dec 15, 2021
450c575
flake8 cleanup
grlee77 Dec 15, 2021
63a9e3c
remove duplicate lines in Metadata2.encode_array_metadata
grlee77 Dec 16, 2021
1a2a1ef
Fix fields in array metadata
grlee77 Dec 17, 2021
bcb2d5f
Fix encode/decode of codec metadata
grlee77 Dec 17, 2021
9bfeacb
add missing level to Zlib in _decode_codec_metadata
grlee77 Dec 17, 2021
23aca42
add extensions entry to v3 array metadata
grlee77 Dec 17, 2021
e47035d
dimension_separator should not be in the array metadata for v3
grlee77 Dec 17, 2021
7549d5b
update Attributes, adding StoreV3 support
grlee77 Nov 30, 2021
765fe7d
add StoreV3 support to core Array object
grlee77 Nov 30, 2021
5efc786
update hexdigests
grlee77 Dec 17, 2021
6a308c8
handle additional codecs that were not implemented in zarrita
grlee77 Dec 17, 2021
f7883fc
fix
grlee77 Dec 17, 2021
5040119
fix hexdigests
grlee77 Dec 17, 2021
7c3736d
fix indentation
grlee77 Dec 17, 2021
d07caed
add StoreV3 support to Group, open_group, etc.
grlee77 Dec 1, 2021
00b2cc0
add StoreV3 support to creation routines
grlee77 Dec 1, 2021
504913a
Handle dimension_separator appropriately in open_array
grlee77 Dec 16, 2021
7142974
TST: add tests for open_array and dimension_separator
grlee77 Dec 16, 2021
e4ce79f
only allow Codec not a simple str as compressor during array initiali…
grlee77 Dec 17, 2021
8bef4fc
add StoreV3 support to most convenience routines
grlee77 Dec 1, 2021
9478ea3
set convenience routines default to zarr_version=None
grlee77 Dec 16, 2021
2c21761
adjust test have dimension_separator key was removed from v3 metadata
grlee77 Dec 17, 2021
f28d3d3
Merge branch 'v3-store-part1' into v3-store-part6
grlee77 Dec 17, 2021
14a3c05
Merge remote-tracking branch 'upstream/master' into v3-store-part6
grlee77 Dec 17, 2021
8783f44
add underscores to imported test classes in test_storage_v3.py
grlee77 Dec 17, 2021
4bd99dc
Merge branch 'v3-store-part1' into v3-store-part6
grlee77 Dec 17, 2021
981c6b9
add underscore to imported TestArrayWithPath in test_core_v3.py
grlee77 Dec 17, 2021
fc5c1c1
refactore _valid_keys and add tests
grlee77 Dec 19, 2021
83cf345
move KVStoreV3 logic from StoreV3.__eq__ to KVStoreV3.__eq__
grlee77 Dec 19, 2021
1dbce4a
expand tests for _ensure_store
grlee77 Dec 19, 2021
5391c46
test exception for v2 store input to _get_hierarchy_metadata
grlee77 Dec 19, 2021
6feacdb
test exception for init_array with path=None
grlee77 Dec 19, 2021
bf244df
remove unneeded checks from Attributes
grlee77 Dec 19, 2021
097459b
tests __repr__ of LazyLoader
grlee77 Dec 19, 2021
2f15195
test load of individual array
grlee77 Dec 19, 2021
235b445
Add simple test case for zarr.tree convenience method
grlee77 Dec 19, 2021
0b82bda
add tests for copy_store with a V3 store class
grlee77 Dec 19, 2021
ab71ed5
test raising of exception on intialization with mismatched store and …
grlee77 Dec 19, 2021
9bcfb24
add key validation on setitem in v3 stores
grlee77 Dec 20, 2021
f4bedd6
Fix core V3 tests now that keys are validated on __setitem__
grlee77 Dec 20, 2021
95c0a22
pep8 in storage_v3 tests
grlee77 Dec 20, 2021
e321c12
flake8 in test_convenience.py
grlee77 Dec 20, 2021
2d9058e
pep8
grlee77 Dec 20, 2021
63d8d27
fix test_attrs.py
grlee77 Dec 20, 2021
8417dc3
Fix SQLLiteStore
grlee77 Dec 20, 2021
b9c9ed4
fix failing hierarchy test
grlee77 Dec 20, 2021
efb0b38
update ZipStore tests to make sure they all run on V3
grlee77 Dec 20, 2021
d2ee391
add default rmdir implementation to all StoreV3 classes
grlee77 Dec 20, 2021
6d1ac20
fix test_sync.py
grlee77 Dec 20, 2021
e12adac
all rmdir methods for StoreV3 classes need to remove associated metadata
grlee77 Dec 20, 2021
d142da1
avoid warning from test_entropy.py
grlee77 Dec 20, 2021
2c8098e
pep8 fixes
grlee77 Dec 20, 2021
ae2145a
greatly reduce code duplication in test_storage_v3.py
grlee77 Dec 20, 2021
9fa4bdc
remove redundant test_hexdigest methods
grlee77 Dec 21, 2021
3291890
move test_core_v3.py functions back into test_core.py
grlee77 Dec 21, 2021
1850d88
typing fixes for mypy
grlee77 Dec 21, 2021
7524764
can assume self.keys() exists since BaseStore inherits from MutableMa…
grlee77 Dec 21, 2021
4824143
refactor rmdir methods for v3 and improve coverage
grlee77 Dec 21, 2021
19fcbee
improve coverage of core.py
grlee77 Dec 21, 2021
81d1c9a
improve coverage of convenience.py
grlee77 Dec 21, 2021
b0a963a
expend info tests
grlee77 Dec 21, 2021
2b79be1
Expand tests of Array.view
grlee77 Dec 21, 2021
02d9535
improve coverage of creation.py
grlee77 Dec 21, 2021
f2dbf7b
improve coverage of hierarchy.py
grlee77 Dec 21, 2021
f3378b8
improve coverage of meta.py
grlee77 Dec 21, 2021
c86802a
pep8
grlee77 Dec 21, 2021
20338c4
skip FSStoreV3 test when fsspec not installed
grlee77 Dec 21, 2021
70ea4a5
test raising of PermissionError for setter on views
grlee77 Dec 21, 2021
f2982d0
remove redundant check (_normalize_store_arg will already raise here)
grlee77 Dec 21, 2021
9bc92c5
improve coverage and fix bugs in normalize_store_arg
grlee77 Dec 21, 2021
82be4c9
improve coverage of storage.py
grlee77 Dec 21, 2021
8bea4b6
pep8
grlee77 Dec 21, 2021
ce64fab
fix StoreV3 tests
grlee77 Dec 22, 2021
9de3849
Merge remote-tracking branch 'upstream/master' into v3-store-part6
grlee77 Dec 22, 2021
b5a691b
fix duplicate zarr_fsstore entry
grlee77 Dec 22, 2021
47e4354
fix rename
grlee77 Dec 22, 2021
2415d85
remove debug statements
grlee77 Dec 22, 2021
98120df
fix typo
grlee77 Dec 22, 2021
a99519c
skip unavailable NumPy dtypes
grlee77 Dec 22, 2021
bd613bf
pep8
grlee77 Dec 22, 2021
eec4a3e
mypy fixes
grlee77 Dec 22, 2021
5970c69
remove redundant check (already done above)
grlee77 Dec 22, 2021
77f6fee
remove KeyError check. list_prefix only returns keys that exist
grlee77 Dec 22, 2021
f2b3ed8
coverage fixes
grlee77 Dec 22, 2021
05fbb2f
Merge remote-tracking branch 'upstream/master' into v3-store-part6
grlee77 Jan 6, 2022
347b67d
implemented ConsolidatedMetadataStoreV3
grlee77 Jan 6, 2022
0f2d583
expand ConsolidatedMetadataStoreV3 tests
grlee77 Jan 6, 2022
0c39bd4
remove debug statement
grlee77 Jan 7, 2022
993493b
fix tests: restore clobber=True
grlee77 Jan 7, 2022
a08d4f7
test error path in consolidate_metadata
grlee77 Jan 7, 2022
43dfa29
add pragma: no cover for lines in test_meta.py that will only be visi…
grlee77 Jan 7, 2022
41b052f
flake8 fixes
grlee77 Jan 7, 2022
8af6131
flake8
grlee77 Jan 9, 2022
001510b
ENH: add ABSStoreV3
grlee77 Jan 13, 2022
92f4b80
flake8
grlee77 Jan 13, 2022
aa64b7e
Merge remote-tracking branch 'upstream/master' into v3-store-part6
grlee77 Feb 28, 2022
c358506
fix ABSStore.rmdir test coverage
grlee77 Mar 1, 2022
133ee26
always use / in path
grlee77 Mar 2, 2022
652960f
Merge remote-tracking branch 'upstream/master' into v3-store-part6
grlee77 Mar 4, 2022
34f6747
remove remaining use of clobber argument in new tests
grlee77 Mar 4, 2022
9f56e82
remove NestedDirectoryStoreV3
grlee77 Mar 4, 2022
88405a8
flake8
grlee77 Mar 4, 2022
87b9543
Merge remote-tracking branch 'upstream/master' into v3-store-part6
grlee77 Mar 9, 2022
69e5a12
remove rmdir_abs: rmdir method of ABSStore parent class in ABSStoreV3
grlee77 Mar 9, 2022
58c8c20
define meta_root and data_root variables
grlee77 Mar 9, 2022
5e1ed7f
move _valid_key_characters to be a StoreV3 class field
grlee77 Mar 9, 2022
3593cad
make _get_hierarchy_metadata strictly require 'zarr.json'
grlee77 Mar 9, 2022
f036215
ignore type checks for _get_metadata_suffix
grlee77 Mar 11, 2022
6f08185
Merge remote-tracking branch 'upstream/master' into v3-store-part6
grlee77 Mar 11, 2022
353058d
remove unneeded if/else in Array and Hierarchy class __init__
grlee77 Mar 11, 2022
2ec2b2d
remove unused import
grlee77 Mar 11, 2022
2b82967
define DEFAULT_ZARR_VERSION so we can later more easily change from 2…
grlee77 Mar 11, 2022
7aa5dff
add test_get_hierarchy_metadata to test the v3 _get_hierarchy_metadat…
grlee77 Mar 11, 2022
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
68 changes: 62 additions & 6 deletions zarr/_storage/absstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import warnings
from numcodecs.compat import ensure_bytes
from zarr.util import normalize_storage_path
from zarr._storage.store import Store
from zarr._storage.store import Store, StoreV3, _get_hierarchy_metadata

__doctest_requires__ = {
('ABSStore', 'ABSStore.*'): ['azure.storage.blob'],
Expand Down Expand Up @@ -179,11 +179,7 @@ def listdir(self, path=None):
return items

def rmdir(self, path=None):
dir_path = normalize_storage_path(self._append_path_to_prefix(path))
if dir_path:
dir_path += '/'
for blob in self.client.list_blobs(name_starts_with=dir_path):
self.client.delete_blob(blob)
rmdir_abs(self, path)

def getsize(self, path=None):
store_path = normalize_storage_path(path)
Expand All @@ -209,3 +205,63 @@ def getsize(self, path=None):

def clear(self):
self.rmdir()


def rmdir_abs(store: ABSStore, path=None):
Copy link
Member

Choose a reason for hiding this comment

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

Why is this not a method on the store?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure why I did it that way. I can make this ABSStore.rmdir and just call it from there in ABSStoreV3.rmdir

dir_path = normalize_storage_path(store._append_path_to_prefix(path))
if dir_path:
dir_path += '/'
for blob in store.client.list_blobs(name_starts_with=dir_path):
store.client.delete_blob(blob)


class ABSStoreV3(ABSStore, StoreV3):

def list(self):
return list(self.keys())

def __eq__(self, other):
return (
isinstance(other, ABSStoreV3) and
self.client == other.client and
self.prefix == other.prefix
)

def __setitem__(self, key, value):
self._validate_key(key)
super().__setitem__(key, value)

def rmdir(self, path=None):
if not path:
# Currently allowing clear to delete everything as in v2

# If we disallow an empty path then we will need to modify
# TestABSStoreV3 to have the create_store method use a prefix.
rmdir_abs(self, '')
return
meta_dir = 'meta/root/' + path
grlee77 marked this conversation as resolved.
Show resolved Hide resolved
meta_dir = meta_dir.rstrip('/')
rmdir_abs(self, meta_dir)

# remove data folder
data_dir = 'data/root/' + path
data_dir = data_dir.rstrip('/')
rmdir_abs(self, data_dir)

# remove metadata files
sfx = _get_hierarchy_metadata(self)['metadata_key_suffix']
array_meta_file = meta_dir + '.array' + sfx
if array_meta_file in self:
del self[array_meta_file]
group_meta_file = meta_dir + '.group' + sfx
if group_meta_file in self:
del self[group_meta_file]

# TODO: adapt the v2 getsize method to work for v3
# For now, calling the generic keys-based _getsize
def getsize(self, path=None):
from zarr.storage import _getsize # avoid circular import
return _getsize(self, path)


ABSStoreV3.__doc__ = ABSStore.__doc__
Loading