Max Jones
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.

      Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Explore these features while you wait
      Complete general settings
      Bookmark and like published notes
      Write a few more notes
      Complete general settings
      Write a few more notes
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Zarr chunk/shard introspection what users want to know vs. what the API provides Status: written 2026-06-03, verified against zarr-python `main` (`3.2.2.dev40+gfe229107`) and the xarray `poc/unified-zarr-chunk-grid` branch. All example outputs below were produced by running the code, not inferred. ## Context Zarr v3.2.0 introduced rectilinear (variable-sized) chunk grids behind the `array.rectilinear_chunks` config flag. This split the formerly one-property world (`Array.chunks`) into a family of partially overlapping accessors: `.chunks`, `.shards`, `.read_chunk_sizes`, `.write_chunk_sizes`. Downstream consumers (xarray's zarr backend being the motivating case) need to answer a small set of questions about any array, and today some of those answers require exception handling or imports from `zarr.core` internals. This doc maps the questions to the API and lists concrete improvement proposals. ## The four array configurations | | Regular grid | Rectilinear grid | |---|---|---| | **Unsharded** | the classic case | chunk edges enumerated in metadata | | **Sharded** | regular outer shards, regular inner chunks | rectilinear outer shards, regular inner chunks (rectilinear *inner* chunks with sharding are rejected at creation: `"Rectilinear chunks with sharding"`) | ## Question matrix Each cell says how to get the answer, or why you can't. | What the user wants to know | Regular | Regular + sharded | Rectilinear | Rectilinear + sharded | |---|---|---|---|---| | **Declared chunk shape** (what was passed at creation, unclipped) | `.chunks` → `(30,)` | `.chunks` → inner chunk shape | n/a — no single shape; the declared edge listing is in metadata | n/a for outer; `.chunks` raises even though inner chunks are regular ⚠️ | | **Declared shard shape** (unclipped) | `.shards` → `None` | `.shards` → `(60,)` | `.shards` → `None` | **raises `NotImplementedError`** ⚠️ | | **Is the array sharded?** | `.shards is not None` | `.shards is not None` | `.shards is not None` | **unanswerable without `try/except`** — `.shards` raises ⚠️ | | **Is the chunk grid regular or rectilinear?** | **no public API** — either `try: .chunks / except NotImplementedError` or `isinstance(array.metadata.chunk_grid, RegularChunkGridMetadata)` with imports from `zarr.core.metadata.v3` ⚠️ | same | same | same | | **Per-chunk read sizes** (dask convention, clipped to extent, inner under sharding) | `.read_chunk_sizes` → `((30, 30, 30, 10),)` | `.read_chunk_sizes` → inner sizes | `.read_chunk_sizes` → `((10, 20, 30),)` | `.read_chunk_sizes` → inner sizes, e.g. `((10,)*12,)` | | **Per-storage-chunk sizes** (outer/shard granularity, clipped) | `.write_chunk_sizes` (= read sizes) | `.write_chunk_sizes` → `((60, 40),)` | `.write_chunk_sizes` (= read sizes) | `.write_chunk_sizes` → `((60, 40, 20),)` | | **Chunk boundaries/offsets** (for write-alignment validation) | `itertools.accumulate` over a sizes listing | same | same | same | | **Number of chunks per dimension** | `len()` of a sizes listing, or derive from shape and `.chunks` | same | same | same | | **Can I open/create this at all?** | always | always | requires `zarr.config.set({"array.rectilinear_chunks": True})` for both read and write; metadata parse raises otherwise | same | ⚠️ marks the cells where the API forces exception-driven control flow, internal imports, or has no answer. ## Key semantic distinctions (easy to get wrong) **Clipped vs. declared.** Both `read_chunk_sizes` and `write_chunk_sizes` clip boundary chunks to the array extent. The declared shape is only recoverable from `.chunks` / `.shards`. Verified examples: ```python zarr.create_array({}, shape=(5,), chunks=(100,), dtype="i4").read_chunk_sizes # ((5,),) — the declared 100 is gone zarr.create_array({}, shape=(100,), chunks=(30,), dtype="i4").read_chunk_sizes # ((30, 30, 30, 10),) zarr.create_array({}, shape=(100,), chunks=(10,), shards=(60,), dtype="i4").write_chunk_sizes # ((60, 40),) — declared (60,) clipped ``` Consequence for round-trips: a consumer that captures only the clipped listings and writes them back will change the on-disk declaration (e.g. chunk size 100 becomes 5 for a short array, and a regular grid with a partial final chunk becomes a rectilinear grid, since zarr's `ChunkGrid.from_sizes` only collapses uniform *full-coverage* edge lists to a regular grid). **Inner vs. outer under sharding.** `.chunks` and `read_chunk_sizes` report inner (read-granularity) chunks; `.shards` and `write_chunk_sizes` report outer (storage-granularity) shards. For unsharded arrays the two listings coincide, which means `read_chunk_sizes == write_chunk_sizes` cannot be used as a sharding test (a sharded array with one inner chunk per shard would also coincide). **`.shards` is tri-state.** `None` = unsharded, tuple = sharded regular, raise = sharded rectilinear. The `None`-ness doubles as the "is sharding enabled" signal, so the raise in the rectilinear case takes that signal down with it. ## Improvement proposals (zarr-side) Ordered roughly by value to downstream consumers. These fit naturally into the rectilinear stabilization window (the config flag is slated for removal within ~6 months of 3.2.0). 1. **Public grid-kind predicate.** `Array.is_regular_chunk_grid -> bool` (or expose the grid kind as an enum/property). Today the only options are catching `NotImplementedError` from `.chunks` or `isinstance` against `zarr.core.metadata.v3.RegularChunkGridMetadata`, which is not public API. Every consumer that supports both grid kinds needs this branch; none should need internal imports for it. 2. **Non-raising sharding predicate.** `Array.is_sharded -> bool`. Restores the "is sharding enabled" signal that `.shards` loses for rectilinear grids. The `.shards` raise itself is defensible (the return type cannot express varying shard sizes, mirroring `.chunks`), so add a predicate rather than change the raise. 3. **Declared (unclipped) sizes accessor.** Something like `Array.declared_chunk_sizes` / a public view of the chunk-grid declaration, so round-trip consumers can preserve on-disk declarations without stitching together `.chunks`, `.shards`, and two exception handlers. For rectilinear grids the listing is the declaration, so this is mostly about regular grids with partial or oversized boundary chunks. 4. **`.chunks` for sharded rectilinear arrays.** The inner chunk shape is regular in this configuration (rectilinear inner chunks are rejected with sharding), yet `.chunks` raises because the check is on the outer grid type. Arguably `.chunks` could answer with the inner chunk shape here; at minimum the error message could note that `read_chunk_sizes` gives the (regular) inner sizes. 5. **Flag-removal timeline.** Library consumers cannot reasonably ask their users to set `zarr.config.set({"array.rectilinear_chunks": True})`; xarray currently documents this requirement. Removing the flag (or providing a per-call opt-in) unblocks making rectilinear support transparent downstream. ## What this means for xarray (current consumer workarounds) - `open_store_variable` branches with `try: tuple(zarr_array.chunks) / except NotImplementedError: <sizes listing>` — would become an `is_regular_chunk_grid` check under proposal 1. - `encoding["shards"] = zarr_array.shards` is currently unguarded and crashes `open_zarr` on any sharded rectilinear store (verified end-to-end); the fix needs `try/except NotImplementedError → write_chunk_sizes`, which proposal 2 would reduce to a plain conditional. - `encoding["chunks"]` must come from `.chunks` for regular grids (declared shape, see clipping above) and from `read_chunk_sizes` for rectilinear grids; proposal 3 would collapse this to one accessor. - The `requires_zarr_rectilinear_chunks` test gate and the documented `zarr.config.set` requirement both disappear with proposal 5.

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password
    or
    Sign in via Google Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully