xarray
xarray copied to clipboard
fix: skip CF encoding for zarr arrays with native DateTime64 dtype (GH#11350)
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
- : Skip CF encoding for existing zarr arrays with native datetime64 dtype
- : Add regression test
Testing
- Regression test passes
- All 172 datetime/timedelta tests pass
- All 387 TestZarrDictStore tests pass
Fixes #11350