Skip to content

Tracking issue: Resolve test suite warnings #2904

@EwoutH

Description

@EwoutH

Summary

The Mesa test suite currently generates 1514 warnings across 366 tests. This issue tracks the categorization and resolution of these warnings to improve code quality and developer experience.

If you're a new contributor this is not a bad place to start (building models is better). Please pick one item of the list, resolve that fully, and open a PR once you have tested and confirmed it was resolved.

Note that very likely, only changes to the examples or test code are needed.


Warning Categories

1. Deprecation Warnings

1.1 Agent Portrayal Dict Deprecation (~130+ warnings)

Warning:

DeprecationWarning: Returning a dict from agent_portrayal is deprecated. 
Please return an AgentPortrayalStyle instance instead.

Affected Files:

  • mesa/visualization/mpl_space_drawing.py (lines 459, 504, 603, 664, 721)
  • mesa/visualization/space_renderer.py (line 196)
  • tests/test_backends.py (lines 74, 210)
  • tests/test_components_matplotlib.py

Action Required:

  • Update all test agent portrayals to return AgentPortrayalStyle instances
  • Update example models to use new portrayal style

See #2786

1.2 PropertyLayer Portrayal Dict Deprecation (~3 warnings)

Warning:

DeprecationWarning: The propertylayer_portrayal dict is deprecated. 
Please use a callable that returns a PropertyLayerStyle instance instead.

Affected Files:

  • mesa/visualization/mpl_space_drawing.py (line 351)
  • mesa/visualization/backends/altair_backend.py (line 368)
  • tests/test_components_matplotlib.py

Action Required:

  • Update test property layer portrayals to use callable returning PropertyLayerStyle

See #2786

1.3 Experimental Cell Space Import Deprecation (1 warning)

Warning:

DeprecationWarning: you are importing from mesa.experimental.cell_space, 
all cell spaces have been moved to mesa.discrete_space

Affected Files:

  • tests/test_components_matplotlib.py (line 7)

Action Required:

  • Update import to use mesa.discrete_space

See #2610


2. UserWarnings

2.1 Missing Random Number Generator (~45+ warnings)

Warning:

UserWarning: Random number generator not specified, this can make models 
non-reproducible. Please pass a random number generator explicitly

Affected Files:

  • mesa/discrete_space/grid.py (line 101)
  • mesa/discrete_space/network.py (line 41)
  • mesa/discrete_space/voronoi.py (line 204)
  • Various test files

Action Required:

  • Update OrthogonalGrid, Network, and VoronoiGrid instantiations in tests to pass random parameter
  • Consider if default RNG behavior should be changed

See #2352.

2.2 PropertyLayer Default Value Type Mismatch (~4 warnings)

Warning:

UserWarning: Default value 0 (int) might not be best suitable with dtype=float64.
UserWarning: Default value 10.0 (float) might not be best suitable with dtype=float64.

Affected Files:

  • tests/test_components_matplotlib.py (line 225)
  • tests/test_solara_viz.py (line 119)
  • tests/test_solara_viz_updated.py (line 134)
  • tests/test_space_renderer.py (line 43)

Action Required:

  • Update PropertyLayer instantiations to use appropriate default values matching dtype

2.3 Ignored Dict Keys in Agent Portrayal (~12 warnings)

Warning:

UserWarning: The following keys from the returned dict were ignored: s, c, linecolors
UserWarning: The following keys from the returned dict were ignored: s, c

Affected Files:

  • mesa/visualization/mpl_space_drawing.py (multiple lines)
  • tests/test_components_matplotlib.py

Action Required:

  • Review and update agent portrayal dicts to use correct key names
  • Document valid keys for agent portrayal

3. PendingDeprecationWarning

3.1 NumPy Matrix Subclass (~1154 warnings)

Warning:

PendingDeprecationWarning: the matrix subclass is not the recommended way 
to represent matrices or deal with linear algebra

Affected Files:

  • External: numpy/matrixlib/defmatrix.py (line 1117)
  • Triggered by: tests/test_components_matplotlib.py, tests/test_discrete_space.py, tests/test_solara_viz.py, tests/test_space_drawer.py

Action Required:

  • Investigate which Mesa code triggers numpy matrix usage
  • Consider if this is from a dependency (likely matplotlib/scipy)
  • May require upstream fix or dependency update

Resources

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions