Skip to content

⬆️ Upgrade Zarr to v3+ Compatibility#904

Merged
shaneahmed merged 84 commits into
developfrom
fix-zarr-check
May 8, 2026
Merged

⬆️ Upgrade Zarr to v3+ Compatibility#904
shaneahmed merged 84 commits into
developfrom
fix-zarr-check

Conversation

@measty
Copy link
Copy Markdown
Collaborator

@measty measty commented Jan 16, 2025

✅ Summary

  • Enables compatibility with Zarr v3+
  • Simplifies error handling across Zarr versions
  • Removes deprecated storage backends and APIs
  • Lays groundwork for full Zarr v3 migration

This PR updates TIAToolbox to support Zarr v3+, addressing breaking changes introduced in Zarr ≥ 3.0 and aligning internal APIs, storage handling, and error handling accordingly.


Zarr v3 removed zarr.errors.FSPathExistNotDir. In Zarr ≥ 3.0, equivalent failure modes now raise standard Python exceptions (e.g. FileNotFoundError).

To avoid fragile version-specific logic:

  • Removed checks for specific Zarr exception types
  • Replaced them with generic exception handling that works consistently across Zarr versions

🔧 Key changes

Dependency updates

  • 🆙 Upgrade to:
    • zarr >= 3.0.8
    • tifffile >= 2025.5.21

Zarr API & storage migration

  • Refactor zarr.core.Arrayzarr.Array
  • Replace zarr.DirectoryStore with zarr.storage.LocalStore
  • Remove ngff.sqlitestore (Zarr v3 no longer supports zarr.SQLiteStore)
  • Replace canvas_zarr.store.path with canvas_zarr.store.root
  • Ensure Zarr paths explicitly use string keys (key / str(i) instead of key / i)

Dask & array handling

  • Remove unsupported object_codec usage in dask.to_zarr
  • Update zarr.resize calls to use tuple inputs
  • Replace output.items() with output.members()

⚠️ Known limitations & follow‑ups

Zarr v3 removes or significantly changes several APIs still used by TIAToolbox, including:

  • zarr.LRUStoreCache
  • zarr.DirectoryStore
  • zarr.SQLiteStore

While this PR resolves immediate incompatibilities and enables Zarr v3 usage, additional refactoring will be required to fully replace or redesign components that depend on these removed features.

In addition, full compatibility with tifffile depends on upstream Zarr v3 support, and some workflows may remain limited until that stabilises.

📖 For a detailed overview of breaking changes, see the official Zarr v3 migration guide:
https://zarr.readthedocs.io/en/latest/user-guide/v3_migration.html


@measty measty changed the title fix zarr checking Zarr 3.0 compatibility Jan 16, 2025
@measty measty marked this pull request as draft January 16, 2025 14:11
@codecov
Copy link
Copy Markdown

codecov Bot commented Jan 16, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.87%. Comparing base (3ca1599) to head (8e4dca6).

Additional details and impacted files
@@           Coverage Diff            @@
##           develop     #904   +/-   ##
========================================
  Coverage    99.87%   99.87%           
========================================
  Files           85       85           
  Lines        11572    11623   +51     
  Branches      1513     1524   +11     
========================================
+ Hits         11557    11608   +51     
- Misses           8        9    +1     
+ Partials         7        6    -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@measty measty mentioned this pull request Jan 16, 2025
@shaneahmed shaneahmed added bug Something isn't working dependencies Pull requests that update a dependency file labels Jan 24, 2025
@shaneahmed
Copy link
Copy Markdown
Member

shaneahmed commented Mar 19, 2025

Zarr v3 is not compatible with tifffile cgohlke/tifffile#282 czbiohub-sf/iohub#292

@shaneahmed shaneahmed added the stale Old PRs/Issues which are inactive label Mar 21, 2025
@shaneahmed shaneahmed added this to the Release v1.7.0 milestone Mar 21, 2025
@shaneahmed
Copy link
Copy Markdown
Member

Zarr 3 is supported by tifffile. However, zarr 3 only supports Python 3.11+.

@shaneahmed shaneahmed marked this pull request as ready for review April 17, 2026 09:20
Comment thread tests/engines/test_multi_task_segmentor.py Outdated
Comment thread tests/engines/test_multi_task_segmentor.py Outdated
Comment thread tests/engines/test_multi_task_segmentor.py Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates TIAToolbox to be compatible with Zarr v3 by migrating deprecated Zarr v2 APIs, adjusting store handling (LocalStore/FsspecStore, group iteration), and updating dependency requirements and tests accordingly.

