8000 JSON encoding engine instrumentation by jonmmease · Pull Request #3012 · plotly/plotly.py · GitHub
[go: up one dir, main page]

Skip to content

JSON encoding engine instrumentation #3012

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 18 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Don't fail when orjson not installed
  • Loading branch information
jonmmease committed Jan 13, 2021
commit 8aa504c5a09b9fb637e650091c1d7e08238e6e7c
16 changes: 10 additions & 6 deletions 8000 packages/python/plotly/plotly/io/_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,12 @@ def coerce_to_strict(const):
def to_json_plotly(plotly_object, pretty=False, engine=None):
# instrucment _to_json_plotly by running it with all 3 engines and comparing results
# before returning
orjson = get_module("orjson", should_load=True)
results = {}
result_str = None
for engine in ["legacy", "json", "orjson"]:
if orjson is None and engine == "orjson":
continue
result_str = _to_json_plotly(plotly_object, pretty=pretty, engine=engine)
results[engine] = from_json_plotly(result_str, engine=engine)

Expand All @@ -73,13 +76,14 @@ def to_json_plotly(plotly_object, pretty=False, engine=None):

{json}""".format(legacy=results["legacy"], json=results["json"]))

if results["json"] != results["orjson"]:
raise ValueError("""
{json}

{orjson}""".format(json=results["json"], orjson=results["orjson"]))
if "orjson" in results:
if results["json"] != results["orjson"]:
raise ValueError("""
{json}

{orjson}""".format(json=results["json"], orjson=results["orjson"]))

return result_str
return result_str


def _to_json_plotly(plotly_object, pretty=False, engine=None):
Expand Down
0