Skip to content

Commit 858a759

Browse files
committed
Close #138. Convert Decimal() objects to float() during serialization
1 parent 5d873e0 commit 858a759

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
* Fixed a bug with multiple altair outputs not working inside a `@shiny.render.ui` decorator. (#140)
1111
* `@render_widget` no longer errors out when giving a `altair.FacetChart` class. (#142)
12+
* `@render_widget` no longer fails to serialize `decimal.Decimal` objects. (#138)
1213

1314
## [0.3.1] - 2024-03-01
1415

shinywidgets/_serialization.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import decimal
12
import json
23
import numbers
34
import warnings
@@ -44,6 +45,9 @@ def json_default(obj: object) -> object:
4445
if isinstance(obj, numbers.Real):
4546
return float(obj)
4647

48+
if isinstance(obj, decimal.Decimal):
49+
return float(obj)
50+
4751
raise TypeError("%r is not JSON serializable" % obj)
4852

4953

0 commit comments

Comments
 (0)