Skip to content

Commit

Permalink
[V3] Allow for incomplete codec metadata using numcodecs.get_codec (#…
Browse files Browse the repository at this point in the history
…1447)

* refactor(v3): Allow for incomplete codec metadata using numcodecs.get_codec

* add test

* lint

* add release note

---------

Co-authored-by: Ryan Abernathey <ryan.abernathey@gmail.com>
  • Loading branch information
jhamman and rabernat committed Jul 10, 2023
1 parent 98f74d5 commit aa5db9f
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 15 deletions.
10 changes: 7 additions & 3 deletions docs/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@ Release notes
Unreleased
----------

Bug fixes
~~~~~~~~~
Enhancements
~~~~~~~~~~~~

* Allow for partial codec specification in V3 array metadata.
By :user:`Joe Hamman <jhamman>` :issue:`1443`.

* Add ``__contains__`` method to ``KVStore``. By :user:`Christoph Gohlke <cgohlke>` :issue:`1454`.
* Add ``__contains__`` method to ``KVStore``.
By :user:`Christoph Gohlke <cgohlke>` :issue:`1454`.

* **Block Indexing**: Implemented blockwise (chunk blocks) indexing to ``zarr.Array``.
By :user:`Altay Sansal <tasansal>` :issue:`1428`
Expand Down
20 changes: 8 additions & 12 deletions zarr/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,26 +441,22 @@ def _decode_codec_metadata(cls, meta: Optional[Mapping]) -> Optional[Codec]:
uri = 'https://purl.org/zarr/spec/codec/'
conf = meta['configuration']
if meta['codec'].startswith(uri + 'gzip/'):
codec = numcodecs.GZip(level=conf['level'])
conf["id"] = "gzip"
elif meta['codec'].startswith(uri + 'zlib/'):
codec = numcodecs.Zlib(level=conf['level'])
conf["id"] = "zlib"
elif meta['codec'].startswith(uri + 'blosc/'):
codec = numcodecs.Blosc(clevel=conf['clevel'],
shuffle=conf['shuffle'],
blocksize=conf['blocksize'],
cname=conf['cname'])
conf["id"] = "blosc"
elif meta['codec'].startswith(uri + 'bz2/'):
codec = numcodecs.BZ2(level=conf['level'])
conf["id"] = "bz2"
elif meta['codec'].startswith(uri + 'lz4/'):
codec = numcodecs.LZ4(acceleration=conf['acceleration'])
conf["id"] = "lz4"
elif meta['codec'].startswith(uri + 'lzma/'):
codec = numcodecs.LZMA(format=conf['format'],
check=conf['check'],
preset=conf['preset'],
filters=conf['filters'])
conf["id"] = "lzma"
else:
raise NotImplementedError

codec = numcodecs.get_codec(conf)

return codec

@classmethod
Expand Down
28 changes: 28 additions & 0 deletions zarr/tests/test_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,34 @@ def test_encode_decode_array_dtype_shape_v3():
assert 'filters' not in meta_dec


@pytest.mark.parametrize("comp_id", ["gzip", "zlib", "blosc", "bz2", "lz4", "lzma"])
def test_decode_metadata_implicit_compressor_config_v3(comp_id):
meta = {
"attributes": {},
"chunk_grid": {
"chunk_shape": [10],
"separator": "/",
"type": "regular"
},
"chunk_memory_layout": "C",
"compressor": {
"codec": f"https://purl.org/zarr/spec/codec/{comp_id}/1.0",
"configuration": {
# intentionally left empty
}
},
"data_type": "<f8",
"extensions": [],
"fill_value": None,
"shape": [100, 10, 10]
}
meta_json = json.dumps(meta)

# test decoding
meta_dec = Metadata3.decode_array_metadata(meta_json)
assert meta_dec['compressor'].codec_id == comp_id


def test_encode_decode_array_structured():

meta = dict(
Expand Down

0 comments on commit aa5db9f

Please sign in to comment.