Repository navigation
Do not count the chunk keys of Zarr arrays towards the depth limit - #2008
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2008 +/- ##
==========================================
+ Coverage 91.29% 91.36% +0.07%
==========================================
Files 99 99
Lines 15877 15919 +42
==========================================
+ Hits 14495 14545 +50
+ Misses 1382 1374 -8
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
@yarikoptic-gitmate fight me on this |
yarikoptic-gitmate
left a comment
There was a problem hiding this comment.
The change is correct and does what it says, so approving; the remarks below are not blocking.
Where the limit came from (since #1919 asks whether it is still needed): it was not introduced for NWB, nor for chunk keys.
- Proposed in #852 (comment) (2021-12-16) as a guard against a Zarr's innards being uploaded as "thousands of assets which would only need to be removed", with a tentative N ("5?", possibly to be made an option), reasoned from dandiset layouts (
dandi organize: 1 level, BIDS: 4) rather than from anything inside a Zarr. - Implemented in ca049a1 (#853) as
MAX_ZARR_DEPTH = 5, applied inside an already recognised Zarr. - Raised to 7 in ae99630 (#984) for #983: the NGFF Zarrs of 000108 failed on chunk paths
0/0/0/0/0/0(resolution level + 5 dimensions with/as separator), and 7 was picked "for the moment" ("7 (even 6) should cover our current use cases"), on the reasoning that "we are limiting zarr to ngff files", with other kinds of Zarr left to "discuss in the future".
So the only change to the value was to make room for chunk keys, which this PR stops counting altogether. I found no depth limit in dandi-archive either: the only check it applies to Zarr entry paths (validate_zarr_path()) rejects .. segments, so this looks to be a client-side check only.
What I checked
Old vs new _is_too_deep() on stores written by zarr-python 3.4.2:
| Store | master | this PR |
|---|---|---|
#1919 reproducer (v3, a/b/c/d/series/data, 2D) |
too deep | ok |
v2, 5D, / separator, at labels/cells/0 |
too deep | ok |
v3, sharded 3D array whose path inside the Zarr has 6 components (g1/…/g5/data) |
too deep | ok |
| v3, 8D array at the root | too deep | ok |
v3, array whose path inside the Zarr has 7 components (g1/…/g6/data) |
too deep | too deep |
| directory without Zarr metadata holding a file with 8 path parts | too deep | too deep |
| non-chunk tree 9 levels deep below an array directory | too deep | ok |
The boundary outside arrays is unchanged (a file with MAX_ZARR_DEPTH + 1 path parts is still flagged), and the check no longer walks chunks: on a 64k-chunk array it went from 1.1 s to under 1 ms.
Remarks
- With chunk keys out, the limit measures group nesting only, which the original rationale (accidentally uploading a heavy tree as separate assets) does not motivate inside a recognised Zarr. It still rejects an array whose path inside the Zarr has 7 components (6 nested groups below the root, plus the array), which an NWB extension with nested containers could reach. #1919 asked to "remove it or exclude chunk coordinates"; it would be good to state here why the limit is kept, or to follow up by removing it or demoting it to a warning.
- Nothing below an array directory is inspected any more (last row of the table). Fine for the purpose, but worth a sentence in the docstring, which currently only speaks of chunks; the description's "Groups and other directories still count" likewise holds only outside arrays.
- The docstring says chunk keys "span as many directories as it has dimensions (plus one,
c)" (the description likewise), which overcounts by one:c/1/0of a 2D v3 array lies in 2 directories,1/0/0/0of a 4D v2 array in 3. "Have as many path components as the array has dimensions (plus a leadingcin v3)" would be exact. - Tests: the new test goes from "passes" straight to three more subgroups. Asserting that it still passes with
a/b(whose metadata file has 7 path parts, the most allowed outside arrays) would pin the boundary, and adding an array that is itself too deep (e.g.g1/…/g6/data) would exercise thereturn Truein the array branch, which no test reaches now (presumably the line Codecov reports as missed). - Counting, not new here: what is flagged is a file with more than
MAX_ZARR_DEPTHpath components, i.e. inside 7 or more nested directories. The error message, the new docstring and the test comment ("a file 8 directories deep") describe that as more than 7, or 8, directories deep; "path components" would be unambiguous.
Generated by Claude Code
|
@CodyCBakerPhD you have "my" blessing to merge unless you want to reflect on recommendations from the gitmate |
The chunk keys of an array span as many directories as it has dimensions (plus one, "c") with Zarr v3's default chunk key encoding (e.g. data/c/1/0), or with "/" as dimension separator in Zarr v2, so they do not tell how deep the Zarr hierarchy is. A Zarr with groups nested a few levels deep, such as an NWB file stored as Zarr v3, thus failed validation with dandi_zarr.tree_depth_exceeded. ZarrAsset._is_too_deep() now counts the chunks of an array as files directly in its directory, and does not list arrays at all (sparing listing their chunks). Groups and other directories still count. Fixes #1919 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DQrzw5ecrJY9QseLyohB4j
205c6eb to
ec7cbb1
Compare
We should determine that in a dedicated session doing its own logical justification and research; the current value is just a starting point |
I did find that interesting that the gitmate could actually formally grant approval |
So as not to change the imports of test_helpers, which other open pull requests change too, and which the zarr-publishing test setup merges: test_upload_discovery already imports mkpaths() from test_files. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DQrzw5ecrJY9QseLyohB4j
Fixes #1919.
The chunk keys of a Zarr array span as many directories as it has dimensions (plus
c) with Zarr v3's default chunk key encoding (data/c/1/0), or with/as dimension separator in Zarr v2. Because they were counted, a Zarr whose groups nest only a few levels deep, such as an NWB file stored as Zarr v3, failed validation withdandi_zarr.tree_depth_exceeded.ZarrAsset._is_too_deep()now counts an array's chunks as files directly in its directory, and no longer lists arrays at all (sparing listing their chunks). Groups and other directories still count.Split out of #1996, which builds on it.
Generated by Claude Code