fix: skip CF encoding for zarr arrays with native DateTime64 dtype (GH#11350)#11419
Open
C1-BA-B1-F3 wants to merge 1 commit into
Open
fix: skip CF encoding for zarr arrays with native DateTime64 dtype (GH#11350)#11419C1-BA-B1-F3 wants to merge 1 commit into
C1-BA-B1-F3 wants to merge 1 commit into
Conversation
…H#11350) When writing to a zarr array with native DateTime64 dtype (zarr v3), skip CF datetime encoding. CF encoding converts datetime64 to int64 with units/calendar attributes, which corrupts data when written to a native DateTime64 zarr array — the int64 values get misinterpreted as raw epoch seconds instead of the encoded 'days since' values. Fixes pydata#11350
f92ddef to
d864330
Compare
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.
Problem
When writing a dataset back to a zarr store with native dtype (zarr v3), the datetime values get corrupted. For example, and become and .
Root Cause
The function applies CF datetime encoding which converts to with and attributes. When these values (e.g., for "days since 2025-01-01") are written to a zarr array, the array interprets them as raw epoch seconds, resulting in corrupted data.
Fix
In , detect when an existing zarr array has a native dtype (via ). For these arrays, skip CF encoding and write the raw values directly, since zarr handles the datetime storage natively.
Changes
Testing
Fixes #11350