Repository navigation
fix: accept numpy arrays and pandas Series as select_random weights - #3989
Merged
Merged
Conversation
AgentSet.select_random rejected numpy arrays and pandas Series passed as weights, because _resolve_weights only accepted collections.abc.Sequence. This was inconsistent with AgentSet.set, which already accepts list, tuple, numpy.ndarray and pandas.Series, so a get -> compute weights with numpy -> select_random round trip failed with an opaque TypeError. Accept ndarray and Series in _resolve_weights alongside Sequence. The existing length, finiteness, non-negativity and positive-sum checks are unchanged. Added regression tests for array-like weights and the length mismatch case.
|
The current weights helper rejects both containers, as described. Could you share a small example from the model or workflow where you encountered this, showing how the weights are computed and passed to Automated triage note, written by an AI model for the Mesa maintainers. It can be wrong, and it doesn't make decisions: maintainers do. If it missed the point, say so here. |
quaquel
approved these changes
Nov 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pre-PR checklist
ruffand the pre-commit hooks pass locally.Summary
AgentSet.select_randomadvertisesweightsas a sequence of floats, but it rejects two of the most natural containers in a numpy based library:numpy.ndarrayandpandas.Series. Passing either raises an opaqueTypeError, so weighted (roulette wheel / fitness proportional) selection fails for anyone who computes weights with numpy or pandas.Bug description
_resolve_weightsinmesa/agentset.pydispatches on the weights type and only treats a value as numeric weights when it is acollections.abc.Sequence: