altair
altair copied to clipboard
alt.Chart.from_json slow after upgrading jsonschema from 3.x to 4.x
I tested all of the below with altair version 4.1.0.
I recently upgraded my jupyter stack to the following versions: notebook==6.4.4 ipython==7.28.0 ipykernel==6.4.1
Update: The culprit downstream dependency is jsonschema==4.1.0
Since then, alt.Chart.from_json(spec)
takes 2.6 seconds on my machine. Code to reproduce:
import time
import altair as alt
spec = """
{
"$schema": "https://vega.github.io/schema/vega-lite/v4.json",
"mark": {
"type": "bar",
"tooltip": {
"content": "data"
}
},
"height": 220,
"autosize": {
"type": "fit"
},
"data": {
"name": "placeholder"
},
"encoding": {
"x": {
"field": "bookID",
"type": "quantitative",
"sort": null,
"scale": {
"type": "linear",
"zero": false
}
},
"y": {
"field": "title",
"type": "nominal",
"sort": null,
"scale": {
"type": "linear",
"zero": true
}
},
"color": {
"field": "",
"type": "nominal",
"sort": null,
"scale": {
"type": "linear",
"zero": false
}
}
}
}
"""
start = time.time()
chart = alt.Chart.from_json(spec)
end = time.time()
print(end - start)
Running the same code on an older version jsonschema==3.2.0
executes in 0.03 seconds.
Note that I am not yet passing any data to altair, just a data-less vega-lite spec.
Thanks for the report: this seems to be due to https://github.com/Julian/jsonschema/issues/853
For now, I'd suggest using jsonschema
version 3.2 with Altair.
closing as there is nothing to do on the altair side of things and there are newer versions of jsonschema to use