diff --git a/h5netcdf/attrs.py b/h5netcdf/attrs.py index 326a0db..8f8a2ab 100644 --- a/h5netcdf/attrs.py +++ b/h5netcdf/attrs.py @@ -31,6 +31,7 @@ def __getitem__(self, key): if self._h5py.__name__ == "h5py": attr = self._h5attrs.get_id(key) else: + # pyfive backend attr = self._h5attrs[key] # handle Empty types @@ -66,11 +67,21 @@ def __getitem__(self, key): # transform string array to list if not np.isscalar(output): output = output.tolist() - - # return item if single element list/array - # see https://github.com/h5netcdf/h5netcdf/issues/116 - if not np.isscalar(output) and len(output) == 1: - return output[0] + else: + # pyfive backend: There is no '_h5py.check_string_dtype' + # method, but we only have to deal with + # the case of a numpy array of strings. + try: + if output.dtype == object: + # transform string array to list + output = output.tolist() + except AttributeError: + pass + + # return item if single element list/array see + # https://github.com/h5netcdf/h5netcdf/issues/116 + if not np.isscalar(output) and len(output) == 1: + return output[0] return output diff --git a/h5netcdf/core.py b/h5netcdf/core.py index 597f011..167912a 100644 --- a/h5netcdf/core.py +++ b/h5netcdf/core.py @@ -419,6 +419,7 @@ def __getitem__(self, key): # get padding padding = self._get_padding(key) + # apply padding with fillvalue (both api) if padding: fv = self.dtype.type(self._h5ds.fillvalue) diff --git a/h5netcdf/tests/test.nc b/h5netcdf/tests/test.nc index f2f0352..8e17d53 100644 Binary files a/h5netcdf/tests/test.nc and b/h5netcdf/tests/test.nc differ diff --git a/test.nc b/test.nc index f75f67a..2854d7f 100644 Binary files a/test.nc and b/test.nc differ