Skip to content

feat(data)!: support zarr-python 3 - #197

Open
janickm wants to merge 1 commit into
stack/zarr3/03-node-cachefrom
stack/zarr3/04-zarr-python-3
Open

janickm wants to merge 1 commit into
stack/zarr3/03-node-cachefrom
stack/zarr3/04-zarr-python-3

Conversation

@janickm

@janickm janickm commented Oct 14, 2026 •

Copy link
Copy Markdown
Collaborator

Support zarr-python 3 (>= 3.1.4) next to zarr-python 2 for zarr format v2 data. The zarr-python version specific operations of nodes and stores are implemented by a zarr-python 3 backend (backend_zarr3.py), which is selected at import time:

  • zarr-python's coroutines run on an event loop owned by the calling thread (offloaded codec work runs inline), avoiding thread hand-offs to zarr-python's I/O thread per access. Forked processes create new loops, coroutines within running event loops run on zarr-python's I/O loop
  • a zarr-python 3 store of indexed tar archives; complete reads of arrays of archives stored as a single uncompressed chunk are views of the chunk record (no copies), as with zarr-python 2
  • consolidated hierarchies are opened from the decoded compressed consolidated metadata (no node metadata reads), with node metadata ordered by parent group (zarr-python < 3.4 attaches members of a group to its first run of keys only, zarr-python#4226)

Data written with zarr-python 2 and 3 is equivalent: chunk records are byte-identical, node metadata documents are equivalent JSON.

zarr-python 3 rewrites node metadata on every update of a node, which the write-once records of indexed tar archives don't support. Node metadata records of archives opened for writing are now kept in memory and appended when closing the archive (parents first), independent of the zarr-python version.

Test environments: python 3.11 uses zarr-python 3.1.4 (the oldest supported version), python 3.13 zarr-python 3.4, python 3.8 / 3.12 zarr-python 2. Type checking runs against zarr-python 3 (the zarr-python 2 backend is exempt from unresolved zarr-python 2 APIs).

BREAKING CHANGE: node metadata records of indexed tar archives are appended when closing archives (after all chunk records), so archives are no longer byte-identical to archives written by ncore 19.8 (their records are).

@copy-pr-bot

copy-pr-bot Bot commented Oct 14, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@janickm
janickm added this pull request to stack #201 October 14, 2026 07:28
@janickm

janickm commented Oct 14, 2026

Copy link
Copy Markdown
Collaborator Author

/ok to test 5d93e0d

@janickm

janickm commented Oct 14, 2026

Copy link
Copy Markdown
Collaborator Author

/ok to test 8c9cf08

@janickm
janickm force-pushed the stack/zarr3/04-zarr-python-3 branch from 8c9cf08 to 5e23488 Compare October 14, 2026 10:02
@janickm

janickm commented Oct 14, 2026

Copy link
Copy Markdown
Collaborator Author

/ok to test 5e23488

@janickm
janickm force-pushed the stack/zarr3/04-zarr-python-3 branch from 5e23488 to ac23351 Compare October 14, 2026 10:09
@janickm

janickm commented Oct 14, 2026

Copy link
Copy Markdown
Collaborator Author

/ok to test ac23351

@janickm
janickm force-pushed the stack/zarr3/04-zarr-python-3 branch from ac23351 to ab64cd0 Compare October 14, 2026 11:58
@janickm

janickm commented Oct 14, 2026

Copy link
Copy Markdown
Collaborator Author

/ok to test ab64cd0

@janickm
janickm force-pushed the stack/zarr3/04-zarr-python-3 branch from ab64cd0 to 64db7b6 Compare October 14, 2026 14:16
@janickm

janickm commented Oct 14, 2026

Copy link
Copy Markdown
Collaborator Author

/ok to test 64db7b6

@janickm
janickm force-pushed the stack/zarr3/04-zarr-python-3 branch from 64db7b6 to e6b9494 Compare October 14, 2026 14:43
@janickm

janickm commented Oct 14, 2026

Copy link
Copy Markdown
Collaborator Author

/ok to test e6b9494

@janickm
janickm force-pushed the stack/zarr3/04-zarr-python-3 branch from e6b9494 to f9e17de Compare October 14, 2026 15:32
@janickm

janickm commented Oct 14, 2026

Copy link
Copy Markdown
Collaborator Author

/ok to test f9e17de

@janickm
janickm force-pushed the stack/zarr3/04-zarr-python-3 branch from f9e17de to 9248118 Compare October 15, 2026 07:55
@janickm

janickm commented Oct 15, 2026

Copy link
Copy Markdown
Collaborator Author

/ok to test 9248118

@janickm
janickm force-pushed the stack/zarr3/04-zarr-python-3 branch from 9248118 to 754c687 Compare October 15, 2026 10:20
@janickm

janickm commented Oct 15, 2026

Copy link
Copy Markdown
Collaborator Author

/ok to test 754c687

@janickm

janickm commented Oct 15, 2026

Copy link
Copy Markdown
Collaborator Author

/ok to test f15e3ff

@janickm
janickm force-pushed the stack/zarr3/04-zarr-python-3 branch from f15e3ff to 9aee757 Compare October 15, 2026 15:08
@janickm

janickm commented Oct 15, 2026

Copy link
Copy Markdown
Collaborator Author

/ok to test 9aee757

Comment thread ncore/impl/data/backend_zarr3.py Outdated
Comment thread ncore/impl/data/backend_zarr3.py Outdated
Comment thread pyproject.toml
@janickm
janickm force-pushed the stack/zarr3/04-zarr-python-3 branch from 9aee757 to 9e7d5aa Compare October 15, 2026 18:04
@janickm

janickm commented Oct 15, 2026

Copy link
Copy Markdown
Collaborator Author

/ok to test 9e7d5aa

@janickm janickm left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Running something like

bazel run //tools:ncore_export_camera --
--output-dir=/tmp/img_orig
--camera-id=camera_front_wide_120fov
--step-frame=1
--timestamp-image-names
--encode-video
#--rectify
#--rectify-fov-factor=1.4
v4
--component-group=/tmp/pai/pai_4f14b8f4-4c16-48ce-aa42-02add7cd9f4d/pai_4f14b8f4-4c16-48ce-aa42-02add7cd9f4d.json

on a non-existing .json it seems like there is a directory created and then we fail with

backend_zarr3.py", line 426, in open_root_group
raise KeyError(V2_CONSOLIDATED_METADATA_KEY)
KeyError: '.zmetadata.cbor.xz'

rather, we should fail to open with a proper error message

Comment thread ncore/impl/data/itar.py
Comment thread ncore/impl/data/itar.py Outdated
Comment thread ncore/impl/data/backend.py
Comment thread ncore/impl/data/backend_zarr3.py
Comment thread ncore/impl/data/backend_zarr3.py
Comment thread ncore/impl/data/backend_zarr3.py Outdated
Comment thread ncore/impl/data/backend_zarr3.py
Comment thread ncore/impl/data/backend_zarr3.py Outdated
@janickm
janickm force-pushed the stack/zarr3/04-zarr-python-3 branch from 9e7d5aa to b3835fc Compare October 16, 2026 13:23
@janickm

janickm commented Oct 16, 2026

Copy link
Copy Markdown
Collaborator Author

/ok to test b3835fc

@janickm

janickm commented Oct 16, 2026

Copy link
Copy Markdown
Collaborator Author

Re running ncore_export_camera on a missing .json: Fixed. SequenceComponentGroupsReader now raises FileNotFoundError for a component store path that doesn't exist, before opening it. With zarr-python 3, LocalStore opened in write mode had created the directory and then failed on the missing consolidated metadata. Added TestMissingComponentStores for .zarr.itar, .zarr and .json paths, which also checks that nothing gets created.

Comment thread ncore/impl/data/backend.py Outdated
@janickm
janickm marked this pull request as ready for review October 16, 2026 13:36
@janickm
janickm force-pushed the stack/zarr3/04-zarr-python-3 branch from b3835fc to b3ccd65 Compare October 16, 2026 13:37
@janickm

janickm commented Oct 16, 2026

Copy link
Copy Markdown
Collaborator Author

/ok to test b3ccd65

@janickm
janickm force-pushed the stack/zarr3/04-zarr-python-3 branch from b3ccd65 to 8ef4526 Compare October 19, 2026 08:56
@janickm

janickm commented Oct 19, 2026

Copy link
Copy Markdown
Collaborator Author

/ok to test 8ef4526

@janickm
janickm force-pushed the stack/zarr3/04-zarr-python-3 branch from 8ef4526 to 3296db7 Compare October 19, 2026 11:52
@janickm

janickm commented Oct 19, 2026

Copy link
Copy Markdown
Collaborator Author

/ok to test 3296db7

Support zarr-python 3 (>= 3.1.4) next to zarr-python 2 for zarr format
v2 data. The zarr-python version specific operations of nodes and
stores are implemented by a zarr-python 3 backend (backend_zarr3.py),
which is selected at import time:

- zarr-python's coroutines run on an event loop owned by the calling
  thread (offloaded codec work runs inline), avoiding thread hand-offs
  to zarr-python's I/O thread per access. Forked processes create new
  loops, coroutines within running event loops run on zarr-python's
  I/O loop
- a zarr-python 3 store of indexed tar archives; complete reads of
  arrays of archives stored as a single uncompressed chunk are views of
  the chunk record (no copies), as with zarr-python 2
- consolidated hierarchies are opened from the decoded compressed
  consolidated metadata (no node metadata reads), with node metadata
  ordered by parent group (zarr-python < 3.4 attaches members of a
  group to its first run of keys only, zarr-python#4226)

Data written with zarr-python 2 and 3 is equivalent: chunk records are
byte-identical, node metadata documents are equivalent JSON.

zarr-python 3 rewrites node metadata on every update of a node, which
the write-once records of indexed tar archives don't support. Node
metadata records of archives opened for writing are now kept in memory
and appended when closing the archive (parents first), independent of
the zarr-python version.

Test environments: python 3.11 uses zarr-python 3.1.4 (the oldest
supported version), python 3.13 zarr-python 3.4, python 3.8 / 3.12
zarr-python 2. Type checking runs against zarr-python 3 (the zarr-python
2 backend is exempt from unresolved zarr-python 2 APIs).

BREAKING CHANGE: node metadata records of indexed tar archives are
appended when closing archives (after all chunk records), so archives
are no longer byte-identical to archives written by ncore 19.8 (their
records are).
@janickm
janickm force-pushed the stack/zarr3/04-zarr-python-3 branch from 3296db7 to 050e595 Compare October 19, 2026 11:58
@janickm

janickm commented Oct 19, 2026

Copy link
Copy Markdown
Collaborator Author

/ok to test 050e595

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant