Repository navigation
Add informative __repr__ and __str__ to AgentSet and GroupBy - #3741
Merged
Merged
Conversation
|
Performance benchmarks:
|
Member
|
In groupby, you went with just the number of groups but not the composition of each group (or at least the identifiers for the groups). Why and would it not make sense to at least include the group identifiers? |
Contributor
Author
|
Good point. I kept it minimal at first because of the cost concern from #3735, but that was about the AgentSet per-type breakdown, which needs a full pass over the agents. It doesn't apply to GroupBy since the groups are already split, so len(group) per group is cheap. Updated the repr to include the identifiers and sizes: GroupBy(2 groups: {'Wolf': 2, 'Sheep': 1}) Test updated too. |
quaquel
approved these changes
Jun 15, 2026
EwoutH
pushed a commit
that referenced
this pull request
Oct 28, 2026
* Add informative __repr__ and __str__ to AgentSet and GroupBy * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Show group identifiers and sizes in GroupBy repr --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> (cherry picked from commit 79639de)
53 of 65 tasks
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.
Closes #3735
What
The core collection objects had no informative
__repr__/__str__, so in a REPL,notebook, or debugger they showed only the default
<... object at 0x...>.Cellalready defines a useful
__repr__, so this also removes an API inconsistency.Change
Per the discussion in #3735:
AbstractAgentSet.__repr__→<AgentSet (200 agents)>(uses the real class name,so
model.agentsshows<_HardKeyAgentSet (200 agents)>).AbstractAgentSet.__str__→AgentSet with 200 agents.GroupBy.__repr__→GroupBy(3 groups).All are count-only and O(1) (
len()is constant-time for both AgentSet types andGroupBy), so they add no overhead. The per-type breakdown was dropped to avoid
iterating all agents on every call, and
_repr_html_is left for a future issue,both as agreed on the issue.
Test
Added
test_agentset_repr_and_strandtest_groupby_repr. Full non-viz suite(508 tests) passes under
-Werror; ruff clean.