|
11 | 11 | import numpy as np |
12 | 12 | import numpy.typing as npt |
13 | 13 | import pytest |
| 14 | +from packaging.version import Version |
14 | 15 |
|
15 | 16 | import zarr.api.asynchronous |
16 | 17 | import zarr.api.synchronous as sync_api |
@@ -1457,3 +1458,47 @@ async def test_orthogonal_set_total_slice() -> None: |
1457 | 1458 | array = zarr.create_array(store, shape=(20, 20), chunks=(1, 2), dtype=int, fill_value=-1) |
1458 | 1459 | with mock.patch("zarr.storage.MemoryStore.get", side_effect=ValueError): |
1459 | 1460 | array[0, slice(4, 10)] = np.arange(6) |
| 1461 | + |
| 1462 | + |
| 1463 | +@pytest.mark.skipif( |
| 1464 | + Version(numcodecs.__version__) < Version("0.15.1"), |
| 1465 | + reason="codec configuration is overwritten on older versions. GH2800", |
| 1466 | +) |
| 1467 | +def test_roundtrip_numcodecs() -> None: |
| 1468 | + store = MemoryStore() |
| 1469 | + |
| 1470 | + compressors = [ |
| 1471 | + {"name": "numcodecs.shuffle", "configuration": {"elementsize": 2}}, |
| 1472 | + {"name": "numcodecs.zlib", "configuration": {"level": 4}}, |
| 1473 | + ] |
| 1474 | + filters = [ |
| 1475 | + { |
| 1476 | + "name": "numcodecs.fixedscaleoffset", |
| 1477 | + "configuration": { |
| 1478 | + "scale": 100.0, |
| 1479 | + "offset": 0.0, |
| 1480 | + "dtype": "<f8", |
| 1481 | + "astype": "<i2", |
| 1482 | + }, |
| 1483 | + }, |
| 1484 | + ] |
| 1485 | + |
| 1486 | + # Create the array with the correct codecs |
| 1487 | + root = zarr.group(store) |
| 1488 | + root.create_array( |
| 1489 | + "test", |
| 1490 | + shape=(720, 1440), |
| 1491 | + chunks=(720, 1440), |
| 1492 | + dtype="float64", |
| 1493 | + compressors=compressors, |
| 1494 | + filters=filters, |
| 1495 | + fill_value=-9.99, |
| 1496 | + dimension_names=["lat", "lon"], |
| 1497 | + ) |
| 1498 | + |
| 1499 | + BYTES_CODEC = {"name": "bytes", "configuration": {"endian": "little"}} |
| 1500 | + # Read in the array again and check compressor config |
| 1501 | + root = zarr.open_group(store, mode="r") |
| 1502 | + metadata = root["test"].metadata.to_dict() |
| 1503 | + expected = (*filters, BYTES_CODEC, *compressors) |
| 1504 | + assert metadata["codecs"] == expected |
0 commit comments