Skip to content

Commit a8d52ab

Browse files
committed
Try to help Python 2 from getting confused about which json module to import
1 parent c7c1819 commit a8d52ab

File tree

1 file changed

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

1 file changed

+8
-6
lines changed

packages/python/plotly/plotly/io/_html.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
import uuid
2-
import json
32
import os
43
import webbrowser
54

65
import six
76

7+
from _plotly_utils.optional_imports import get_module
88
from plotly.io._utils import validate_coerce_fig_to_dict
99
from plotly.offline.offline import _get_jconfig, get_plotlyjs
1010
from plotly import utils
1111

12+
_json = get_module("json")
13+
1214

1315
# Build script to set global PlotlyConfig object. This must execute before
1416
# plotly.js is loaded.
@@ -134,15 +136,15 @@ def to_html(
134136
plotdivid = str(uuid.uuid4())
135137

136138
# ## Serialize figure ##
137-
jdata = json.dumps(
139+
jdata = _json.dumps(
138140
fig_dict.get("data", []), cls=utils.PlotlyJSONEncoder, sort_keys=True
139141
)
140-
jlayout = json.dumps(
142+
jlayout = _json.dumps(
141143
fig_dict.get("layout", {}), cls=utils.PlotlyJSONEncoder, sort_keys=True
142144
)
143145

144146
if fig_dict.get("frames", None):
145-
jframes = json.dumps(fig_dict.get("frames", []), cls=utils.PlotlyJSONEncoder)
147+
jframes = _json.dumps(fig_dict.get("frames", []), cls=utils.PlotlyJSONEncoder)
146148
else:
147149
jframes = None
148150

@@ -218,7 +220,7 @@ def to_html(
218220

219221
if auto_play:
220222
if animation_opts:
221-
animation_opts_arg = ", " + json.dumps(animation_opts)
223+
animation_opts_arg = ", " + _json.dumps(animation_opts)
222224
else:
223225
animation_opts_arg = ""
224226
then_animate = """.then(function(){{
@@ -228,7 +230,7 @@ def to_html(
228230
)
229231

230232
# Serialize config dict to JSON
231-
jconfig = json.dumps(config)
233+
jconfig = _json.dumps(config)
232234

233235
script = """\
234236
if (document.getElementById("{id}")) {{\

0 commit comments

Comments
 (0)