Skip to content

Commit

Permalink
Extend NumberEncoder to encode also numpy.ndarray
Browse files Browse the repository at this point in the history
  • Loading branch information
miccoli committed Aug 6, 2022
1 parent f9fd8c7 commit 380ee7c
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions zarr/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ def default(self, o):
return int(o)
if isinstance(o, numbers.Real):
return float(o)
# hdf5 attributes can be arrays, which h5py renders as np.ndarray
if isinstance(o, np.ndarray):
return o.tolist()
# this is for encoding numpy.bytes_
if isinstance(o, bytes):
return o.decode()
return json.JSONEncoder.default(self, o)


Expand Down

0 comments on commit 380ee7c

Please sign in to comment.