Skip to content

Commit 90de115

Browse files
committed
update reading fill values to new dtypes
1 parent ea460d4 commit 90de115

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
@@ -824,19 +824,19 @@ def open_store_variable(self, name):
824824
# probably be 3.1
825825
import zarr
826826

827+
#
827828
if Version(zarr.__version__) >= Version("3.0.6"):
828829
attributes["_FillValue"] = (
829830
# Use the new dtype infrastructure instead of doing xarray
830831
# specific fill value decoding
831-
zarr_array.metadata.data_type.from_json_value(
832+
FillValueCoder.decode(
832833
attributes["_FillValue"],
833-
zarr_format=zarr_array.metadata.zarr_format,
834+
zarr_array.metadata.data_type.to_native_dtype(),
834835
)
835836
)
836837
else:
837-
original_zarr_dtype = zarr_array.metadata.data_type
838838
attributes["_FillValue"] = FillValueCoder.decode(
839-
attributes["_FillValue"], original_zarr_dtype.value
839+
attributes["_FillValue"], zarr_array.metadata.data_type.value
840840
)
841841
return Variable(dimensions, data, attributes, encoding)
842842

@@ -953,6 +953,7 @@ def store(
953953
variables_encoded, attributes = self.encode(
954954
{vn: variables[vn] for vn in new_variable_names}, attributes
955955
)
956+
print(f"{variables_encoded=}")
956957

957958
if existing_variable_names:
958959
# We make sure that values to be appended are encoded *exactly*
@@ -1005,6 +1006,7 @@ def store(
10051006
else:
10061007
variables_to_set = variables_encoded
10071008

1009+
print(f"{variables_to_set=}")
10081010
self.set_variables(
10091011
variables_to_set, check_encoding_set, writer, unlimited_dims=unlimited_dims
10101012
)
@@ -1013,6 +1015,7 @@ def store(
10131015
if _zarr_v3():
10141016
kwargs["zarr_format"] = self.zarr_group.metadata.zarr_format
10151017
zarr.consolidate_metadata(self.zarr_group.store, **kwargs)
1018+
print("DONE STORE.STORE")
10161019

10171020
def sync(self):
10181021
pass
@@ -1062,6 +1065,7 @@ def _open_existing_array(self, *, name) -> ZarrArray:
10621065
def _create_new_array(
10631066
self, *, name, shape, dtype, fill_value, encoding, attrs
10641067
) -> ZarrArray:
1068+
# STRING ERROR FOR OBJECT HERE
10651069
if coding.strings.check_vlen_dtype(dtype) is str:
10661070
dtype = str
10671071

@@ -1085,6 +1089,8 @@ def _create_new_array(
10851089
if c in encoding:
10861090
encoding["config"][c] = encoding.pop(c)
10871091

1092+
print("create")
1093+
print(dtype)
10881094
zarr_array = self.zarr_group.create(
10891095
name,
10901096
shape=shape,
@@ -1223,6 +1229,8 @@ def set_variables(
12231229

12241230
encoding["overwrite"] = self._mode == "w"
12251231

1232+
print(dtype)
1233+
print(";sdf")
12261234
zarr_array = self._create_new_array(
12271235
name=name,
12281236
dtype=dtype,
@@ -1231,6 +1239,8 @@ def set_variables(
12311239
encoding=encoding,
12321240
attrs=encoded_attrs,
12331241
)
1242+
print(zarr_array)
1243+
print(type(zarr_array))
12341244

12351245
writer.add(v.data, zarr_array, region)
12361246

0 commit comments

Comments
 (0)