Repository navigation
fix: preserve non-canonical NaN payloads and distinguish -0.0 in v3 metadata - #4702
Open
barlowa124 wants to merge 6 commits into
Open
barlowa124 wants to merge 6 commits into
barlowa124 wants to merge 6 commits into
Conversation
…etadata float_from_json_v3 decoded hex strings through Python float64, which cannot carry a float16 payload and risks narrowing float32 payloads; decode into a same-width NumPy scalar via np.frombuffer instead. float_to_json_v3 flattened every NaN to "NaN" on write; emit the hex bit pattern for NaNs that are not the canonical positive NaN so the document round-trips the payload it parsed. ArrayV3Metadata.__eq__ compared to_dict() dictionaries, under which -0.0 == 0.0 and (before this change) any NaN payload == "NaN" even though the documents serialize differently. Compare the canonical serialized JSON text instead, which is also the exact form __hash__ already hashes, making the two consistent by construction. Partial fix for zarr-developers#4453
The strict bits==canonical check serialized float32 0xffc00000 as hex, but the canonical NaN designation covers the payload, not the sign; mask the sign bit so 0xffc00000 writes as "NaN" like the canonical form.
…s, key-order-free metadata equality
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Supersedes #4486, which GitHub auto-closed when the branch history was rewritten to remove tooling attribution.
Summary
Third item of #4453: float fill values holding non-canonical NaN
payloads did not round-trip, and
ArrayV3Metadata.__eq__conflateddocuments whose
fill_values serialize differently.Parse to serialize dropped NaN payloads.
"0x7fc00001"parsed fine,but
float_to_json_v3flattened every NaN to"NaN"on write. It nowemits the hex bit pattern for any NaN differing from the canonical
positive one, which is the case the spec's hex encoding names. The old
comment claiming NumPy cannot hold distinct NaNs was wrong. The
payload bits were being discarded on write, not absent. The canonical
check compares all NaN bits including sign, matching zarrs and
tensorstore. In the same place,
float_from_json_v3decoded hex intoPython's 64-bit
floatand narrowed float16/float32 payloads. Hexnow decodes through
np.frombufferinto a same-width scalar, so allthree widths round-trip.
Equality conflated distinct documents.
__eq__comparedto_dict()dictionaries, where negative zero equals positive zero and every NaN
equaled
"NaN".__eq__now comparesjson.dumps(to_dict(), sort_keys=True). That is the string__hash__already hashes, soequal implies equal-hash by construction.
For reviewers
float_from_json_v3returnsnp.floatingfor hex input rather thanfloat. Both call sites consume it through a cast orcomplex(), socallers see no change.
"NaN"still denotes the canonical positiveNaN per width. v2 serialization is untouched. Complex fills route
through the same helpers per component, so a complex64 real part with
a non-canonical payload now round-trips as hex as well. That path
was exercised but has no dedicated test. Payload bits survive only when the hex
width matches the dtype width, which the spec requires anyway.
Author attestation
TODO
Done:
changes/Outstanding:
docs/user-guide/*.md(no user-facing behavior beyond spec compliance)