Skip to content
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

Refactor JSON encoding to use plotly.py JSON engine #1514

Merged
merged 15 commits into from
Aug 16, 2021
Merged

Conversation

jonmmease
Copy link
Contributor

@jonmmease jonmmease commented Jan 2, 2021

Update to make Dash use the active plotly.py JSON engine. The JSON engine system was introduced in plotly.py in plotly/plotly.py#2955.

Note: This PR adds a plotly.py lower version bound of 5.0.

plotly.py will use the faster orjson encoder by default if the orjson package is installed. But to make the orjson engine is in use, add this snippet:

import plotly.io as pio
pio.json.config.default_engine = "orjson"

@jonmmease
Copy link
Contributor Author

There is one percy baseline change. The plotly.py JSON engines always sort object keys in alphabetical order. So the devtools validation exception snapshot changed.

Before:

label/value/typo

Screenshot_20210812_125657

After:

label/typo/value in alphabetical order

Screenshot_20210812_125709

@jonmmease jonmmease marked this pull request as ready for review August 12, 2021 17:02
@jonmmease
Copy link
Contributor Author

Ready for review

Copy link
Collaborator

@alexcjohnson alexcjohnson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a changelog entry and this is great! 💃

There are also a couple instances of PlotlyJSONEncoder in the tests, do you want to convert these too?

@alexcjohnson
Copy link
Collaborator

Oh actually I don't see orjson listed as a dep, were you going to include it in requires-dev.txt? Can we perhaps pick one or two integration tests and run them with both json and orjson? I don't care which, they all make extensive use of JSON encodings :)

@jonmmease
Copy link
Contributor Author

Thanks! Yeah, I'll make sure both get used in some tests.

@jonmmease
Copy link
Contributor Author

Can we perhaps pick one or two integration tests and run them with both json and orjson? I don't care which, they all make extensive use of JSON encodings :)

Yeah, I added it to requires-dev.txt and made a couple of tests run with both encoders (a167542)

There are also a couple instances of PlotlyJSONEncoder in the tests, do you want to convert these too?

I decided not to as a small extra check for backward compatibility. But it wouldn't take much to talk me into it 🙂

Changelog entry added in (53419b0)

@jonmmease
Copy link
Contributor Author

ping @alexcjohnson or @chriddyp. This is ready to merge, but I don't have permission to approve the percy diff mentioned above. Could one of you approve that in percy?

@chriddyp
Copy link
Member

Approved, looks good!

@jonmmease jonmmease merged commit 9d10871 into dev Aug 16, 2021
@jonmmease
Copy link
Contributor Author

Thanks!

@jonmmease jonmmease deleted the plotly-json-engine branch August 16, 2021 22:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants