From d168eb6f9336a736d34446c75e1c405977d97b9b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 4 Sep 2024 13:13:20 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- mesa/agent.py | 22 +++++++++++----------- tests/test_agent.py | 1 + 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/mesa/agent.py b/mesa/agent.py index d952d1b0eca..4328c7a4b9a 100644 --- a/mesa/agent.py +++ b/mesa/agent.py @@ -142,12 +142,12 @@ def __contains__(self, agent: Agent) -> bool: return agent in self._agents def select( - self, - filter_func: Callable[[Agent], bool] | None = None, - at_most: int | float = float("inf"), - inplace: bool = False, - agent_type: type[Agent] | None = None, - n: int | None = None, + self, + filter_func: Callable[[Agent], bool] | None = None, + at_most: int | float = float("inf"), + inplace: bool = False, + agent_type: type[Agent] | None = None, + n: int | None = None, ) -> AgentSet: """ Select a subset of agents from the AgentSet based on a filter function and/or quantity limit. @@ -190,7 +190,7 @@ def agent_generator(filter_func, agent_type, at_most): if count >= at_most: break if (not filter_func or filter_func(agent)) and ( - not agent_type or isinstance(agent, agent_type) + not agent_type or isinstance(agent, agent_type) ): yield agent count += 1 @@ -225,10 +225,10 @@ def shuffle(self, inplace: bool = False) -> AgentSet: ) def sort( - self, - key: Callable[[Agent], Any] | str, - ascending: bool = False, - inplace: bool = False, + self, + key: Callable[[Agent], Any] | str, + ascending: bool = False, + inplace: bool = False, ) -> AgentSet: """ Sort the agents in the AgentSet based on a specified attribute or custom function. diff --git a/tests/test_agent.py b/tests/test_agent.py index 559ecc150a3..0c05b78e4fc 100644 --- a/tests/test_agent.py +++ b/tests/test_agent.py @@ -288,6 +288,7 @@ def test_agentset_get(): results = agentset.get("unknown_attribute", True) assert all(results) is True + def test_agentset_agg(): model = Model() agents = [TestAgent(model) for i in range(10)]