Repository navigation
Fix SpaceRenderer.canvas crash for Altair with property layers - #3953
Conversation
canvas unpacked the property layer result into a chart and a colorbar, but the Altair backend has always returned a single chart with the legend built in. Unpacking it raised KeyError: 0, so canvas never worked for Altair once a property layer was set up. Treat the result as one chart and drop the colorbar branches, which could never be reached. Also fix the backend docstring that said it returns a tuple, and add a test for the Altair canvas. Fixes mesa#3950
|
Performance benchmarks:
|
|
Checked The description follows the bug template. Please add the before/after visual evidence requested in its Testing section: the original One optional test improvement: parameterize CI still has one failing check: the examples job stops during collection because the warehouse example imports No blocking issue found in the changed code. |
|
@AshNicolus the fix and the new agent overlay test look good. on python 3.13, all 1116 tests pass locally. both new test cases fail on the unchanged base with the original KeyError. the CI Playwright screenshot failure didn't reproduce in five runs each on base and head, but that check still needs a clean rerun. please add the before/after images when you get a chance. no blocking issue found in the changed code. lgtm |
|
There is a merge conflict that needs to be resolved. Also one of the builds seems to have failed. Can you please check? |
# Conflicts: # tests/visualization/test_space_renderer.py
|
Merged main in. The conflict was only in The failed build was |
EwoutH
left a comment
There was a problem hiding this comment.
Thanks, reproduced the KeyError: 0 on main and confirmed a valid 3-layer chart here.
|
Merging, thanks! |
Adapted for 3.5.x: uses 3.5's propertylayer_mesh / draw_propertylayer / setup_propertylayer names. (cherry picked from commit e43e3c9) Assisted-by: Claude Opus 5.5
Pre-PR Checklist
Summary
SpaceRenderer.canvascrashes withKeyError: 0when you use the Altair backend and have a property layer set up. This PR makes it return the combined chart like it should.Bug / Issue
Fixes #3950
canvasexpects the property layer drawing to give back two things, a chart and a colorbar. The matplotlib backend does that, but the Altair backend has always returned a single chart, with the legend already inside it. Socanvastries to unpack one chart into two values and fails.flowchart LR A[renderer.canvas] --> B[draw_property_layer] B --> C[Altair returns one chart] C --> D{"canvas does<br/>chart, colorbar = result"} D --> E["KeyError: 0"]SolaraViz isn't affected because it builds the Altair chart on its own and never calls
canvas. This mostly hits people working in a notebook who callrenderer.canvasdirectly.Implementation
canvas, treat the Altair property layer result as one chart and layer it with the structure and agents.AltairBackend.draw_property_layerdocstring, which said it returns a tuple. That's likely how the mismatch happened.Testing
test_altair_canvas_with_property_layerintests/visualization/test_space_renderer.py. It fails onmainwithKeyError: 0and passes with this change. It also checks the chart turns into a valid Vega-Lite spec.pytest tests/ -Werror(876 passed), andpre-commitpasses.Additional Notes
The Altair
canvashad no tests before, so this also adds the first one.