Skip to content

Commit 70a7e8b

Browse files
committed
read fill value with new datatypes
1 parent 7920054 commit 70a7e8b

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

xarray/backends/zarr.py

Lines changed: 19 additions & 8 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.common import (
@@ -880,10 +881,24 @@ def open_store_variable(self, name):
880881
if zarr_array.fill_value is not None:
881882
attributes["_FillValue"] = zarr_array.fill_value
882883
elif "_FillValue" in attributes:
883-
original_zarr_dtype = zarr_array.metadata.data_type
884-
attributes["_FillValue"] = FillValueCoder.decode(
885-
attributes["_FillValue"], original_zarr_dtype.value
886-
)
884+
# TODO update version check for the released version with dtypes
885+
# probably be 3.1
886+
import zarr
887+
888+
if Version(zarr.__version__) >= Version("3.0.6"):
889+
attributes["_FillValue"] = (
890+
# Use the new dtype infrastructure instead of doing xarray
891+
# specific fill value decoding
892+
zarr_array.metadata.data_type.from_json_value(
893+
attributes["_FillValue"],
894+
zarr_format=zarr_array.metadata.zarr_format,
895+
)
896+
)
897+
else:
898+
original_zarr_dtype = zarr_array.metadata.data_type
899+
attributes["_FillValue"] = FillValueCoder.decode(
900+
attributes["_FillValue"], original_zarr_dtype.value
901+
)
887902

888903
return Variable(dimensions, data, attributes, encoding)
889904

@@ -1132,10 +1147,6 @@ def _create_new_array(
11321147
if c in encoding:
11331148
encoding["config"][c] = encoding.pop(c)
11341149

1135-
print(fill_value)
1136-
print(encoding)
1137-
print(dtype)
1138-
print(shape)
11391150
zarr_array = self.zarr_group.create(
11401151
name,
11411152
shape=shape,

0 commit comments

Comments
 (0)