mesa icon indicating copy to clipboard operation
mesa copied to clipboard

Tracking issue: Resolve test suite warnings

Open EwoutH opened this issue 3 weeks ago • 5 comments

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 https://github.com/projectmesa/mesa/pull/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:

  • [x] Update test property layer portrayals to use callable returning PropertyLayerStyle

See https://github.com/projectmesa/mesa/pull/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:

  • [x] Update import to use mesa.discrete_space

See https://github.com/projectmesa/mesa/pull/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 https://github.com/projectmesa/mesa/pull/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:

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

Resources

  • Migration guide: https://mesa.readthedocs.io/latest/migration_guide.html#defining-portrayal-components

EwoutH avatar Dec 01 '25 16:12 EwoutH

@EwoutH Hi! I am interested to work on this issue . I am new to contribute here .Please assign this issue to me. Timeline: Will raise a PR within 2-3 days of assignment.

ShreyasN707 avatar Dec 01 '25 17:12 ShreyasN707

@ShreyasN707 Cool! I’m not going to assign the whole issue to you, but please pick one item to start.

EwoutH avatar Dec 01 '25 17:12 EwoutH

@EwoutH Ok i will work on the 2. UserWarnings issue first then fix others too.

ShreyasN707 avatar Dec 01 '25 18:12 ShreyasN707

@EwoutH I have raised the PR for issue 2.1 . Can i work on issue 2.2.

ShreyasN707 avatar Dec 02 '25 17:12 ShreyasN707

Lot's of warnings resolved already!

Few more to fix, including the AgentPortrayalStyle, Missing Random Number Generator an d PropertyLayer Default Value Type, if I'm correct.

EwoutH avatar Dec 04 '25 21:12 EwoutH

@EwoutH Hii Can you assign me the 3rd one PendingDeprection Warning for numpy. Please!!! I can compelete it within 3 days of the assignment.

codebyNJ avatar Dec 15 '25 17:12 codebyNJ

I think I already fixed it in #2915.

EwoutH avatar Dec 15 '25 21:12 EwoutH

Hey @ EwoutH can u review my PR #2934 please

falloficarus22 avatar Dec 16 '25 04:12 falloficarus22

Oh ok. is there any issue open I am willing to contribute @EwoutH

I think I already fixed it in #2915.

codebyNJ avatar Dec 16 '25 06:12 codebyNJ