Skip to content

Conversation

@ShreyasN707
Copy link
Contributor

Summary

Fixed UserWarnings caused by using incorrect keys (s, c, linecolors) in agent portrayal dictionaries within tests and clarified documentation.

Bug / Issue #2904

The issue was that tests/test_components_matplotlib.py was using Matplotlib-style keys (s, c) in the dictionary returned by agent_portrayal, which are not recognized by Mesa's mpl_space_drawing module. This led to multiple UserWarning: The following keys from the returned dict were ignored messages during testing. Additionally, the documentation in mpl_space_drawing.py needed consistent formatting for valid keys.

Implementation

  • Tests: Updated tests/test_components_matplotlib.py to use the correct keys expected by mpl_space_drawing:
    • Replaced "s" with "size".
    • Replaced "c" with "color".
    • Replaced "linecolors" with "edgecolors".
  • Documentation: Updated the docstring in mesa/visualization/mpl_space_drawing.py to consistently quote all valid keys ("size", "color", etc.) for better readability and accuracy.

Testing

  • Ran pytest tests/test_components_matplotlib.py -W always and verified that the UserWarning: The following keys from the returned dict were ignored messages are no longer present.
  • Confirmed that all tests in the file pass successfully.

Additional Notes

This ensures that the tests follow the recommended way of defining agent portrayals and keeps the test output clean.

Comment on lines 39 to 42
return {
"size": 10,
"color": "tab:blue",
"marker": "s" if (agent.unique_id % 2) == 0 else "o",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is changing stuff backwards right? Using dicts is deprecated, we now use AgentPortrayalStyle objects.

See #2786 and #2872, and our migration guide.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay I will look on to it.

@github-actions

This comment was marked as off-topic.

Comment on lines 138 to 140
# The runtime now emits a FutureWarning for this deprecation.
# Update test to match the current warning type.
with pytest.warns(FutureWarning, match="simulator.time is deprecated"):
Copy link
Member

@EwoutH EwoutH Dec 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching this. This was a bit time pressing however, so I already fixed it in #2922.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants