-
Notifications
You must be signed in to change notification settings - Fork 4
Fix zarr ZipStore write failure for large trees (v0.2.6) #86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
8740b50
Fix zarr ZipStore write failure for large trees
colganwi 0566fc5
Move _write_zarr_via_memory before write_zarr
colganwi 8f7a195
zarr format without awkward arrays
colganwi 32f8d27
Merge branch 'main' into fix/zarr-zipstore-large-trees
colganwi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,3 +30,7 @@ __pycache__/ | |
|
|
||
| # Environment | ||
| environment.yml | ||
|
|
||
| # Development | ||
| /dev/ | ||
| CLAUDE.md | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| # On-disk format | ||
|
|
||
| TreeData is written to `.h5td` (HDF5) and `.zarr` stores using the same | ||
| hierarchical, self-describing layout as AnnData. A TreeData file **is** an | ||
| AnnData file with a few extra top-level elements, so almost everything is | ||
| covered by the [AnnData on-disk format][anndata-format] — read that first. This | ||
| page documents only what TreeData adds. | ||
|
|
||
| [anndata-format]: https://anndata.scverse.org/en/stable/fileformat-prose.html | ||
|
|
||
| ## Top-level | ||
|
|
||
| The root group carries `encoding-type: "treedata"` and, in addition to the | ||
| standard AnnData elements (`X`, `obs`, `var`, `obsm`, `uns`, …), stores: | ||
|
|
||
| | Element | Type | Description | | ||
| | --- | --- | --- | | ||
| | `label` | scalar (string) or absent | Column in `obs`/`var` that holds each node's tree key | | ||
| | `allow_overlap` | scalar (bool) | Whether trees may share nodes | | ||
| | `alignment` | scalar (string) | One of `leaves`, `nodes`, `subset` | | ||
| | `obst` | see below | Trees aligned to observations | | ||
| | `vart` | see below | Trees aligned to variables | | ||
|
|
||
| `obst` and `vart` are mappings of a key to a :class:`networkx.DiGraph`. They are | ||
| the only elements stored differently from AnnData, and the layout depends on the | ||
| backend. | ||
|
|
||
| ## Trees in HDF5 (`.h5td`) | ||
|
|
||
| Each of `obst`/`vart` is stored as a **single JSON string** dataset mapping tree | ||
| key → `{"nodes": {...}, "edges": {...}}`, with node and edge attributes inline: | ||
|
|
||
| ```json | ||
| {"tree1": {"nodes": {"root": {"depth": 0}, "0": {}}, | ||
| "edges": {"root": {"0": {"length": 1.5}}}}} | ||
| ``` | ||
|
|
||
| ## Trees in zarr | ||
|
|
||
| zarr cannot store a single arbitrarily large string, so each of `obst`/`vart` is | ||
| a **group** with one subgroup per tree, stored columnar: | ||
|
|
||
| ``` | ||
| obst/ | ||
| tree1/ | ||
| nodes # 1-D array of node IDs | ||
| edges # (n_edges, 2) array of (source, target) pairs | ||
| node_attrs/ # one array per node-attribute key (optional) | ||
| depth | ||
| characters | ||
| edge_attrs/ # one array per edge-attribute key (optional) | ||
| length | ||
| ``` | ||
|
|
||
| The number of arrays scales with the number of **attribute keys**, not the | ||
| number of nodes. | ||
|
|
||
| Each attribute column has one entry per node (or edge), in the order of `nodes` | ||
| (or `edges`), and is encoded one of two ways: | ||
|
|
||
| - **Native** — a dense column whose values are all a single numeric or boolean | ||
| type is stored with the corresponding native array dtype (e.g. `int64`, | ||
| `float64`, `bool`). | ||
| - **JSON** — any other column (strings, ragged/nested values, mixed types, | ||
| columns missing from some nodes) is stored as a string array of per-element | ||
| JSON. The empty string `""` marks an absent attribute, so a value explicitly | ||
| set to `null` is preserved and kept distinct from a missing one. | ||
|
|
||
| :::{note} | ||
| zarr files written before treedata 0.3.0 stored `obst`/`vart` as a single JSON | ||
| string (as in HDF5). Such files are still read correctly; the format is detected | ||
| at read time. | ||
| ::: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This writes into
obst/vartwithrequire_groupbut never removes existing child groups that are no longer present intrees. When users pass an existingzarr.Groupand rewrite data, deleted trees remain on disk and are still returned byread_zarr, so the persisted tree set can diverge from the in-memoryTreeDatabeing written.Useful? React with 👍 / 👎.