Skip to content

Commit

Permalink
float type checking
Browse files Browse the repository at this point in the history
  • Loading branch information
magland committed Apr 4, 2024
1 parent 249feda commit 7dc223a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lindi/conversion/attr_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def h5_to_zarr_attr(attr: Any, *, label: str = '', h5f: Union[h5py.File, None]):
raise Exception(f"Unexpected h5 attribute: None at {label}")
elif type(attr) in [int, np.int8, np.int16, np.int32, np.int64, np.uint8, np.uint16, np.uint32, np.uint64]:
return int(attr)
elif type(attr) in [float, np.float16, np.float32, np.float64]:
elif isinstance(attr, (float, np.floating)):
return encode_nan_inf_ninf(float(attr))
elif isinstance(attr, complex) or (isinstance(attr, np.ndarray) and np.issubdtype(attr.dtype, np.complexfloating)):
raise Exception(f"Complex number is not supported at {label}")
Expand Down
2 changes: 1 addition & 1 deletion lindi/conversion/nan_inf_ninf.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def encode_nan_inf_ninf(val):
return [encode_nan_inf_ninf(v) for v in val]
elif isinstance(val, dict):
return {k: encode_nan_inf_ninf(v) for k, v in val.items()}
elif type(val) in [float, np.float16, np.float32, np.float64]:
elif isinstance(val, (float, np.floating)):
if np.isnan(val):
return 'NaN'
elif val == float('inf'):
Expand Down

0 comments on commit 7dc223a

Please sign in to comment.