Skip to content

Commit 9fbecd9

Browse files
committed
Regression test for codec overwriting.
Fix is in upstream zarr-developers/numcodecs#700 Closes #2800
1 parent a52048d commit 9fbecd9

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

tests/test_array.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import numcodecs
1111
import numpy as np
1212
import pytest
13+
from packaging.version import Version
1314

1415
import zarr.api.asynchronous
1516
import zarr.api.synchronous as sync_api
@@ -1337,3 +1338,47 @@ async def test_orthogonal_set_total_slice() -> None:
13371338
array = zarr.create_array(store, shape=(20, 20), chunks=(1, 2), dtype=int, fill_value=-1)
13381339
with mock.patch("zarr.storage.MemoryStore.get", side_effect=ValueError):
13391340
array[0, slice(4, 10)] = np.arange(6)
1341+
1342+
1343+
@pytest.mark.skipif(
1344+
Version(numcodecs.__version__) <= Version("0.15.1"),
1345+
reason="codec configuration is overwritten on older versions. GH2800",
1346+
)
1347+
def test_roundtrip_numcodecs() -> None:
1348+
store = MemoryStore()
1349+
1350+
compressors = [
1351+
{"name": "numcodecs.shuffle", "configuration": {"elementsize": 2}},
1352+
{"name": "numcodecs.zlib", "configuration": {"level": 4}},
1353+
]
1354+
filters = [
1355+
{
1356+
"name": "numcodecs.fixedscaleoffset",
1357+
"configuration": {
1358+
"scale": 100.0,
1359+
"offset": 0.0,
1360+
"dtype": "<f8",
1361+
"astype": "<i2",
1362+
},
1363+
},
1364+
]
1365+
1366+
# Create the array with the correct codecs
1367+
root = zarr.group(store)
1368+
root.create_array(
1369+
"test",
1370+
shape=(720, 1440),
1371+
chunks=(720, 1440),
1372+
dtype="float64",
1373+
compressors=compressors,
1374+
filters=filters,
1375+
fill_value=-9.99,
1376+
dimension_names=["lat", "lon"],
1377+
)
1378+
1379+
BYTES_CODEC = {"name": "bytes", "configuration": {"endian": "little"}}
1380+
# Read in the array again and check compressor config
1381+
root = zarr.open_group(store, mode="r")
1382+
metadata = root["test"].metadata.to_dict()
1383+
expected = (*filters, BYTES_CODEC, *compressors)
1384+
assert metadata["codecs"] == expected

0 commit comments

Comments
 (0)