|
10 | 10 | import numcodecs
|
11 | 11 | import numpy as np
|
12 | 12 | import pytest
|
| 13 | +from packaging.version import Version |
13 | 14 |
|
14 | 15 | import zarr.api.asynchronous
|
15 | 16 | import zarr.api.synchronous as sync_api
|
@@ -1337,3 +1338,47 @@ async def test_orthogonal_set_total_slice() -> None:
|
1337 | 1338 | array = zarr.create_array(store, shape=(20, 20), chunks=(1, 2), dtype=int, fill_value=-1)
|
1338 | 1339 | with mock.patch("zarr.storage.MemoryStore.get", side_effect=ValueError):
|
1339 | 1340 | 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