Skip to content

Replace deprecated np.bmat with np.block in Voronoi Delaunay triangulation#2915

Merged
EwoutH merged 2 commits intomesa:mainfrom
EwoutH:voronoi_np_block
Dec 3, 2025
Merged

Replace deprecated np.bmat with np.block in Voronoi Delaunay triangulation#2915
EwoutH merged 2 commits intomesa:mainfrom
EwoutH:voronoi_np_block

Conversation

@EwoutH
Copy link
Copy Markdown
Member

@EwoutH EwoutH commented Dec 3, 2025

Summary

Fixes 108 deprecation warnings in the test suite related to numpy.matrix being deprecated.

Bug / Issue

When running tests/test_space_drawer.py, NumPy emits PendingDeprecationWarning for each call to Delaunay._circumcenter():

PendingDeprecationWarning: the matrix subclass is not the recommended way to represent matrices or deal with linear algebra (see https://docs.scipy.org/doc/numpy/user/numpy-for-matlab-users.html). Please adjust your code to use regular ndarray.

This occurs because np.bmat returns a numpy.matrix object, which NumPy intends to deprecate in favor of regular ndarray.

Implementation

In mesa/discrete_space/voronoi.py, the Delaunay._circumcenter method used np.bmat to construct a block matrix. This is replaced with np.block, wrapping the nested lists in np.array() calls to ensure consistent 2D array depths:

Testing

Existing tests pass. The 108 PendingDeprecationWarning messages from test_space_drawer.py are eliminated.

Additional Notes

This is a forward-compatibility fix. When NumPy eventually removes the matrix subclass, this code would have broken.

Part of #2904.

@EwoutH EwoutH added the maintenance Release notes label label Dec 3, 2025
@EwoutH EwoutH force-pushed the voronoi_np_block branch 2 times, most recently from bcbb968 to 0d2c3a7 Compare December 3, 2025 13:06
EwoutH and others added 2 commits December 3, 2025 14:07
Replace np.bmat with np.block in Delaunay._circumcenter to fix PendingDeprecationWarning about numpy.matrix subclass. The nested lists are wrapped in np.array() calls to ensure consistent array depths required by np.block.
@github-actions

This comment was marked as off-topic.

@quaquel quaquel self-requested a review December 3, 2025 13:45
@EwoutH EwoutH merged commit fba7e4d into mesa:main Dec 3, 2025
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintenance Release notes label

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants