From 585d1f6721d430e7846acf0b1d6da6536e4b9ab8 Mon Sep 17 00:00:00 2001 From: Ewout ter Hoeven Date: Thu, 14 Dec 2023 14:21:49 +0100 Subject: [PATCH] Update get_agent_data_from_coord_iter to allow no agents on the grid --- src/mesa_interactive/components/grid.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/mesa_interactive/components/grid.py b/src/mesa_interactive/components/grid.py index 2cc3db3..fef519f 100644 --- a/src/mesa_interactive/components/grid.py +++ b/src/mesa_interactive/components/grid.py @@ -6,18 +6,18 @@ import solara -def get_agent_data_from_coord_iter(data): - for agent, (x, y) in data: - if agent: - agent_data = json.loads( - json.dumps(agent.__dict__, skipkeys=True, default=str) - ) - agent_data["x"] = x - agent_data["y"] = y - agent_data.pop("model", None) - agent_data.pop("pos", None) - yield agent_data - +def get_agent_data_from_coord_iter(agents_per_coordinate): + for agents, (x, y) in agents_per_coordinate: + if agents: # Checking if the list is non-empty + for agent in agents: + agent_data = json.loads( + json.dumps(agent.__dict__, skipkeys=True, default=str) + ) + agent_data["x"] = x + agent_data["y"] = y + agent_data.pop("model", None) + agent_data.pop("pos", None) + yield agent_data def create_grid( color: str | None = None,