Changes:

  • Upgrade dependencies to zarr>=3.0.8 and tifffile>=2025.5.21, and refactor Zarr usage to Zarr v3 APIs (stores, group/array types, iteration, resize signatures).
  • Update WSI readers (TIFF/NGFF/fsspec-json) to work with Zarr v3 storage and caching patterns.
  • Adjust model engines and tests to avoid Zarr v2-only features (e.g., object codecs, SQLiteStore) and accommodate Zarr v3 group key semantics.

Reviewed changes

Copilot reviewed 25 out of 25 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
tiatoolbox/wsicore/wsireader.py Refactors Zarr/NGFF detection and readers for Zarr v3, introduces CacheStore usage, URL handling, and updates group iteration.
tiatoolbox/wsicore/__init__.py Adds WSIReaderParams to exports and extends it with storage_options.
tiatoolbox/utils/transforms.py Minor typing adjustments for NumPy dtype handling and local variable annotations.
tiatoolbox/utils/misc.py Updates shapely typing, migrates Zarr types (zarr.Array/zarr.Group), updates Zarr creation API, and adds pad_contours helper for Zarr v3.
tiatoolbox/utils/metrics.py Adds explicit NumPy typing for unpaired coordinate outputs.
tiatoolbox/utils/image.py Adds explicit ndarray annotations for intermediate variables.
tiatoolbox/tools/pyramid.py Adds a mypy ignore for defusedxml.defuse_stdlib() attribute typing.
tiatoolbox/tools/patchextraction.py Refactors meshgrid helper into a static method with improved typing.
tiatoolbox/tools/graph.py Normalizes cKDTree.query outputs into NumPy arrays.
tiatoolbox/models/engine/semantic_segmentor.py Updates Zarr store root usage and Zarr v3 resize signature / LocalStore.
tiatoolbox/models/engine/nucleus_detector.py Removes object_codec usage in to_zarr call.
tiatoolbox/models/engine/multi_task_segmentor.py Adapts output handling to Zarr v3 group semantics and adds Zarr cleanup helper logic.
tiatoolbox/models/engine/engine_abc.py Removes object codec logic for Zarr writing; always rechunks before saving.
tiatoolbox/models/architecture/micronet.py Ensures empty outputs use non-object dtypes for Zarr v3 compatibility.
tiatoolbox/models/architecture/hovernetplus.py Ensures empty outputs use non-object dtypes for Zarr v3 compatibility.
tiatoolbox/models/architecture/hovernet.py Avoids object dtypes in outputs and pads inhomogeneous arrays for Zarr v3 saving.
tests/test_wsireader.py Updates/introduces tests for Zarr v3 metadata and adds an xfail S3 NGFF test plus additional coverage branches.
tests/test_utils.py Adds tests for pad_contours and create_smart_array chunk handling.
tests/models/test_models_abc.py Changes pretrained-model download test to be unconditionally skipped.
tests/models/test_arch_micronet.py Updates Zarr group indexing to string keys.
tests/engines/test_semantic_segmentor.py Updates iteration to use members() for Zarr v3 groups.
tests/engines/test_nucleus_detection_engine.py Updates Zarr group indexing to string keys.
tests/engines/test_multi_task_segmentor.py Updates assertions and indexing for Zarr v3 storage and contour handling.
requirements/requirements.txt Bumps tifffile and zarr minimum versions for v3 compatibility.
.github/workflows/mypy-type-check.yml Relaxes mypy import handling with --follow-imports=skip --ignore-missing-imports.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tiatoolbox/wsicore/wsireader.py
Comment thread tiatoolbox/models/engine/multi_task_segmentor.py Outdated
Comment thread tests/test_wsireader.py Outdated
Comment thread tiatoolbox/wsicore/wsireader.py
Comment thread tiatoolbox/wsicore/wsireader.py
Comment thread tiatoolbox/wsicore/wsireader.py Outdated
Comment thread tiatoolbox/models/engine/multi_task_segmentor.py
Comment thread tests/models/test_models_abc.py
Comment thread .github/workflows/mypy-type-check.yml
Copy link
Copy Markdown
Member

@shaneahmed shaneahmed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have tested the engines locally and they work well. I have also addressed Co-Pilots comments.

Comment thread tests/engines/test_multi_task_segmentor.py Fixed
@shaneahmed shaneahmed removed the help wanted Extra attention is needed label May 6, 2026
@shaneahmed shaneahmed changed the title ⬆️ Zarr V3 compatibility ⬆️ Upgrade Zarr to v3+ Compatibility May 8, 2026
@shaneahmed shaneahmed merged commit 9d5abca into develop May 8, 2026
34 of 35 checks passed
@shaneahmed shaneahmed deleted the fix-zarr-check branch May 8, 2026 11:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working dependencies Pull requests that update a dependency file

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants