Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions xarray/backends/zarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ class FillValueCoder:
"""

@classmethod
def encode(cls, value: int | float | str | bytes, dtype: np.dtype[Any]) -> Any:
def encode(
cls, value: int | float | complex | str | bytes, dtype: np.dtype[Any]
) -> Any:
if dtype.kind in "S":
# byte string, this implies that 'value' must also be `bytes` dtype.
assert isinstance(value, bytes)
Expand All @@ -132,16 +134,33 @@ def encode(cls, value: int | float | str | bytes, dtype: np.dtype[Any]) -> Any:
return bool(value)
elif dtype.kind in "iu":
# todo: do we want to check for decimals?
assert isinstance(value, int | float)
return int(value)
elif dtype.kind in "f":
assert isinstance(value, int | float)
return base64.standard_b64encode(struct.pack("<d", float(value))).decode()
elif dtype.kind in "c":
# complex - encode each component as base64, matching float encoding
assert isinstance(value, complex) or np.issubdtype(
type(value), np.complexfloating
)
return [
base64.standard_b64encode(
struct.pack("<d", float(value.real)) # type: ignore[union-attr]
).decode(),
base64.standard_b64encode(
struct.pack("<d", float(value.imag)) # type: ignore[union-attr]
).decode(),
]
elif dtype.kind in "U":
return str(value)
else:
raise ValueError(f"Failed to encode fill_value. Unsupported dtype {dtype}")

@classmethod
def decode(cls, value: int | float | str | bytes, dtype: str | np.dtype[Any]):
def decode(
cls, value: int | float | str | bytes | list, dtype: str | np.dtype[Any]
):
if dtype == "string":
# zarr V3 string type
return str(value)
Expand All @@ -153,9 +172,16 @@ def decode(cls, value: int | float | str | bytes, dtype: str | np.dtype[Any]):
if np_dtype.kind in "f":
assert isinstance(value, str | bytes)
return struct.unpack("<d", base64.standard_b64decode(value))[0]
elif np_dtype.kind in "c":
# complex - decode each component from base64, matching float decoding
assert isinstance(value, list | tuple) and len(value) == 2
real = struct.unpack("<d", base64.standard_b64decode(value[0]))[0]
imag = struct.unpack("<d", base64.standard_b64decode(value[1]))[0]
return complex(real, imag)
elif np_dtype.kind in "b":
return bool(value)
elif np_dtype.kind in "iu":
assert isinstance(value, int | float)
return int(value)
else:
raise ValueError(f"Failed to decode fill_value. Unsupported dtype {dtype}")
Expand Down
12 changes: 12 additions & 0 deletions xarray/tests/test_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -1129,7 +1129,7 @@
):
pytest.skip("uint8 data can't be written to non-NetCDF4 data")

with self.roundtrip(decoded) as actual:

Check failure on line 1132 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest | test-py313-no-numba

TestZarrDictStore.test_roundtrip_mask_and_scale[3-dtype0-create_masked_and_scaled_data-create_encoded_masked_and_scaled_data] AssertionError

Check failure on line 1132 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest | test-py313-no-numba

TestZarrDictStore.test_roundtrip_mask_and_scale[3-dtype0-create_signed_masked_scaled_data-create_encoded_signed_masked_scaled_data] AssertionError

Check failure on line 1132 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest | test-py313-no-numba

TestZarrDictStore.test_roundtrip_mask_and_scale[3-dtype0-create_unsigned_masked_scaled_data-create_encoded_unsigned_masked_scaled_data] AssertionError

Check failure on line 1132 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest | test-py311

TestZarrDictStore.test_roundtrip_mask_and_scale[3-dtype0-create_masked_and_scaled_data-create_encoded_masked_and_scaled_data] AssertionError

Check failure on line 1132 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest | test-py311

TestZarrDictStore.test_roundtrip_mask_and_scale[3-dtype0-create_signed_masked_scaled_data-create_encoded_signed_masked_scaled_data] AssertionError

Check failure on line 1132 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest | test-py311

TestZarrDictStore.test_roundtrip_mask_and_scale[3-dtype0-create_unsigned_masked_scaled_data-create_encoded_unsigned_masked_scaled_data] AssertionError

Check failure on line 1132 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest | test-py313

TestZarrDictStore.test_roundtrip_mask_and_scale[3-dtype0-create_masked_and_scaled_data-create_encoded_masked_and_scaled_data] AssertionError

Check failure on line 1132 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest | test-py313

TestZarrDictStore.test_roundtrip_mask_and_scale[3-dtype0-create_signed_masked_scaled_data-create_encoded_signed_masked_scaled_data] AssertionError

Check failure on line 1132 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest | test-py313

TestZarrDictStore.test_roundtrip_mask_and_scale[3-dtype0-create_unsigned_masked_scaled_data-create_encoded_unsigned_masked_scaled_data] AssertionError

Check failure on line 1132 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest | test-py313-no-dask

TestZarrDictStore.test_roundtrip_mask_and_scale[3-dtype0-create_masked_and_scaled_data-create_encoded_masked_and_scaled_data] AssertionError

Check failure on line 1132 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest | test-py313-no-dask

TestZarrDictStore.test_roundtrip_mask_and_scale[3-dtype0-create_signed_masked_scaled_data-create_encoded_signed_masked_scaled_data] AssertionError

Check failure on line 1132 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest | test-py313-no-dask

TestZarrDictStore.test_roundtrip_mask_and_scale[3-dtype0-create_unsigned_masked_scaled_data-create_encoded_unsigned_masked_scaled_data] AssertionError

Check failure on line 1132 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / macos-latest | test-py311

TestZarrDictStore.test_roundtrip_mask_and_scale[3-dtype0-create_masked_and_scaled_data-create_encoded_masked_and_scaled_data] AssertionError

Check failure on line 1132 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / macos-latest | test-py311

TestZarrDictStore.test_roundtrip_mask_and_scale[3-dtype0-create_signed_masked_scaled_data-create_encoded_signed_masked_scaled_data] AssertionError

Check failure on line 1132 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / macos-latest | test-py311

TestZarrDictStore.test_roundtrip_mask_and_scale[3-dtype0-create_unsigned_masked_scaled_data-create_encoded_unsigned_masked_scaled_data] AssertionError

Check failure on line 1132 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / macos-latest | test-py313

TestZarrDictStore.test_roundtrip_mask_and_scale[3-dtype0-create_masked_and_scaled_data-create_encoded_masked_and_scaled_data] AssertionError

Check failure on line 1132 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / macos-latest | test-py313

TestZarrDictStore.test_roundtrip_mask_and_scale[3-dtype0-create_signed_masked_scaled_data-create_encoded_signed_masked_scaled_data] AssertionError

Check failure on line 1132 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / macos-latest | test-py313

TestZarrDictStore.test_roundtrip_mask_and_scale[3-dtype0-create_unsigned_masked_scaled_data-create_encoded_unsigned_masked_scaled_data] AssertionError

Check failure on line 1132 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest | test-py313-with-typing

TestZarrDictStore.test_roundtrip_mask_and_scale[3-dtype0-create_masked_and_scaled_data-create_encoded_masked_and_scaled_data] AssertionError

Check failure on line 1132 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest | test-py313-with-typing

TestZarrDictStore.test_roundtrip_mask_and_scale[3-dtype0-create_signed_masked_scaled_data-create_encoded_signed_masked_scaled_data] AssertionError

Check failure on line 1132 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest | test-py313-with-typing

TestZarrDictStore.test_roundtrip_mask_and_scale[3-dtype0-create_unsigned_masked_scaled_data-create_encoded_unsigned_masked_scaled_data] AssertionError
for k in decoded.variables:
assert decoded.variables[k].dtype == actual.variables[k].dtype
# CF _FillValue is always on-disk type
Expand Down Expand Up @@ -1212,7 +1212,7 @@
encoded = Dataset({"x": ("t", sb, attributes)})
unsigned_dtype = np.dtype(f"u{sb.dtype.itemsize}")

with _roundtrip_with_warnings(decoded) as actual:

Check failure on line 1215 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest | test-py313-no-numba

TestZarrDictStore.test_roundtrip_unsigned[3--1-False] AssertionError

Check failure on line 1215 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest | test-py313-no-numba

TestZarrDictStore.test_roundtrip_unsigned[3-fill_value0-False] AssertionError

Check failure on line 1215 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest | test-py311

TestZarrDictStore.test_roundtrip_unsigned[3--1-False] AssertionError

Check failure on line 1215 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest | test-py311

TestZarrDictStore.test_roundtrip_unsigned[3-fill_value0-False] AssertionError

Check failure on line 1215 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest | test-py313

TestZarrDictStore.test_roundtrip_unsigned[3--1-False] AssertionError

Check failure on line 1215 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest | test-py313

TestZarrDictStore.test_roundtrip_unsigned[3-fill_value0-False] AssertionError

Check failure on line 1215 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest | test-py313-no-dask

TestZarrDictStore.test_roundtrip_unsigned[3--1-False] AssertionError

Check failure on line 1215 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest | test-py313-no-dask

TestZarrDictStore.test_roundtrip_unsigned[3-fill_value0-False] AssertionError

Check failure on line 1215 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / macos-latest | test-py311

TestZarrDictStore.test_roundtrip_unsigned[3--1-False] AssertionError

Check failure on line 1215 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / macos-latest | test-py311

TestZarrDictStore.test_roundtrip_unsigned[3-fill_value0-False] AssertionError

Check failure on line 1215 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / macos-latest | test-py313

TestZarrDictStore.test_roundtrip_unsigned[3--1-False] AssertionError

Check failure on line 1215 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / macos-latest | test-py313

TestZarrDictStore.test_roundtrip_unsigned[3-fill_value0-False] AssertionError

Check failure on line 1215 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest | test-py313-with-typing

TestZarrDictStore.test_roundtrip_unsigned[3--1-False] AssertionError

Check failure on line 1215 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest | test-py313-with-typing

TestZarrDictStore.test_roundtrip_unsigned[3-fill_value0-False] AssertionError
for k in decoded.variables:
assert decoded.variables[k].dtype == actual.variables[k].dtype
exp_fv = decoded.variables[k].encoding["_FillValue"]
Expand Down Expand Up @@ -1288,7 +1288,7 @@

def test_grid_mapping_and_bounds_are_not_coordinates_in_file(self) -> None:
original = self._create_cf_dataset()
with self.roundtrip(original, open_kwargs={"decode_coords": False}) as ds:

Check failure on line 1291 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest | test-py313-no-numba

TestZarrDictStore.test_grid_mapping_and_bounds_are_not_coordinates_in_file[3] AssertionError

Check failure on line 1291 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest | test-py311

TestZarrDictStore.test_grid_mapping_and_bounds_are_not_coordinates_in_file[3] AssertionError

Check failure on line 1291 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest | test-py313

TestZarrDictStore.test_grid_mapping_and_bounds_are_not_coordinates_in_file[3] AssertionError

Check failure on line 1291 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest | test-py313-no-dask

TestZarrDictStore.test_grid_mapping_and_bounds_are_not_coordinates_in_file[3] AssertionError

Check failure on line 1291 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / macos-latest | test-py311

TestZarrDictStore.test_grid_mapping_and_bounds_are_not_coordinates_in_file[3] AssertionError

Check failure on line 1291 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / macos-latest | test-py313

TestZarrDictStore.test_grid_mapping_and_bounds_are_not_coordinates_in_file[3] AssertionError

Check failure on line 1291 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest | test-py313-with-typing

TestZarrDictStore.test_grid_mapping_and_bounds_are_not_coordinates_in_file[3] AssertionError
assert ds.coords["latitude"].attrs["bounds"] == "latitude_bnds"
assert ds.coords["longitude"].attrs["bounds"] == "longitude_bnds"
assert "coordinates" not in ds["variable"].attrs
Expand All @@ -1296,7 +1296,7 @@

def test_coordinate_variables_after_dataset_roundtrip(self) -> None:
original = self._create_cf_dataset()
with self.roundtrip(original, open_kwargs={"decode_coords": "all"}) as actual:

Check failure on line 1299 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest | test-py313-no-numba

TestZarrDictStore.test_coordinate_variables_after_dataset_roundtrip[3] AssertionError

Check failure on line 1299 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest | test-py311

TestZarrDictStore.test_coordinate_variables_after_dataset_roundtrip[3] AssertionError

Check failure on line 1299 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest | test-py313

TestZarrDictStore.test_coordinate_variables_after_dataset_roundtrip[3] AssertionError

Check failure on line 1299 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest | test-py313-no-dask

TestZarrDictStore.test_coordinate_variables_after_dataset_roundtrip[3] AssertionError

Check failure on line 1299 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / macos-latest | test-py311

TestZarrDictStore.test_coordinate_variables_after_dataset_roundtrip[3] AssertionError

Check failure on line 1299 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / macos-latest | test-py313

TestZarrDictStore.test_coordinate_variables_after_dataset_roundtrip[3] AssertionError

Check failure on line 1299 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest | test-py313-with-typing

TestZarrDictStore.test_coordinate_variables_after_dataset_roundtrip[3] AssertionError
assert_identical(actual, original)

with self.roundtrip(original) as actual:
Expand All @@ -1321,7 +1321,7 @@
# xarray/tests/test_conventions.py::TestCFEncodedDataStore
# needs the to_dataset. The other backends should be fine
# without it.
with pytest.warns(

Check failure on line 1324 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest | test-py313-no-numba

TestZarrDictStore.test_grid_mapping_and_bounds_are_coordinates_after_dataarray_roundtrip[3] Failed: DID NOT WARN. No warnings of type (<class 'UserWarning'>,) were emitted. Emitted warnings: [].

Check failure on line 1324 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest | test-py311

TestZarrDictStore.test_grid_mapping_and_bounds_are_coordinates_after_dataarray_roundtrip[3] Failed: DID NOT WARN. No warnings of type (<class 'UserWarning'>,) were emitted. Emitted warnings: [].

Check failure on line 1324 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest | test-py313

TestZarrDictStore.test_grid_mapping_and_bounds_are_coordinates_after_dataarray_roundtrip[3] Failed: DID NOT WARN. No warnings of type (<class 'UserWarning'>,) were emitted. Emitted warnings: [].

Check failure on line 1324 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest | test-py313-no-dask

TestZarrDictStore.test_grid_mapping_and_bounds_are_coordinates_after_dataarray_roundtrip[3] Failed: DID NOT WARN. No warnings of type (<class 'UserWarning'>,) were emitted. Emitted warnings: [].

Check failure on line 1324 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / macos-latest | test-py311

TestZarrDictStore.test_grid_mapping_and_bounds_are_coordinates_after_dataarray_roundtrip[3] Failed: DID NOT WARN. No warnings of type (<class 'UserWarning'>,) were emitted. Emitted warnings: [].

Check failure on line 1324 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / macos-latest | test-py313

TestZarrDictStore.test_grid_mapping_and_bounds_are_coordinates_after_dataarray_roundtrip[3] Failed: DID NOT WARN. No warnings of type (<class 'UserWarning'>,) were emitted. Emitted warnings: [].

Check failure on line 1324 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest | test-py313-with-typing

TestZarrDictStore.test_grid_mapping_and_bounds_are_coordinates_after_dataarray_roundtrip[3] Failed: DID NOT WARN. No warnings of type (<class 'UserWarning'>,) were emitted. Emitted warnings: [].
UserWarning,
match=(
r"Variable\(s\) referenced in bounds not in variables: "
Expand Down Expand Up @@ -1423,7 +1423,7 @@
ds = Dataset({"x": ("y", np.arange(10.0))})

kwargs: dict[str, Any] = dict(encoding={"x": {"dtype": "f4"}})
with self.roundtrip(ds, save_kwargs=kwargs) as actual:

Check failure on line 1426 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest | test-py313-no-numba

TestZarrDictStore.test_encoding_kwarg[3] AssertionError

Check failure on line 1426 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest | test-py311

TestZarrDictStore.test_encoding_kwarg[3] AssertionError

Check failure on line 1426 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest | test-py313

TestZarrDictStore.test_encoding_kwarg[3] AssertionError

Check failure on line 1426 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest | test-py313-no-dask

TestZarrDictStore.test_encoding_kwarg[3] AssertionError

Check failure on line 1426 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / macos-latest | test-py311

TestZarrDictStore.test_encoding_kwarg[3] AssertionError

Check failure on line 1426 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / macos-latest | test-py313

TestZarrDictStore.test_encoding_kwarg[3] AssertionError

Check failure on line 1426 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest | test-py313-with-typing

TestZarrDictStore.test_encoding_kwarg[3] AssertionError
encoded_dtype = actual.x.encoding["dtype"]
# On OS X, dtype sometimes switches endianness for unclear reasons
assert encoded_dtype.kind == "f" and encoded_dtype.itemsize == 4
Expand Down Expand Up @@ -1506,7 +1506,7 @@
# Test default encoding for float:
ds = Dataset({"x": ("y", np.arange(10.0))})
kwargs = dict(encoding={"x": {"dtype": "f4"}})
with self.roundtrip(ds, save_kwargs=kwargs) as actual:

Check failure on line 1509 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest | test-py313-no-numba

TestZarrDictStore.test_default_fill_value[3] AssertionError

Check failure on line 1509 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest | test-py311

TestZarrDictStore.test_default_fill_value[3] AssertionError

Check failure on line 1509 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest | test-py313

TestZarrDictStore.test_default_fill_value[3] AssertionError

Check failure on line 1509 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest | test-py313-no-dask

TestZarrDictStore.test_default_fill_value[3] AssertionError

Check failure on line 1509 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest | test-py313-with-typing

TestZarrDictStore.test_default_fill_value[3] AssertionError
assert math.isnan(actual.x.encoding["_FillValue"])
assert ds.x.encoding == {}

Expand Down Expand Up @@ -7099,6 +7099,18 @@
assert actual3 == expected3


@requires_zarr
@pytest.mark.parametrize("dtype", [complex, np.complex64, np.complex128])
def test_fill_value_coder_complex(dtype) -> None:
"""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

encoded = FillValueCoder.encode(value, np.dtype(dtype))
decoded = FillValueCoder.decode(encoded, np.dtype(dtype))
np.testing.assert_equal(np.array(decoded, dtype=dtype), np.array(value))


@requires_zarr
def test_extract_zarr_variable_encoding() -> None:
var = xr.Variable("x", [1, 2])
Expand Down Expand Up @@ -7141,7 +7153,7 @@

m = fsspec.filesystem("memory")
mm = m.get_mapper("out1.zarr")
ds.to_zarr(mm) # old interface

Check failure on line 7156 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / macos-latest | test-py311

test_open_fsspec AssertionError

Check failure on line 7156 in xarray/tests/test_backends.py

View workflow job for this annotation

GitHub Actions / macos-latest | test-py313

test_open_fsspec AssertionError
ds0 = ds.copy()
# pd.to_timedelta returns ns-precision, but the example data is in second precision
# so we need to fix this
Expand Down
Loading