|
9 | 9 |
|
10 | 10 | import numpy as np
|
11 | 11 | import pandas as pd
|
| 12 | +from packaging.version import Version |
12 | 13 |
|
13 | 14 | from xarray import coding, conventions
|
14 | 15 | from xarray.backends.chunks import grid_rechunk, validate_grid_chunks_alignment
|
@@ -819,10 +820,24 @@ def open_store_variable(self, name):
|
819 | 820 | if zarr_array.fill_value is not None:
|
820 | 821 | attributes["_FillValue"] = zarr_array.fill_value
|
821 | 822 | 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 |
825 | 826 |
|
| 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 | + ) |
826 | 841 | return Variable(dimensions, data, attributes, encoding)
|
827 | 842 |
|
828 | 843 | def get_variables(self):
|
@@ -1070,10 +1085,6 @@ def _create_new_array(
|
1070 | 1085 | if c in encoding:
|
1071 | 1086 | encoding["config"][c] = encoding.pop(c)
|
1072 | 1087 |
|
1073 |
| - print(fill_value) |
1074 |
| - print(encoding) |
1075 |
| - print(dtype) |
1076 |
| - print(shape) |
1077 | 1088 | zarr_array = self.zarr_group.create(
|
1078 | 1089 | name,
|
1079 | 1090 | shape=shape,
|
|
0 commit comments