Thanks to visit codestin.com
Credit goes to github.com

Skip to content

JSON encoding refactor and orjson encoding #2955

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

Merged
merged 49 commits into from
May 27, 2021
Merged
Changes from 1 commit
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
40b9af1
WIP accelerated encoding with orjson
jonmmease Dec 5, 2020
f79e318
support fig to dict in io without cloning
jonmmease Dec 5, 2020
55720de
Merge branch 'master' into orjson_encoding
jonmmease Dec 5, 2020
7b3593a
fix clone default
jonmmease Dec 5, 2020
da915d6
Add pio.json.config object to configure default encoder
jonmmease Dec 5, 2020
7b235ef
default_encoder to default_engine
jonmmease Dec 5, 2020
7895b6a
blacken
jonmmease Dec 5, 2020
ce05a68
Handle Dash objects in to_json
jonmmease Dec 6, 2020
4ef6510
add JSON encoding tests
jonmmease Dec 31, 2020
101ba85
add testing of from_plotly_json
jonmmease Dec 31, 2020
67d3670
Better error message when orjson not installed and orjson engine requ…
jonmmease Dec 31, 2020
02c00da
Add orjson as optional testing dependency
jonmmease Dec 31, 2020
99ea6a1
Replace Python 3.5 CI tests with 3.8
jonmmease Dec 31, 2020
d44ec26
Try only install orjson with Python 3.6+
jonmmease Dec 31, 2020
b7d8422
Don't test orjson engine when orjson not installed
jonmmease Dec 31, 2020
ddcd6f5
Try new 3.8.7 docker image since prior guess doesn't exist
jonmmease Dec 31, 2020
33359f3
greater than!
jonmmease Dec 31, 2020
c7c1819
Bump scikit image version for Python 3.8 compatibility
jonmmease Dec 31, 2020
a8d52ab
Try to help Python 2 from getting confused about which json module to…
jonmmease Dec 31, 2020
619838f
Update pandas for Python 3
jonmmease Dec 31, 2020
7c7a272
Revert 3.8 CI updates. Too much for this PR
jonmmease Dec 31, 2020
1708703
Doh
jonmmease Dec 31, 2020
66cab10
Don't skip copying during serialization
jonmmease Dec 31, 2020
56a8945
Rename new JSON functions:
jonmmease Jan 2, 2021
0a51020
Ensure cleaned numpy arrays are contiguous
jonmmease Jan 2, 2021
4e9d64e
Use to_json_plotly in html and orca logic
jonmmease Jan 8, 2021
d4068de
Add orjson documentation dependency
jonmmease Jan 8, 2021
58b7192
Handle pandas Timestamp scalars in orjson engine
jonmmease Jan 8, 2021
974fcba
Rework date and string encoding, add and fix tests
jonmmease Jan 8, 2021
a651a63
default JSON engine to "auto"
jonmmease Jan 8, 2021
af1d88d
Fix expected JSON in html export (no spaces)
jonmmease Jan 8, 2021
1d6acc3
Merge remote-tracking branch 'origin/master' into orjson_encoding
jonmmease Jan 8, 2021
d51fd94
blacken
jonmmease Jan 8, 2021
042c54c
Fix expected JSON in matplotlylib test
jonmmease Jan 8, 2021
ddc1b8f
Fix expected JSON in html repr test
jonmmease Jan 8, 2021
d7928b0
Merge remote-tracking branch 'origin/master' into orjson_encoding
jonmmease Jan 13, 2021
76cc625
Don't drop timezones during serialization, just let Plotly.js ignore …
jonmmease Jan 13, 2021
453461d
Merge branch 'numpy_date_serialization' into orjson_encoding
jonmmease Jan 13, 2021
84ba4b5
no need to skip legacy tests now
jonmmease Jan 13, 2021
340aed3
Only try `datetime_as_string` on datetime kinded numpy arrays
jonmmease Jan 13, 2021
6cea61d
Don't store object or unicode numpy arrays in figure. Coerce to lists
jonmmease Jan 21, 2021
93815c1
Try orjson encoding without cleaning first
jonmmease Jan 21, 2021
242d1fa
Merge remote-tracking branch 'origin/master' into orjson_encoding
jonmmease Jan 21, 2021
8a3a4b3
blacken
jonmmease Jan 21, 2021
1de750a
remove scratch file
jonmmease Jan 21, 2021
81f73d5
Remove unused clone
jonmmease Jan 21, 2021
80be8bd
Remove the new "json" encoder
jonmmease Jan 22, 2021
cb54f88
Reorder dict cleaning for performance
jonmmease Jan 22, 2021
1fbfa0d
Merge remote-tracking branch 'origin/master' into orjson_encoding
jonmmease Apr 29, 2021
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
Better error message when orjson not installed and orjson engine requ…
…ested
  • Loading branch information
jonmmease committed Dec 31, 2020
commit 67d3670e8392415d8a6ef5200e08bdef9b95ec9f
18 changes: 11 additions & 7 deletions packages/python/plotly/plotly/io/_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,16 @@ def default_engine(self, val):
)

if val == "orjson":
orjson = get_module("orjson")
if orjson is None:
raise ValueError("The orjson engine requires the orjson package")
self.validate_orjson()

self._default_engine = val

@classmethod
def validate_orjson(cls):
orjson = get_module("orjson")
if orjson is None:
raise ValueError("The orjson engine requires the orjson package")


config = JsonConfig()

Expand Down Expand Up @@ -106,8 +110,6 @@ def to_plotly_json(plotly_object, pretty=False, engine=None):
"image": get_module("PIL.Image", should_load=False),
}

orjson = get_module("orjson", should_load=True)

# Dump to a JSON string and return
# --------------------------------
if engine in ("json", "legacy"):
Expand Down Expand Up @@ -148,6 +150,7 @@ def to_plotly_json(plotly_object, pretty=False, engine=None):

return json.dumps(plotly_object, cls=PlotlyJSONEncoder, **opts)
elif engine == "orjson":
JsonConfig.validate_orjson()
opts = orjson.OPT_SORT_KEYS | orjson.OPT_SERIALIZE_NUMPY

if pretty:
Expand Down Expand Up @@ -287,6 +290,8 @@ def from_plotly_json(value, engine=None):
-------
dict
"""
orjson = get_module("orjson", should_load=True)

# Validate value
# --------------
if not isinstance(value, (string_types, bytes)):
Expand All @@ -298,8 +303,6 @@ def from_plotly_json(value, engine=None):
)
)

orjson = get_module("orjson", should_load=True)

# Determine json engine
if engine is None:
engine = config.default_engine
Expand All @@ -313,6 +316,7 @@ def from_plotly_json(value, engine=None):
raise ValueError("Invalid json engine: %s" % engine)

if engine == "orjson":
JsonConfig.validate_orjson()
# orjson handles bytes input natively
value_dict = orjson.loads(value)
else:
Expand Down