Repository navigation
fix: handle skipped property layers in matplotlib backend - #4050
Conversation
Initialize the colorbar result before iterating so skipped layers return the existing axes/colorbar tuple with a None colorbar instead of raising UnboundLocalError. Add regression coverage for an empty portrayal dictionary and a callable that returns None.
|
Performance benchmarks:
|
|
Thanks, the fix looks good: draw_property_layer no longer raises UnboundLocalError when every layer is skipped, and the new tests pass on my end. A few small things:
|
|
Thanks @arzaanxeng for the review! I've addressed all three points:
The focused tests and full SpaceRenderer test module pass, and Ruff checks pass as well. Thanks again! |
|
Hi @quaquel, could you please take a look at this PR when you get a chance? I've addressed the feedback from arzaanxeng, pushed the requested changes, and verified the updated implementation with the relevant tests and lint checks. I'd appreciate a maintainer review. Please let me know if anything else needs to be changed. Thanks! |
|
Checked The earlier feedback is addressed. Could you add the two-layer A-with-colorbar/B-without-colorbar case to the PR's tests, asserting that the returned colorbar is A's? It would protect the behavior changed by removing the per-layer reset. Also, please use the bug PR template and fill in its sections, including before/after evidence for the visualization fix. The current description explains the fix, but the template and visual evidence are missing. |
|
Hi @atul-upadhyay-7, I've implemented your suggestions and pushed the updates to this PR. I've added the two-layer regression test verifying that layer A's colorbar is preserved when layer B is drawn without one. I've also updated the PR description using Mesa's bug-fix template, including the before/after reproduction evidence. Thanks for testing the additional cases and pointing these out! |
|
@Jenil1905 the before/after screenshots are still missing from the description. could you add them? the text evidence is already there. |
|
Hi @atul-upadhyay-7 I've added both before/after screenshots to the PR description under the respective reproduction cases. The screenshots also illustrate the returned colorbar behavior. Thanks for pointing this out! |
|
checked the updated version, the fix looks good to me. lgtm |
Adapted for 3.5.x: tests use 3.5's setup_propertylayer/draw_propertylayer names and the _mesa_property_layers API; the fix itself applied unchanged. (cherry picked from commit aa4ca48) Assisted-by: Claude Opus 5.5
Pre-PR Checklist
Summary
Fix skipped property-layer rendering paths in the Matplotlib backend that could cause an
UnboundLocalErroror incorrectly discard a previously created colorbar.Bug / Issue
Fixes #4049
MatplotlibBackend.draw_property_layer()could raise anUnboundLocalErrorwhen all property layers were skipped because the colorbar variable was not initialized before the loop.Additionally, when multiple property layers were rendered, a later layer without a colorbar could reset the returned colorbar to
None, even if an earlier layer had created one.Expected Behavior
(ax, None).Implementation
cbar = Nonebefore iterating over property layers.None.Before / After Evidence
Case 1: All property layers skipped
Before:
After:
Case 2: Two property layers
Before:
After:
Testing
tests/visualization/test_backends.py: 26 passed.tests/visualization/test_space_renderer.py: 11 passed.tests/visualization/test_components_matplotlib.py: 17 passed.git diff --check: passed.The new mixed-colorbar regression test was also verified against the previous implementation, where the returned colorbar assertion failed as expected.
Additional Notes
Codex was used to assist with code investigation, implementation, and regression testing. The changes and test results were reviewed before submission.