Skip to content

Commit 8aa504c

Browse files
committed
Don't fail when orjson not installed
1 parent bf481de commit 8aa504c

File tree

1 file changed

+10
-6
lines changed
  • packages/python/plotly/plotly/io

1 file changed

+10
-6
lines changed

packages/python/plotly/plotly/io/_json.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,12 @@ def coerce_to_strict(const):
6060
def to_json_plotly(plotly_object, pretty=False, engine=None):
6161
# instrucment _to_json_plotly by running it with all 3 engines and comparing results
6262
# before returning
63+
orjson = get_module("orjson", should_load=True)
6364
results = {}
6465
result_str = None
6566
for engine in ["legacy", "json", "orjson"]:
67+
if orjson is None and engine == "orjson":
68+
continue
6669
result_str = _to_json_plotly(plotly_object, pretty=pretty, engine=engine)
6770
results[engine] = from_json_plotly(result_str, engine=engine)
6871

@@ -73,13 +76,14 @@ def to_json_plotly(plotly_object, pretty=False, engine=None):
7376
7477
{json}""".format(legacy=results["legacy"], json=results["json"]))
7578

76-
if results["json"] != results["orjson"]:
77-
raise ValueError("""
78-
{json}
79-
80-
{orjson}""".format(json=results["json"], orjson=results["orjson"]))
79+
if "orjson" in results:
80+
if results["json"] != results["orjson"]:
81+
raise ValueError("""
82+
{json}
83+
84+
{orjson}""".format(json=results["json"], orjson=results["orjson"]))
8185

82-
return result_str
86+
return result_str
8387

8488

8589
def _to_json_plotly(plotly_object, pretty=False, engine=None):

0 commit comments

Comments
 (0)