|
20 | 20 | from zarr_cm import multiscales as multiscales_cm |
21 | 21 | from zarr_cm import spatial as spatial_cm |
22 | 22 |
|
| 23 | +from eopf_geozarr.conversion import utils |
23 | 24 | from eopf_geozarr.conversion.fs_utils import sanitize_dataset_attributes |
24 | 25 | from eopf_geozarr.conversion.geozarr import ( |
25 | 26 | _create_tile_matrix_limits, |
@@ -862,9 +863,15 @@ def create_original_encoding(dataset: xr.Dataset) -> dict[str, XarrayDataArrayEn |
862 | 863 | var_data = dataset.data_vars[var_name] |
863 | 864 | var_encoding: XarrayDataArrayEncoding = {} |
864 | 865 | var_encoding["compressors"] = (compressor,) |
865 | | - for key in XARRAY_ENCODING_KEYS - {"compressors"}: |
| 866 | + for key in XARRAY_ENCODING_KEYS - {"compressors", "fill_value"}: |
866 | 867 | if key in var_data.encoding: |
867 | 868 | var_encoding[key] = var_data.encoding[key] # type: ignore[literal-required] |
| 869 | + # Set the zarr-level `fill_value` explicitly rather than letting xarray |
| 870 | + # decide — different xarray versions infer different defaults from the |
| 871 | + # variable's `_FillValue`. See `explicit_fill_value` for the rationale. |
| 872 | + fv = utils.explicit_fill_value(var_data) |
| 873 | + if fv is not utils.UNSET: |
| 874 | + var_encoding["fill_value"] = fv |
868 | 875 | if len(set(var_data.encoding.keys()) - XARRAY_ENCODING_KEYS) > 0: |
869 | 876 | log.warning( |
870 | 877 | "Unknown encoding keys in %s: %s", |
|
0 commit comments