Skip to content

Comments

Add complex dtype support to FillValueCoder for Zarr backend#11151

Open
maxrjones wants to merge 6 commits intopydata:mainfrom
maxrjones:complex_FillValue
Open

Add complex dtype support to FillValueCoder for Zarr backend#11151
maxrjones wants to merge 6 commits intopydata:mainfrom
maxrjones:complex_FillValue

Conversation

@maxrjones
Copy link
Contributor

This PR adds support for encoding/decoding complex fill values (complex64, complex128) in the Zarr backend's FillValueCoder, which previously raised ValueError for complex dtypes. This enables converting/virtualizing NetCDF files with these fill values to Zarr. As an example, this change unlocks virtualizing full NISAR granules using VirtualiZarr + Xarray.

Each component (real/imag) is base64-encoded as a little-endian double, consistent with how float fill values are already handled and ensuring safe JSON round-tripping of special values like NaN and Infinity.

  • Closes #xxxx
  • Tests added
  • User visible changes (including notable bug fixes) are documented in whats-new.rst
  • New functions/methods are listed in api.rst

@github-actions github-actions bot added topic-backends topic-zarr Related to zarr storage library io labels Feb 9, 2026
@maxrjones
Copy link
Contributor Author

@dcherian thanks for your review. Do I need to get mypy working for this PR to go into main? The failures are in the function that I worked on, but unrelated to the changes that I made.

"""Test that FillValueCoder round-trips complex fill values."""
from xarray.backends.zarr import FillValueCoder

for value in [dtype(1 + 2j), dtype(-3.5 + 4.5j), dtype(complex("nan+nanj"))]:
Copy link
Contributor

@dcherian dcherian Feb 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to test for infs here too i guess. A roundtrip property test in https://github.com/pydata/xarray/blob/main/properties/test_encode_decode.py would be nice. Are you up for it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good, I'll add that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

io topic-backends topic-zarr Related to zarr storage library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants