Skip to content

Commit

Permalink
MNT: prepare h5netcdf backend for (coming) change in dimension handli…
Browse files Browse the repository at this point in the history
…ng (#6200)

* prepare h5netcdf backend for (coming) change in dimension handling

* [test-upstream]
  • Loading branch information
kmuehlbauer committed Jan 29, 2022
1 parent 9b8cba4 commit 5470d93
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions xarray/backends/h5netcdf_.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,11 @@ def _read_attributes(h5netcdf_var):


_extract_h5nc_encoding = functools.partial(
_extract_nc4_variable_encoding, lsd_okay=False, h5py_okay=True, backend="h5netcdf"
_extract_nc4_variable_encoding,
lsd_okay=False,
h5py_okay=True,
backend="h5netcdf",
unlimited_dims=None,
)


Expand Down Expand Up @@ -231,12 +235,24 @@ def get_attrs(self):
return FrozenDict(_read_attributes(self.ds))

def get_dimensions(self):
return self.ds.dimensions
if Version(h5netcdf.__version__) >= Version("0.14.0.dev0"):
return FrozenDict((k, len(v)) for k, v in self.ds.dimensions.items())
else:
return self.ds.dimensions

def get_encoding(self):
return {
"unlimited_dims": {k for k, v in self.ds.dimensions.items() if v is None}
}
if Version(h5netcdf.__version__) >= Version("0.14.0.dev0"):
return {
"unlimited_dims": {
k for k, v in self.ds.dimensions.items() if v.isunlimited()
}
}
else:
return {
"unlimited_dims": {
k for k, v in self.ds.dimensions.items() if v is None
}
}

def set_dimension(self, name, length, is_unlimited=False):
if is_unlimited:
Expand Down

0 comments on commit 5470d93

Please sign in to comment.