|
23 | 23 | from zarr.core.codec_pipeline import BatchedCodecPipeline |
24 | 24 | from zarr.core.config import BadConfigError, config |
25 | 25 | from zarr.core.indexing import SelectorTuple |
26 | | -from zarr.errors import ZarrUserWarning |
| 26 | +from zarr.errors import MissingChunkError, ZarrUserWarning |
27 | 27 | from zarr.registry import ( |
28 | 28 | fully_qualified_name, |
29 | 29 | get_buffer_class, |
@@ -61,6 +61,7 @@ def test_config_defaults_set() -> None: |
61 | 61 | "codec_pipeline": { |
62 | 62 | "path": "zarr.core.codec_pipeline.BatchedCodecPipeline", |
63 | 63 | "batch_size": 1, |
| 64 | + "fill_missing_chunks": True, |
64 | 65 | }, |
65 | 66 | "codecs": { |
66 | 67 | "blosc": "zarr.codecs.blosc.BloscCodec", |
@@ -319,6 +320,26 @@ class NewCodec2(BytesCodec): |
319 | 320 | get_codec_class("new_codec") |
320 | 321 |
|
321 | 322 |
|
| 323 | +@pytest.mark.parametrize("store", ["local", "memory"], indirect=["store"]) |
| 324 | +def test_config_fill_missing_chunks(store: Store) -> None: |
| 325 | + arr = zarr.create_array(store=store, shape=(3, 3), chunks=(2, 2), dtype="int32", fill_value=42) |
| 326 | + |
| 327 | + # default behavior: missing chunks are filled with the fill value |
| 328 | + result = zarr.open_array(store)[:] |
| 329 | + assert np.array_equal(result, np.full((3, 3), 42, dtype="int32")) |
| 330 | + |
| 331 | + # with fill_missing_chunks=False, reading missing chunks raises an error |
| 332 | + with config.set({"codec_pipeline.fill_missing_chunks": False}): |
| 333 | + with pytest.raises(MissingChunkError): |
| 334 | + zarr.open_array(store)[:] |
| 335 | + |
| 336 | + # after writing data, all chunks exist and no error is raised |
| 337 | + arr[:] = np.arange(9, dtype="int32").reshape(3, 3) |
| 338 | + with config.set({"codec_pipeline.fill_missing_chunks": False}): |
| 339 | + result = zarr.open_array(store)[:] |
| 340 | + assert np.array_equal(result, np.arange(9, dtype="int32").reshape(3, 3)) |
| 341 | + |
| 342 | + |
322 | 343 | @pytest.mark.parametrize( |
323 | 344 | "key", |
324 | 345 | [ |
|
0 commit comments