Skip to content

Conversation

@adamamer20
Copy link
Member

Solves #174. must be merged after #172.

@adamamer20 adamamer20 added this to the 0.1.0-stable milestone Sep 19, 2025
@adamamer20 adamamer20 self-assigned this Sep 19, 2025
@adamamer20 adamamer20 added the bug Something isn't working label Sep 19, 2025
@adamamer20 adamamer20 linked an issue Sep 19, 2025 that may be closed by this pull request
@codecov
Copy link

codecov bot commented Sep 19, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.86%. Comparing base (dccc834) to head (f9d7336).
⚠️ Report is 1 commits behind head on 146-enhancement-consider-using-a-key-based-structure-for-agentsets-instead-of-list-in-agentsdf.

Additional details and impacted files
@@                                                       Coverage Diff                                                       @@
##           146-enhancement-consider-using-a-key-based-structure-for-agentsets-instead-of-list-in-agentsdf     #178   +/-   ##
===============================================================================================================================
  Coverage                                                                                           88.85%   88.86%           
===============================================================================================================================
  Files                                                                                                  14       14           
  Lines                                                                                                1983     1984    +1     
===============================================================================================================================
+ Hits                                                                                                 1762     1763    +1     
  Misses                                                                                                221      221           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@adamamer20 adamamer20 changed the base branch from main to 146-enhancement-consider-using-a-key-based-structure-for-agentsets-instead-of-list-in-agentsdf September 22, 2025 16:47
