Skip to content

Commit

Permalink
FIX: correct handling of EnumType on dtype creation
Browse files Browse the repository at this point in the history
  • Loading branch information
kmuehlbauer committed Sep 18, 2024
1 parent 9ec8aba commit 3681224
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions xarray/backends/h5netcdf_.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,18 +228,24 @@ def open_store_variable(self, name, var):
encoding["source"] = self._filename
encoding["original_shape"] = data.shape

print("XX", var)

vlen_dtype = h5py.check_dtype(vlen=var.dtype)
if vlen_dtype is str:
encoding["dtype"] = str
elif vlen_dtype is not None: # pragma: no cover
# xarray doesn't support writing arbitrary vlen dtypes yet.
pass
elif isinstance(var.datatype, h5netcdf.core.EnumType):
# just check if datatype is available and create dtype
# this check can be removed if h5netcdf >= 1.4.0 for any environment
elif (datatype := getattr(var, "datatype", None)) and isinstance(
datatype, h5netcdf.core.EnumType
):
encoding["dtype"] = np.dtype(
data.dtype,
metadata={
"enum": var.datatype.enum_dict,
"enum_name": var.datatype.name,
"enum": datatype.enum_dict,
"enum_name": datatype.name,
},
)
else:
Expand Down

0 comments on commit 3681224

Please sign in to comment.