Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion monai/inferers/merger.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,13 @@ def __init__(
self.value_store = zarr.storage.TempStore() if value_store is None else value_store # type: ignore
self.count_store = zarr.storage.TempStore() if count_store is None else count_store # type: ignore

self.chunks = chunks
# zarr 3.3 rejects boolean chunk arguments; `None` there means auto-chunking,
# which is what `chunks=True` meant before. On zarr < 3.3 `None` instead means
# a single whole-shape chunk, so the substitution must not be applied there.
if chunks is True and version_geq(get_package_version("zarr"), "3.3.0"):
self.chunks: Sequence[int] | bool | None = None
else:
self.chunks = chunks

# Initialize codecs/compressor attributes with proper types
self.codecs: list | None = None
Expand Down
30 changes: 25 additions & 5 deletions tests/inferers/test_zarr_avg_merger.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,20 @@
]

# Define zarr v3 codec configurations with proper bytes codec
ZARR_V3_LZ4_CODECS = [{"name": "bytes", "configuration": {}}, {"name": "blosc", "configuration": {"cname": "lz4"}}]
ZARR_V3_LZ4_CODECS = [
{"name": "bytes", "configuration": {"endian": "little"}},
{"name": "blosc", "configuration": {"cname": "lz4"}},
]

ZARR_V3_PICKLE_CODECS = [{"name": "bytes", "configuration": {}}, {"name": "blosc", "configuration": {"cname": "zstd"}}]
ZARR_V3_PICKLE_CODECS = [
{"name": "bytes", "configuration": {"endian": "little"}},
{"name": "blosc", "configuration": {"cname": "zstd"}},
]

ZARR_V3_LZMA_CODECS = [{"name": "bytes", "configuration": {}}, {"name": "blosc", "configuration": {"cname": "zlib"}}]
ZARR_V3_LZMA_CODECS = [
{"name": "bytes", "configuration": {"endian": "little"}},
{"name": "blosc", "configuration": {"cname": "zlib"}},
]

# test for LZ4 compressor (zarr v2) or codecs (zarr v3)
TEST_CASE_13_COMPRESSOR_LZ4 = [
Expand Down Expand Up @@ -289,7 +298,10 @@
TEST_CASE_19_VALUE_CODECS = [
dict(
merged_shape=TENSOR_4x4.shape,
value_codecs=[{"name": "bytes", "configuration": {}}, {"name": "blosc", "configuration": {"cname": "zstd"}}],
value_codecs=[
{"name": "bytes", "configuration": {"endian": "little"}},
{"name": "blosc", "configuration": {"cname": "zstd"}},
],
Comment thread
ericspod marked this conversation as resolved.
),
[
(TENSOR_4x4[..., :2, :2], (0, 0)),
Expand All @@ -304,7 +316,10 @@
TEST_CASE_20_COUNT_CODECS = [
dict(
merged_shape=TENSOR_4x4.shape,
count_codecs=[{"name": "bytes", "configuration": {}}, {"name": "blosc", "configuration": {"cname": "zlib"}}],
count_codecs=[
{"name": "bytes", "configuration": {"endian": "little"}},
{"name": "blosc", "configuration": {"cname": "zlib"}},
],
),
[
(TENSOR_4x4[..., :2, :2], (0, 0)),
Expand Down Expand Up @@ -449,6 +464,11 @@ def test_zarr_avg_merge_none_merged_shape_error(self):
with self.assertRaises(ValueError):
ZarrAvgMerger(merged_shape=None, store=self.merged_name)

def test_zarr_avg_merger_default_chunks_auto(self):
"""chunks=True must mean auto-chunking, not one whole-shape chunk (zarr 3.3 removed boolean chunks)."""
merger = ZarrAvgMerger(merged_shape=(4096, 4096), store=self.merged_name)
self.assertNotEqual(merger.output.chunks, (4096, 4096))


if __name__ == "__main__":
unittest.main()
Loading