plotly.py icon indicating copy to clipboard operation
plotly.py copied to clipboard

With newer versions of orjson, users need to specify the json engine explicitly (bug?)

Open xucian opened this issue 3 years ago • 3 comments

Hey

I found out I get an AttributeError: partially initialized module 'orjson' has no attribute 'OPT_NON_STR_KEYS' if I don't specify this plotly.io.json.config.default_engine = 'orjson' when using orjson v3.6.6 (latest as of 25jan2022)

Also, additional note for whoever might have this issue: you don't need to uninstall orjson if you don't want to use it. just set the engine to 'json' explicitly.

I'm using orjson because of the performance claims, although I ran some tests switching between the 2 engines and they seem to yield the same results: using go.Candlestick with 10000 candlesticks and some 4-5 indicators, getting ~0.8sec in each case for creating the plot. My purpose is to improve the dash server performace, but it seems it makes no difference (the web page still renders slower than the ticker even with 600 candles)

xucian avatar Jan 25 '22 12:01 xucian

+1

HeddeCrisp avatar Jan 26 '23 13:01 HeddeCrisp

+1. App is presenting problems after a while. Not sure what's going on.

marcelo-ventura avatar Jan 31 '24 10:01 marcelo-ventura

+1. Happens to me when I use streamlit's st.plotly_chart (plotly v5.18.0)

noamgot avatar Feb 11 '24 20:02 noamgot

File "/.venv/lib/python3.11/site-packages/plotly/io/_json.py", line 146, in to_json_plotly opts = orjson.OPT_NON_STR_KEYS | orjson.OPT_SERIALIZE_NUMPY

This line of code may cause this issue

C0deBeez avatar Feb 27 '24 05:02 C0deBeez

A fix may be using a regular import rather than using importlib to manage this package.

ndrezn avatar Mar 28 '24 15:03 ndrezn

To reproduce using Dash:

  1. pip install orjson
  2. Make a Dash app
  3. Trigger reload

If you look at network requests, it'll show this exact error.

ndrezn avatar Mar 28 '24 15:03 ndrezn