@adamamer20 adamamer20 merged commit 67c8d1e into 146-enhancement-consider-using-a-key-based-structure-for-agentsets-instead-of-list-in-agentsdf Oct 19, 2025
14 checks passed
@adamamer20 adamamer20 deleted the 174-bug-solving-polars-deprecation-warnings-for-is_in branch October 19, 2025 10:46
@adamamer20 adamamer20 restored the 174-bug-solving-polars-deprecation-warnings-for-is_in branch October 20, 2025 07:44
@adamamer20 adamamer20 deleted the 174-bug-solving-polars-deprecation-warnings-for-is_in branch October 20, 2025 07:46
adamamer20 added a commit that referenced this pull request Dec 8, 2025
…of concerns (#172)

* Add abstract name property and rename method to AgentSetDF for enhanced agent set management

* Refactor agent retrieval in ModelDF to use dictionary access for improved performance and clarity

* Enhance AgentSetPolars with unique naming and renaming capabilities

* Add abstract base class for agent sets accessors with comprehensive API

* Implement AgentSetsAccessor class for enhanced agent set management and access

* Add KeyBy literal for common option types in type definitions

* Refactor AgentSetsAccessor to use direct access to agent sets for improved clarity and performance

* Fix type hint in constructor and improve default handling in get method for AgentSetsAccessor

* Remove redundant test for agent sets by type in Test_AgentsDF

* Add rename method to AgentSetsAccessor for agent set renaming with conflict handling

* Refactor name handling in AgentSetPolars to simplify uniqueness management and enhance rename method for better delegation to AgentsDF.

* Implement unique name generation and canonicalization for agent sets in AgentsDF

* Enhance type handling in AgentSetsAccessor to provide detailed error messages for key lookups

* Enhance error handling in AgentsDF by providing available agent set names in ValueError for better debugging

* Add mesa package to development dependencies in uv.lock

* Refactor __getitem__ method in AgentSetsAccessor to return matching agent sets as a list for multiple matches and improve error messaging for better clarity.

* Add comprehensive tests for AgentSetsAccessor methods to ensure correct functionality and error handling

* Rename AgentSetsAccessorBase to AbstractAgentSetsAccessor for consistency and clarity in the abstract class naming.

* Refactor AgentSetsAccessor to extend AbstractAgentSetsAccessor for improved consistency and clarity; enhance error messaging in __getitem__ and rename methods for better readability.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Refactor error handling in __getitem__ to use a set for available agent set types, improving performance and clarity in KeyError messages.

* Enhance code readability and organization by adding whitespace for clarity in AGENTS.md, agents.py, agentset.py, and test_sets_accessor.py; improve formatting in test cases.

* Enhance docstring clarity and type annotations in AbstractAgentSetsAccessor; update parameter descriptions for improved understanding.

* Enhance docstring clarity and type annotations in AgentSetsAccessor; update conflict resolution and mode descriptions for improved understanding.

* Refactor docstring in AgentsDF.rename to clarify purpose and improve type annotations for parameters.

* Enhance docstring clarity and type annotations in AbstractAgentSetsAccessor and AgentSetsAccessor; update default values and descriptions for parameters.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Enhance type annotations and overloads in AbstractAgentSetsAccessor; improve clarity for __getitem__, get, keys, items, and mapping methods.

* Refactor type annotations in AbstractAgentSetsAccessor; replace AgentSetDF with generic TSet for improved flexibility in first and all methods, and rename mapping methods to dict for clarity.

* Refactor AgentSetsAccessor methods; replace mapping method with dict for consistency and update test cases accordingly.

* Add rename method to AbstractAgentSetsAccessor for agent set renaming with conflict handling

* Refactor rename method in AgentSetsAccessor; streamline docstring and update call to _rename_sets for batch renaming support.

* Refactor rename method in AbstractAgentSetsAccessor; improve type annotations for target parameter to enhance clarity and flexibility.

* Refactor _rename_set method in AgentsDF; enhance functionality for single and batch renaming with improved conflict handling and parsing logic.

* Refactor AbstractAgentSetsAccessor and AgentSetsAccessor; remove 'object' key option from keys and items methods, and update related logic for consistency. Update KeyBy type alias to reflect changes.

* Add tests for AgentsDF's contains and remove methods; handle empty iterable and None cases

* Enhance tests for AgentSetsAccessor; add validation for key retrieval, improve rename functionality with single and batch rename tests, and handle invalid key scenarios.

* Refactor keys method in AbstractAgentSetsAccessor for consistency; improve KeyError messages in AgentsDF for better clarity; remove unnecessary blank line in test_sets_accessor.

* Update return type of keys method in AbstractAgentSetsAccessor to exclude AgentSetDF for clarity

* Enhance _make_unique_name method in AgentsDF with detailed docstring; ensure name conversion to snake_case and improve uniqueness handling in _canonicalize_names method.

* Implement camel_case_to_snake_case function for converting camelCase strings to snake_case; include detailed docstring with parameters, return values, and examples.

* Refactor AgentSetPolars to convert proposed name to snake_case if in camelCase; update docstring for clarity on name handling.

* Refactor camel_case_to_snake_case function for consistency in regex string delimiters; improve readability.

* Refactor _camel_to_snake function for consistent regex string delimiters; update return types in __getitem__ methods for clarity.

* Enhance AgentContainer type hints to support string and collection of strings; improve method signatures for clarity.

* Refactor AgentSetPolars to improve readability of name assignment; format multiline expression for clarity.

* Refactor tests to use updated Model and AgentSet classes

- Updated test_datacollector.py to replace ModelDF and AgentSetPolars with Model and AgentSet.
- Modified ExampleModel and ExampleModelWithMultipleCollects to use AgentSetRegistry.
- Adjusted fixtures to reflect changes in agent set classes.
- Updated test_grid.py to use new Model and AgentSet classes, ensuring compatibility with the refactored code.
- Changed test_modeldf.py to utilize the new Model class.
- Updated dependencies in uv.lock to include mesa version 3.2.0.

* Refactor agent set imports and introduce AgentSetRegistry

- Updated import paths for AbstractAgentSet and AgentSetRegistry to reflect new module structure.
- Created a new concrete implementation of AgentSetRegistry in `agentsetregistry.py`, providing a collection for managing agent sets with DataFrame-based storage.
- Modified existing files to utilize the new AgentSetRegistry class, ensuring consistent usage across the codebase.

* Refactor import statements for better readability in space.py and agentsetregistry.py

* Fix formatting in AGENTS.md for MESA_FRAMES_RUNTIME_TYPECHECKING variable

* Update type hints in AbstractAgentSetRegistry to reference abstract agents

* Introduce AbstractAgentSet class and refactor imports for consistency

* Update type hints in AbstractAgentSetRegistry to reference concrete AbstractAgentSet

* Refactor import statements in agentset.py for improved readability

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update docstring in AbstractAgentSet and improve type hints in AbstractAgentSetRegistry

* Remove AbstractAgentSetsAccessor class and its associated methods from accessors.py

* Remove TestAgentSetsAccessor class and its associated tests from test_sets_accessor.py

* Rename test class from Test_ModelDF to Test_Model for consistency

* Add abstract agent set classes and concrete agent set registry implementation

- Introduced AbstractAgentSet class for agent management with DataFrame operations.
- Implemented AgentSetRegistry for managing collections of AbstractAgentSets.
- Refactored AgentSetPolars to improve name handling and added name property.
- Removed deprecated methods from ModelDF related to agent retrieval and types.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Refactor GridPolars to Grid and update related references across the codebase for consistency and clarity

* Remove concrete implementation of AgentSetsAccessor for codebase cleanup

* Remove camel_case_to_snake_case function for codebase cleanup

* Rename SpaceDF to Space and update related references for consistency

* Rename MoneyAgentDFConcise to MoneyAgentConcise and MoneyAgentDFNative to MoneyAgentNative for clarity; update MoneyModelDF to MoneyModel and adjust related references.

* Update rename method documentation to reflect delegation to AgentSetRegistry instead of AgentsDF

* Remove unused properties from AgentSetRegistry for codebase cleanup

* Update space type annotations to reflect Space object instead of MultiSpaceDF

* Fix get_unique_ids function to correctly cast unique_id series from model sets

* Refactor space property type annotation to use Space instead of SpaceDF; remove unused abstract properties for cleaner interface.

* Update copyright year in conf.py to use current year dynamically

* Rename MoneyAgentDF and MoneyModelDF classes to MoneyAgents and MoneyModel for consistency across the codebase

* Add tests for CustomModel and its step functionality

* Update space property type hint to use Space instead of SpaceDF for clarity

* Format list comprehensions for improved readability in AgentSetRegistry methods

* Rename parameter in ExampleModel constructor from 'agents' to 'sets' for clarity

* Reorder DataCollector import to avoid circular import error

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Remove unused import of camel_case_to_snake_case in agentset.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Add conftest.py to enable beartype runtime checking for tests

* Fix import order by adding a newline for clarity in __init__.py

* Enhance type hinting for agent parameters in Space and AbstractDiscreteSpace classes

* Refactor agent type checks to use AbstractAgentSetRegistry for improved clarity and consistency

* Refactor AgentSet constructor and name property for improved clarity and type consistency

* precommit

* Replace MoneyAgentDF with MoneyAgents in MoneyModel constructor for consistency

* Rename MoneyAgentDF to MoneyAgents for consistency in agent set implementation

* Update tutorial to reflect renaming of agent classes from MoneyAgentPandas and MoneyAgentDF to MoneyAgentsConcise and MoneyAgentsNative

* Refactor MoneyModel and MoneyAgents classes for consistency and clarity in naming

* Update DataCollector tutorial with execution results and fix agent wealth calculations

* Refactor agent and model classes for consistency: rename MoneyModel to MesaMoneyModel and MoneyAgent to MesaMoneyAgent; update agent sets to MoneyAgentsConcise and MoneyAgentsNative.

* Fix agent type reference in SugarscapePolars model: update from AntPolarsBase to AntDFBase for consistency

* Fix model_reporters lambda function in ExampleModel to correctly sum agent wealth

* Refactor agent and model classes for consistency: update references from AbstractAgentSet to AgentSet and adjust related documentation.

* Fix missing newline at end of file in ExampleModel documentation

* Remove unused import of Model in agentset.py

* Fix class name in documentation: update Space to AbstractSpace for clarity

* Refactor AbstractAgentSet class: remove inheritance from AbstractAgentSetRegistry and add contains method overloads

* Add method overloads for do and implement remove method in AgentSet class

* Refactor AbstractAgentSet class: add remove method and improve agent management functionality

* Refactor AbstractAgentSetRegistry: update discard, add, and contains methods to use AgentSetSelector; enhance type annotations for clarity

* Refactor type aliases in types_.py: reorganize imports, enhance AgentSetSelector definitions, and add __all__ for better module export

* Refactor import statement in agentsetregistry.py: rename AbstractAgentSetSelector to AgentSetSelector for clarity

* Refactor AgentSetRegistry: streamline imports, rename parameters for clarity, and enhance type annotations

* Refactor AbstractAgentSetRegistry: add abstract methods keys, items, and values for improved agent set iteration

* Refactor AgentSetRegistry: add keys, items, and values methods for enhanced agent set iteration

* Refactor contains method in AgentSetRegistry: optimize type checks and improve handling of single values and iterables

* Refactor AgentSetRegistry: streamline method for resolving agent sets and improve key generation logic

* Refactor AgentSetRegistry: simplify key retrieval logic and enhance error handling in the get method

* Refactor AgentSetRegistry: implement _resolve_selector method for improved agent set selection and deduplication

* Refactor AgentSetRegistry: optimize agent removal logic and normalize selection using _resolve_selector method

* Refactor AgentSetRegistry: add replace method for bulk updating of agent sets and improve id recomputation logic

* Refactor AgentSetRegistry: simplify index key generation logic using yield from

* Refactor AbstractAgentSetRegistry: update parameter names and types for clarity and consistency

* Refactor AgentSet: update model parameter type for improved clarity

* Refactor get_unique_ids: update implementation for clarity and correctness

* Refactor AgentSet: enhance agent removal logic with validation for unique_ids

* Refactor AgentSetRegistry: improve agent set name assignment logic for uniqueness

* Refactor Model: update step method to use public registry API for invoking agent steps

* Refactor Space: improve agent ID validation and handling using public API

* Add comprehensive tests for AgentSetRegistry functionality

- Implemented unit tests for AgentSetRegistry, covering initialization, addition, removal, and retrieval of agent sets.
- Created example agent sets (ExampleAgentSetA and ExampleAgentSetB) to facilitate testing.
- Verified behavior for methods such as add, remove, contains, do, get, and various dunder methods.
- Ensured proper handling of edge cases, including duplicate names and model mismatches.
- Utilized pytest fixtures for consistent test setup and teardown.

* Enhance agent reporter functionality: support string collections and callable types for data collection

* Refactor agent reporter lambda functions to use sets parameter for wealth retrieval

* Refactor test assertions in TestAgentSetRegistry for improved readability and consistency

* Refactor DataCollector model reporters for improved efficiency and readability

* Fix execution counts in DataCollector tutorial notebook for consistency

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Implement rename functionality for AgentSet and AgentSetRegistry with conflict handling

* Refactor test assertion in TestAgentSetRegistry to use set literal for improved clarity

* Enhance parameter documentation for agent handling and rename functionality across multiple classes

* Update documentation to clarify usage of AgentSetRegistry and improve DataCollector examples

* fix ss_polars

* formatting

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix: remove conflict markers by preferring OURS from 2c43b3f^1

* remove old test_agents.py

* feat: add abstract rename method to AbstractAgentSet for consistent naming management

* feat: add abstract set method to AbstractAgentSet for updating agent attributes

* Remove obsolete OLD_concrete_accessors.py and OLD_concrete_agents.py files

These files contained outdated implementations of the AgentSetsAccessor and AgentsDF classes, which are no longer in use. Their removal helps to clean up the codebase and reduce confusion regarding the current architecture of the mesa-frames library.

* refactor: streamline key management methods in AgentSetRegistry and enforce model consistency

* feat: enhance key handling in AbstractAgentSetRegistry for string keys

* refactor: remove unused _skip_copy attribute from CopyMixin

* refactor: improve key handling and update logic in AgentSetRegistry

* fix: specify exception type in DataCollector to improve error handling

* refactor: optimize agent presence checks by using implode() for unique_id comparisons (#178)

* refactor: remove usage of implode() for unique_id comparisons across multiple files
feat: add seed property to Model for better random generator management
docs: update docstrings in AbstractDataCollector for consistency and clarity

* refactor: simplify key renaming logic in AbstractAgentSetRegistry

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* chore: update .gitignore to exclude benchmark results and documentation build artifacts

* refactor: introduce TypeAliasType for agent set selectors to avoid import cycles
feat: add typing-extensions dependency for enhanced type support

* refactor: enhance documentation for AbstractAgentSetSelector type alias to clarify usage and avoid import cycles

* import mesa-frames and also update function parameter

* fix redundant code

* rename used in name

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* remove private methods from abstract

* refactor: consider using a key-based structure for agentsets instead of a list in agentsdf

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* refactor: enhance AbstractAgentSet to utilize AgentMaskLiteral for key handling

* refactor: ensure agents are removed from space when detaching sets from registry

* refactor: update rename logic in AgentSet to correctly handle non-inplace renames

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Ben <[email protected]>
Co-authored-by: adamamer20 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Solving polars Deprecation warnings for is_in

2 participants