Skip to content

fix: accept uint8 dtype aliases in Zarr v2 - #4381

Merged
d-v-b merged 3 commits into
zarr-developers:mainfrom
guhou-hvi:fix/uint8-dtype-aliases
Sep 23, 2026
Merged

d-v-b merged 3 commits into
zarr-developers:mainfrom
guhou-hvi:fix/uint8-dtype-aliases

Conversation

@guhou-hvi

Copy link
Copy Markdown
Contributor

Summary

Addresses #3622.

A single-byte element has no internal byte ordering, so <u1, >u1 and
|u1 can describe the same uint8 data. Currently only |u1 is registered
as a UInt8 v2 name: the stored bytes are valid, but metadata parsing rejects
the two aliases and prevents the array from opening.

This accepts both aliases while keeping |u1 as the serialized name.

For reviewers

The implementation extends only the accepted UInt8 v2 names. <u1 and >u1
are accepted on input, while serialization remains |u1. Tests cover dtype
and registry parsing, reading local arrays containing [0, 128, 255],
canonical serialization, unchanged on-disk metadata after read-only access,
and rejection of invalid names and object codecs. Other dtypes and v3 are unchanged.

Local validation run by Codex on Windows with Python 3.12.2:

  • Selected dtype, registry, v2 metadata and array modules: 2978 passed, 758 skipped.
  • Ruff, formatting, spelling, docstring checks and changelog draft build passed.
  • Native Windows mypy reports two existing unused-ignore errors in
    tests/test_store/test_local.py, reproduced on main in the same environment.
    mypy --platform linux passes for 196 files; this is type analysis, not a Linux runtime test.

Codex implemented the code, tests and changelog, ran the local checks, and
translated and polished my explanation, and prepared the validation notes. A separate Codex agent performed a static review.
I have reviewed and understand the changes.

Author attestation

  • I am a human, these are my changes, and I have reviewed and understood every change and can explain why each is correct.

TODO

  • Add unit tests and/or doctests in docstrings
  • Add docstrings and API docs for any new/modified user-facing classes and functions — no new API
  • New/modified features documented in docs/user-guide/*.md — bug fix; changelog added
  • Changes documented as a new file in changes/
  • GitHub Actions have all passed
  • Test coverage is 100% (Codecov passes)

@codecov

codecov Bot commented Sep 20, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.22%. Comparing base (7291469) to head (d42ab76).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4381   +/-   ##
=======================================
  Coverage   94.22%   94.22%           
=======================================
  Files          92       92           
  Lines       12942    12942           
=======================================
  Hits        12195    12195           
  Misses        747      747           
Files with missing lines Coverage Δ
src/zarr/core/dtype/npy/int.py 99.38% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@d-v-b
d-v-b merged commit c2451b3 into zarr-developers:main Sep 23, 2026
39 checks passed
d-v-b added a commit that referenced this pull request Sep 23, 2026
…names (#4385)

* fix(dtype): accept any byte order for byte-order-irrelevant v2 dtype names

Zarr V2 data type names are NumPy typestrs, whose first character is the
byte order ("<", ">", or "|" for not relevant). For single-byte booleans
and integers and for raw bytes the byte order is not relevant, so "<i1",
">b1", "<V4" etc. name the same data type as the "|" spelling. Other
implementations write these (netCDF-C, Zarr.jl, jzarr), and zarr-python
has rejected them since 3.1.

The data type registry now retries a v2 name that fails to match with its
canonical "|" spelling. The name as written is tried first, so a data type
that declares a non-canonical spelling keeps it. This replaces the
UInt8-only aliases from #4381, keeping the normalization invisible to the
data type classes, and covers structured fields.

Fixed-length bytes ("S") are left out: NCZarr gives ">S1" a meaning of its
own, and a dedicated data type for it will land first.

Tests: the invalid_json_v2/_v3 fixtures of BaseTestZDType are now consumed,
and their v2 entries have the v2 data type shape so they fail for their
contents. This found two bugs, fixed here: datetime64/timedelta64 accepted
a v2 object codec, and a structured data type with an unknown field data
type raised ValueError instead of DataTypeValidationError.

Assisted-by: ClaudeCode:claude-opus-5-5

* docs: add changelog fragment

Assisted-by: ClaudeCode:claude-opus-5-5

* refactor(dtype): enumerate v2 byte order aliases; add check_dtype_spec_no_object_codec_v2

Review follow-ups:

- The byte order aliases are an explicit table of the single-byte data
  types' non-canonical spellings, plus an explicit list of the
  fixed-length bytes kinds, in place of a regular expression.
- check_dtype_spec_no_object_codec_v2 (exported from zarr.dtype) checks a
  Zarr V2 data type without an object codec. Every data type that is not
  stored as a NumPy object uses it, so omitting the object codec check (as
  datetime64/timedelta64 did) is no longer possible by construction. The
  custom data type example uses it too.

Assisted-by: ClaudeCode:claude-opus-5-5

* refactor(dtype): return the v2 spellings to match instead of an optional alias

_v2_spellings returns the spellings of a v2 data type JSON in the order
they are matched (as written, then canonical), so match_json has no None
to check and the precedence rule lives in one place.

Assisted-by: ClaudeCode:claude-opus-5-5

* refactor(dtype): make _v2_canonical_name total

Every v2 data type name has a canonical spelling: the "|" spelling for a
byte order that is not relevant, and the name as written otherwise. The
function returns it instead of None, and _v2_spellings adds the canonical
spelling when it differs from the name as written.

Assisted-by: ClaudeCode:claude-opus-5-5
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.

2 participants