Skip to content

Commit 510c72d

Browse files
committed
Set default for fill_missing_chunks in config.py. Add test replicating
example in zarr-python #486.
1 parent 34befaa commit 510c72d

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

src/zarr/core/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ def enable_gpu(self) -> ConfigSet:
104104
"codec_pipeline": {
105105
"path": "zarr.core.codec_pipeline.BatchedCodecPipeline",
106106
"batch_size": 1,
107+
"fill_missing_chunks": True,
107108
},
108109
"codecs": {
109110
"blosc": "zarr.codecs.blosc.BloscCodec",

tests/test_config.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from zarr.core.codec_pipeline import BatchedCodecPipeline
2424
from zarr.core.config import BadConfigError, config
2525
from zarr.core.indexing import SelectorTuple
26-
from zarr.errors import ZarrUserWarning
26+
from zarr.errors import MissingChunkError, ZarrUserWarning
2727
from zarr.registry import (
2828
fully_qualified_name,
2929
get_buffer_class,
@@ -61,6 +61,7 @@ def test_config_defaults_set() -> None:
6161
"codec_pipeline": {
6262
"path": "zarr.core.codec_pipeline.BatchedCodecPipeline",
6363
"batch_size": 1,
64+
"fill_missing_chunks": True,
6465
},
6566
"codecs": {
6667
"blosc": "zarr.codecs.blosc.BloscCodec",
@@ -319,6 +320,26 @@ class NewCodec2(BytesCodec):
319320
get_codec_class("new_codec")
320321

321322

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+
322343
@pytest.mark.parametrize(
323344
"key",
324345
[

0 commit comments

Comments
 (0)