Skip to content

fix: compare metadata objects by JSON form#3999

Merged
d-v-b merged 2 commits into
zarr-developers:mainfrom
d-v-b:fix-metadata-eq
May 22, 2026
Merged

fix: compare metadata objects by JSON form#3999
d-v-b merged 2 commits into
zarr-developers:mainfrom
d-v-b:fix-metadata-eq

Conversation

@d-v-b
Copy link
Copy Markdown
Contributor

@d-v-b d-v-b commented May 22, 2026

this PR makes __eq__ and __hash__ use the JSON form of array / group metadata objects, which means two metadata objects with fill_value=NaN will compare as equal, because the string form of the fill value will be used in the comparison.

This change makes our metadata objects hashable on the string form of the JSON representation. We can use a simpler form of hashing in the future if we go all-in on immutable data structures like frozendict here.

(finally) closes #2929

d-v-b and others added 2 commits May 22, 2026 16:17
Frozen dataclass __eq__ compared fill_value directly, so two identical
metadata objects with a NaN fill value compared unequal (NaN != NaN under
IEEE 754). Compare the JSON-serialized form instead, which treats matching
NaN and infinite fill values as equal.

Fixes zarr-developers#2929

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@d-v-b d-v-b requested a review from dcherian May 22, 2026 14:36
@codecov
Copy link
Copy Markdown

codecov Bot commented May 22, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.49%. Comparing base (1907ad6) to head (1d76b83).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3999   +/-   ##
=======================================
  Coverage   93.49%   93.49%           
=======================================
  Files          88       88           
  Lines       11861    11873   +12     
=======================================
+ Hits        11089    11101   +12     
  Misses        772      772           
Files with missing lines Coverage Δ
src/zarr/core/metadata/v2.py 89.38% <100.00%> (+0.36%) ⬆️
src/zarr/core/metadata/v3.py 93.96% <100.00%> (+0.10%) ⬆️
🚀 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 c0e2afa into zarr-developers:main May 22, 2026
30 checks passed
@d-v-b d-v-b deleted the fix-metadata-eq branch May 22, 2026 16:07
@maxrjones
Copy link
Copy Markdown
Member

@d-v-b are you surprised by the codspeed analysis results from https://github.com/zarr-developers/zarr-python/runs/77699725053?

@d-v-b
Copy link
Copy Markdown
Contributor Author

d-v-b commented May 26, 2026

I am surprised! we should see if it's due to changes in this PR (which I doubt) or instead changes that we merged recently without a baseline benchmark.

@d-v-b
Copy link
Copy Markdown
Contributor Author

d-v-b commented May 26, 2026

the cause was loss of morton order caching in #3826, we should get our perf back when we bring back the caching

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.

Metadata comparison fails for NaN fill_values

4 participants