Skip to content

Commit

Permalink
Handle missing fillvalue raised by gpm-imerg in #342.
Browse files Browse the repository at this point in the history
  • Loading branch information
sharkinsspatial committed Dec 14, 2024
1 parent 105b43d commit 887e1cf
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions virtualizarr/readers/hdf/hdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,20 @@ def _extract_attrs(h5obj: Union[Dataset, Group]):
attrs[n] = v
return attrs

@staticmethod
def _extract_fill_value(
fill_value: Union[np.ndarray, np.nan, np.generic, None],
) -> Union[int, float, None]:
if not fill_value:
return fill_value
if isinstance(fill_value, np.ndarray):
fillvalue = fill_value[0]
if np.isnan(fill_value):
fillvalue = float("nan")
if isinstance(fill_value, np.generic):
fillvalue = fill_value.item()
return fillvalue

@staticmethod
def _dataset_to_variable(path: str, dataset: Dataset) -> Optional[Variable]:
"""
Expand Down Expand Up @@ -279,12 +293,11 @@ def _dataset_to_variable(path: str, dataset: Dataset) -> Optional[Variable]:
else:
dtype = dataset.dtype
fill_value = dataset.fillvalue
if isinstance(fill_value, np.ndarray):
fill_value = fill_value[0]
if np.isnan(fill_value):
fill_value = float("nan")
if isinstance(fill_value, np.generic):
fill_value = fill_value.item()
try:
fill_value = dataset.fillvalue
except Exception:
fill_value = None
fill_value = HDFVirtualBackend._extract_fill_value(fill_value=fill_value)
filters = [codec.get_config() for codec in codecs]
zarray = ZArray(
chunks=chunks, # type: ignore
Expand Down

0 comments on commit 887e1cf

Please sign in to comment.