Skip to content

Commit ea460d4

Browse files
committed
read fill value with new datatypes
1 parent 2c40977 commit ea460d4

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

xarray/backends/zarr.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import numpy as np
1111
import pandas as pd
12+
from packaging.version import Version
1213

1314
from xarray import coding, conventions
1415
from xarray.backends.chunks import grid_rechunk, validate_grid_chunks_alignment
@@ -819,10 +820,24 @@ def open_store_variable(self, name):
819820
if zarr_array.fill_value is not None:
820821
attributes["_FillValue"] = zarr_array.fill_value
821822
elif "_FillValue" in attributes:
822-
attributes["_FillValue"] = FillValueCoder.decode(
823-
attributes["_FillValue"], zarr_array.dtype
824-
)
823+
# TODO update version check for the released version with dtypes
824+
# probably be 3.1
825+
import zarr
825826

827+
if Version(zarr.__version__) >= Version("3.0.6"):
828+
attributes["_FillValue"] = (
829+
# Use the new dtype infrastructure instead of doing xarray
830+
# specific fill value decoding
831+
zarr_array.metadata.data_type.from_json_value(
832+
attributes["_FillValue"],
833+
zarr_format=zarr_array.metadata.zarr_format,
834+
)
835+
)
836+
else:
837+
original_zarr_dtype = zarr_array.metadata.data_type
838+
attributes["_FillValue"] = FillValueCoder.decode(
839+
attributes["_FillValue"], original_zarr_dtype.value
840+
)
826841
return Variable(dimensions, data, attributes, encoding)
827842

828843
def get_variables(self):
@@ -1070,10 +1085,6 @@ def _create_new_array(
10701085
if c in encoding:
10711086
encoding["config"][c] = encoding.pop(c)
10721087

1073-
print(fill_value)
1074-
print(encoding)
1075-
print(dtype)
1076-
print(shape)
10771088
zarr_array = self.zarr_group.create(
10781089
name,
10791090
shape=shape,

0 commit comments

Comments
 (0)