Skip to content

Conversation

@Tejasv-Singh
Copy link
Contributor

@Tejasv-Singh Tejasv-Singh commented Dec 3, 2025

Migrate Property Layer Visualization to PropertyLayerStyle (Part of #2904)

This PR resolves deprecation warnings related to PropertyLayer visualization by migrating from dictionary-based styles to the PropertyLayerStyle class across both visualization backends and the test suite.

Linked Issue

Part of #2904, Item 1.2 (PropertyLayer Portrayal Dict Deprecation)

Problem

The current test suite and visualization backends were returning plain Python dictionaries for property layer portrayals. This behavior is deprecated and produces DeprecationWarnings because the visualization pipeline now expects PropertyLayerStyle instances.

Implementation

Updated Visualization Backends

Migrated property layer handling in:

mesa/visualization/mpl_space_drawing.py
mesa/visualization/backends/altair_backend.py

Both backends now return PropertyLayerStyle instead of dictionaries.

Updated Tests

Refactored:
tests/test_components_matplotlib.py

tests/test_solara_viz_updated.py
Tests now use the new PropertyLayerStyle API directly, eliminating Solara-specific and Matplotlib-specific warnings.

Code Style Improvements

Renamed unused portrayal callback arguments from layer to _:

def propertylayer_portrayal(_): ...

This follows Python best practices and addresses prior reviewer feedback.

Testing

Ran the targeted test modules:


pytest tests/test_components_matplotlib.py
pytest tests/test_solara_viz_updated.py

Results:

All tests passed

All PropertyLayer-related deprecation warnings are resolved in these modules

Additional Notes

This PR supersedes #2912, which was closed due to merge conflicts.

Fully resolves Item 1.2 from the deprecation migration plan in #2904.

Ensures consistent usage of PropertyLayerStyle across both backends and tests.

@github-actions

This comment was marked as off-topic.

@EwoutH
Copy link
Member

EwoutH commented Dec 4, 2025

@Tejasv-Singh Thanks for fixing the PropertyLayer warnings in test_components_matplotlib.py.

However, there's still one PropertyLayer deprecation warning remaining in the test suite:

tests/test_solara_viz_updated.py::test_call_space_drawer
  /home/runner/work/mesa/mesa/mesa/visualization/backends/altair_backend.py:368: FutureWarning: The propertylayer_portrayal dict is deprecated...

This suggests test_solara_viz_updated.py also needs to be updated to use PropertyLayerStyle instead of dictionaries. Would you like to include that fix in this PR?

@Tejasv-Singh
Copy link
Contributor Author

@EwoutH Yes, absolutely! I will update tests/test_solara_viz_updated.py to use PropertyLayerStyle and push the changes to this PR shortly.

I am also closing the previous PR (#2912) now to avoid any confusion regarding the merge conflicts. This PR will be the main one going forward.

@EwoutH EwoutH changed the title Fix #2904: Use PropertyLayerStyle for property layers tests: Migrate PropertyLayer portrayals from dict to PropertyLayerStyle Dec 4, 2025
@EwoutH EwoutH added the testing Release notes label label Dec 4, 2025
@EwoutH EwoutH merged commit 6609301 into projectmesa:main Dec 4, 2025
14 checks passed
@EwoutH
Copy link
Member

EwoutH commented Dec 4, 2025

Awesome, thanks!

Could you update the PR description to represent the final state of the PR?

@Tejasv-Singh
Copy link
Contributor Author

Done 🫡

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

testing Release notes label

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants