Skip to content

Commit 328d178

Browse files
committed
update reading fill values to new dtypes
1 parent 70a7e8b commit 328d178

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

xarray/backends/zarr.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -885,19 +885,19 @@ def open_store_variable(self, name):
885885
# probably be 3.1
886886
import zarr
887887

888+
#
888889
if Version(zarr.__version__) >= Version("3.0.6"):
889890
attributes["_FillValue"] = (
890891
# Use the new dtype infrastructure instead of doing xarray
891892
# specific fill value decoding
892-
zarr_array.metadata.data_type.from_json_value(
893+
FillValueCoder.decode(
893894
attributes["_FillValue"],
894-
zarr_format=zarr_array.metadata.zarr_format,
895+
zarr_array.metadata.data_type.to_native_dtype(),
895896
)
896897
)
897898
else:
898-
original_zarr_dtype = zarr_array.metadata.data_type
899899
attributes["_FillValue"] = FillValueCoder.decode(
900-
attributes["_FillValue"], original_zarr_dtype.value
900+
attributes["_FillValue"], zarr_array.metadata.data_type.value
901901
)
902902

903903
return Variable(dimensions, data, attributes, encoding)
@@ -1015,6 +1015,7 @@ def store(
10151015
variables_encoded, attributes = self.encode(
10161016
{vn: variables[vn] for vn in new_variable_names}, attributes
10171017
)
1018+
print(f"{variables_encoded=}")
10181019

10191020
if existing_variable_names:
10201021
# We make sure that values to be appended are encoded *exactly*
@@ -1067,6 +1068,7 @@ def store(
10671068
else:
10681069
variables_to_set = variables_encoded
10691070

1071+
print(f"{variables_to_set=}")
10701072
self.set_variables(
10711073
variables_to_set, check_encoding_set, writer, unlimited_dims=unlimited_dims
10721074
)
@@ -1075,6 +1077,7 @@ def store(
10751077
if _zarr_v3():
10761078
kwargs["zarr_format"] = self.zarr_group.metadata.zarr_format
10771079
zarr.consolidate_metadata(self.zarr_group.store, **kwargs)
1080+
print("DONE STORE.STORE")
10781081

10791082
def sync(self):
10801083
pass
@@ -1124,6 +1127,7 @@ def _open_existing_array(self, *, name) -> ZarrArray:
11241127
def _create_new_array(
11251128
self, *, name, shape, dtype, fill_value, encoding, attrs
11261129
) -> ZarrArray:
1130+
# STRING ERROR FOR OBJECT HERE
11271131
if coding.strings.check_vlen_dtype(dtype) is str:
11281132
dtype = str
11291133

@@ -1147,6 +1151,8 @@ def _create_new_array(
11471151
if c in encoding:
11481152
encoding["config"][c] = encoding.pop(c)
11491153

1154+
print("create")
1155+
print(dtype)
11501156
zarr_array = self.zarr_group.create(
11511157
name,
11521158
shape=shape,
@@ -1253,6 +1259,8 @@ def set_variables(self, variables, check_encoding_set, writer, unlimited_dims=No
12531259

12541260
encoding["overwrite"] = True if self._mode == "w" else False
12551261

1262+
print(dtype)
1263+
print(";sdf")
12561264
zarr_array = self._create_new_array(
12571265
name=name,
12581266
dtype=dtype,
@@ -1261,6 +1269,8 @@ def set_variables(self, variables, check_encoding_set, writer, unlimited_dims=No
12611269
encoding=encoding,
12621270
attrs=encoded_attrs,
12631271
)
1272+
print(zarr_array)
1273+
print(type(zarr_array))
12641274

12651275
writer.add(v.data, zarr_array, region)
12661276

0 commit comments

Comments
 (0)