Skip to content

fix(dtype): write the generic time unit in brackets in Zarr format 2 metadata - #4581

Merged
d-v-b merged 5 commits into
zarr-developers:mainfrom
d-v-b:fix/v2-time-unit-brackets
Oct 29, 2026
Merged

d-v-b merged 5 commits into
zarr-developers:mainfrom
d-v-b:fix/v2-time-unit-brackets

Conversation

@d-v-b

@d-v-b d-v-b commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

Summary

We write invalid v2 dtype metadata for datetime / timedelta data. See #4580. This PR fixes that by ensuring that we always serialize dtype metadata with the unit enclosed in brackets, even for the "generic" unit.

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
  • New/modified features documented in docs/user-guide/*.md
  • Changes documented as a new file in changes/
  • GitHub Actions have all passed
  • Test coverage is 100% (Codecov passes)

d-v-b added 5 commits October 29, 2026 15:05
…metadata

The v2 spec requires the unit of a datetime64 or timedelta64 dtype in
brackets, but a generic-unit time dtype serialized as NumPy's unitless
typestr (<M8), which the spec forbids. The generic unit is now written
explicitly — <M8[generic], or <M8[2generic] with a scale, as scaled
generic units already were — which NumPy parses back to the same dtype.
The unitless spellings stay readable as the generic unit.

Fixes zarr-developers#4580

Assisted-by: ClaudeCode:claude-fable-5
Assisted-by: ClaudeCode:claude-fable-5
…ime types

The generic-unit bracketing moves to TimeDTypeBase._v2_name, which both
to_json implementations call, instead of being duplicated in each.

Assisted-by: ClaudeCode:claude-fable-5
… tests

The one-off unitless-time test becomes json_alias_v2_params on the
shared dtype test base: (alias, canonical) pairs asserting that reading
either spelling gives the same dtype and writing gives the canonical
one. The time types list the unitless generic spellings and NumPy's
microsecond alias; other types can list their aliases the same way.

Assisted-by: ClaudeCode:claude-fable-5
@d-v-b

d-v-b commented Oct 29, 2026

Copy link
Copy Markdown
Contributor Author

this is a simple bugfix that brings us into spec compliance (with the v2 spec) so I will self-merge this

@codecov

codecov Bot commented Oct 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.75%. Comparing base (bf0d231) to head (a85a0b7).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4581   +/-   ##
=======================================
  Coverage   94.75%   94.75%           
=======================================
  Files          94       94           
  Lines       13704    13704           
=======================================
  Hits        12985    12985           
  Misses        719      719           
Files with missing lines Coverage Δ
src/zarr/core/dtype/npy/time.py 98.91% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@d-v-b
d-v-b merged commit 0b053b2 into zarr-developers:main Oct 29, 2026
40 checks passed
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