Skip to content

Commit

Permalink
Merge pull request #91 from silx-kit/complex256
Browse files Browse the repository at this point in the history
Fix serialization of complex256 objects to JSON
  • Loading branch information
axelboc authored Mar 13, 2024
2 parents a248a20 + 8b21766 commit 62b17c7
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions h5grove/encoders.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import orjson
import h5py
import tifffile
import numbers

from .utils import QueryArgumentError, is_numeric_data

Expand All @@ -23,10 +24,10 @@ def orjson_default(o: Any) -> Union[list, float, str, None]:
if isinstance(o, np.number) and o.dtype.kind == "f" and o.itemsize > 8:
# Force conversion of float >64bits to native float even if it means losing precision
return float(o)
if isinstance(o, numbers.Complex):
return [o.real, o.imag]
if isinstance(o, (np.generic, np.ndarray)):
return o.tolist()
if isinstance(o, complex):
return [o.real, o.imag]
if isinstance(o, h5py.Empty):
return None
if isinstance(o, bytes):
Expand Down

0 comments on commit 62b17c7

Please sign in to comment.