Skip to content

Commit 8dcb9dc

Browse files
authored
Zarr compression tests only with versions before 3.0 (#8319)
Fixes #8298. ### Description This includes the tests for the `compressor` argument when testing with Zarr before version 3.0 when this argument was deprecated. A fix to upgrade the version of `pycln` used is also included. The version of PyTorch is also fixed to below 2.6 to avoid issues with misuse of `torch.load` which must be addressed later. ### Types of changes <!--- Put an `x` in all the boxes that apply, and remove the not applicable items --> - [x] Non-breaking change (fix or new feature that would not break existing functionality). - [ ] Breaking change (fix or new feature that would cause existing functionality to change). - [ ] New tests added to cover the changes. - [ ] Integration tests passed locally by running `./runtests.sh -f -u --net --coverage`. - [ ] Quick tests passed locally by running `./runtests.sh --quick --unittests --disttests`. - [ ] In-line docstrings updated. - [ ] Documentation updated, tested `make html` command in the `docs/` folder. --------- Signed-off-by: Eric Kerfoot <eric.kerfoot@kcl.ac.uk>
1 parent 8ac8e0d commit 8dcb9dc

7 files changed

+34
-28
lines changed

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ repos:
6666
)$
6767
6868
- repo: https://github.com/hadialqattan/pycln
69-
rev: v2.4.0
69+
rev: v2.5.0
7070
hooks:
7171
- id: pycln
7272
args: [--config=pyproject.toml]

monai/data/meta_tensor.py

+5
Original file line numberDiff line numberDiff line change
@@ -607,3 +607,8 @@ def print_verbose(self) -> None:
607607
print(self)
608608
if self.meta is not None:
609609
print(self.meta.__repr__())
610+
611+
612+
# needed in later versions of Pytorch to indicate the class is safe for serialisation
613+
if hasattr(torch.serialization, "add_safe_globals"):
614+
torch.serialization.add_safe_globals([MetaTensor])

monai/utils/jupyter_utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ def plot_engine_status(
234234

235235

236236
def _get_loss_from_output(
237-
output: list[torch.Tensor | dict[str, torch.Tensor]] | dict[str, torch.Tensor] | torch.Tensor
237+
output: list[torch.Tensor | dict[str, torch.Tensor]] | dict[str, torch.Tensor] | torch.Tensor,
238238
) -> torch.Tensor:
239239
"""Returns a single value from the network output, which is a dict or tensor."""
240240

monai/visualize/img2tensorboard.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ def _image3_animated_gif(
6565
img_str = b""
6666
for b_data in PIL.GifImagePlugin.getheader(ims[0])[0]:
6767
img_str += b_data
68-
img_str += b"\x21\xFF\x0B\x4E\x45\x54\x53\x43\x41\x50" b"\x45\x32\x2E\x30\x03\x01\x00\x00\x00"
68+
img_str += b"\x21\xff\x0b\x4e\x45\x54\x53\x43\x41\x50" b"\x45\x32\x2e\x30\x03\x01\x00\x00\x00"
6969
for i in ims:
7070
for b_data in PIL.GifImagePlugin.getdata(i):
7171
img_str += b_data
72-
img_str += b"\x3B"
72+
img_str += b"\x3b"
7373

7474
summary = SummaryX if has_tensorboardx and isinstance(writer, SummaryWriterX) else Summary
7575
summary_image_str = summary.Image(height=10, width=10, colorspace=1, encoded_image_string=img_str)

requirements-dev.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pep8-naming
1818
pycodestyle
1919
pyflakes
2020
black>=22.12
21-
isort>=5.1
21+
isort>=5.1, <6.0
2222
ruff
2323
pytype>=2020.6.1; platform_system != "Windows"
2424
types-setuptools

requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
torch>=1.9
1+
torch>=1.9,<2.6
22
numpy>=1.24,<2.0

tests/test_zarr_avg_merger.py

+23-22
Original file line numberDiff line numberDiff line change
@@ -260,32 +260,33 @@
260260
TENSOR_4x4,
261261
]
262262

263+
ALL_TESTS = [
264+
TEST_CASE_0_DEFAULT_DTYPE,
265+
TEST_CASE_1_DEFAULT_DTYPE,
266+
TEST_CASE_2_DEFAULT_DTYPE,
267+
TEST_CASE_3_DEFAULT_DTYPE,
268+
TEST_CASE_4_DEFAULT_DTYPE,
269+
TEST_CASE_5_VALUE_DTYPE,
270+
TEST_CASE_6_COUNT_DTYPE,
271+
TEST_CASE_7_COUNT_VALUE_DTYPE,
272+
TEST_CASE_8_DTYPE,
273+
TEST_CASE_9_LARGER_SHAPE,
274+
TEST_CASE_10_DIRECTORY_STORE,
275+
TEST_CASE_11_MEMORY_STORE,
276+
TEST_CASE_12_CHUNKS,
277+
TEST_CASE_16_WITH_LOCK,
278+
TEST_CASE_17_WITHOUT_LOCK,
279+
]
280+
281+
# add compression tests only when using Zarr version before 3.0
282+
if not version_geq(get_package_version("zarr"), "3.0.0"):
283+
ALL_TESTS += [TEST_CASE_13_COMPRESSOR_LZ4, TEST_CASE_14_COMPRESSOR_PICKLE, TEST_CASE_15_COMPRESSOR_LZMA]
284+
263285

264286
@unittest.skipUnless(has_zarr and has_numcodecs, "Requires zarr (and numcodecs) packages.)")
265287
class ZarrAvgMergerTests(unittest.TestCase):
266288

267-
@parameterized.expand(
268-
[
269-
TEST_CASE_0_DEFAULT_DTYPE,
270-
TEST_CASE_1_DEFAULT_DTYPE,
271-
TEST_CASE_2_DEFAULT_DTYPE,
272-
TEST_CASE_3_DEFAULT_DTYPE,
273-
TEST_CASE_4_DEFAULT_DTYPE,
274-
TEST_CASE_5_VALUE_DTYPE,
275-
TEST_CASE_6_COUNT_DTYPE,
276-
TEST_CASE_7_COUNT_VALUE_DTYPE,
277-
TEST_CASE_8_DTYPE,
278-
TEST_CASE_9_LARGER_SHAPE,
279-
TEST_CASE_10_DIRECTORY_STORE,
280-
TEST_CASE_11_MEMORY_STORE,
281-
TEST_CASE_12_CHUNKS,
282-
TEST_CASE_13_COMPRESSOR_LZ4,
283-
TEST_CASE_14_COMPRESSOR_PICKLE,
284-
TEST_CASE_15_COMPRESSOR_LZMA,
285-
TEST_CASE_16_WITH_LOCK,
286-
TEST_CASE_17_WITHOUT_LOCK,
287-
]
288-
)
289+
@parameterized.expand(ALL_TESTS)
289290
def test_zarr_avg_merger_patches(self, arguments, patch_locations, expected):
290291
codec_reg = numcodecs.registry.codec_registry
291292
if "compressor" in arguments:

0 commit comments

Comments
 (0)