@@ -247,6 +247,20 @@ def _extract_attrs(h5obj: Union[Dataset, Group]):
247
247
attrs [n ] = v
248
248
return attrs
249
249
250
+ @staticmethod
251
+ def _extract_fill_value (
252
+ fill_value : Union [np .ndarray , np .nan , np .generic , None ],
253
+ ) -> Union [int , float , None ]:
254
+ if not fill_value :
255
+ return fill_value
256
+ if isinstance (fill_value , np .ndarray ):
257
+ fillvalue = fill_value [0 ]
258
+ if np .isnan (fill_value ):
259
+ fillvalue = float ("nan" )
260
+ if isinstance (fill_value , np .generic ):
261
+ fillvalue = fill_value .item ()
262
+ return fillvalue
263
+
250
264
@staticmethod
251
265
def _dataset_to_variable (path : str , dataset : Dataset ) -> Optional [Variable ]:
252
266
"""
@@ -279,12 +293,11 @@ def _dataset_to_variable(path: str, dataset: Dataset) -> Optional[Variable]:
279
293
else :
280
294
dtype = dataset .dtype
281
295
fill_value = dataset .fillvalue
282
- if isinstance (fill_value , np .ndarray ):
283
- fill_value = fill_value [0 ]
284
- if np .isnan (fill_value ):
285
- fill_value = float ("nan" )
286
- if isinstance (fill_value , np .generic ):
287
- fill_value = fill_value .item ()
296
+ try :
297
+ fill_value = dataset .fillvalue
298
+ except Exception :
299
+ fill_value = None
300
+ fill_value = HDFVirtualBackend ._extract_fill_value (fill_value = fill_value )
288
301
filters = [codec .get_config () for codec in codecs ]
289
302
zarray = ZArray (
290
303
chunks = chunks , # type: ignore
0 commit comments