Skip to content

Commit

Permalink
fix: support numpy scalars
Browse files Browse the repository at this point in the history
  • Loading branch information
maartenbreddels committed Oct 17, 2023
1 parent a375a5a commit 63e05bb
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions solara/server/kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ def json_default(obj):
return obj.isoformat().replace("+00:00", "Z")
elif isinstance(obj, bytes):
return b2a_base64(obj).decode("ascii")
if type(obj).__module__ == "numpy":
import numpy as np

if isinstance(obj, np.number):
return repr(obj.item())
else:
raise TypeError("%r is not JSON serializable" % obj)
else:
raise TypeError("%r is not JSON serializable" % obj)

Expand Down

0 comments on commit 63e05bb

Please sign in to comment.