Skip to content

Commit 1d04e65

Browse files
committed
breaking: space: Remove deprecated position_agent
1 parent b83dff1 commit 1d04e65

File tree

3 files changed

+1
-56
lines changed

3 files changed

+1
-56
lines changed

mesa/space.py

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -504,42 +504,6 @@ class SingleGrid(_Grid):
504504
torus: Boolean which determines whether to treat the grid as a torus.
505505
"""
506506

507-
def position_agent(
508-
self, agent: Agent, x: int | str = "random", y: int | str = "random"
509-
) -> None:
510-
"""Position an agent on the grid.
511-
This is used when first placing agents! Setting either x or y to "random"
512-
gives the same behavior as 'move_to_empty()' to get a random position.
513-
If x or y are positive, they are used.
514-
Use 'swap_pos()' to swap agents positions.
515-
"""
516-
warn(
517-
(
518-
"`position_agent` is being deprecated; use instead "
519-
"`place_agent` to place an agent at a specified "
520-
"location or `move_to_empty` to place an agent "
521-
"at a random empty cell."
522-
),
523-
DeprecationWarning,
524-
)
525-
526-
if not (isinstance(x, int) or x == "random"):
527-
raise Exception(
528-
"x must be an integer or a string 'random'."
529-
f" Actual type: {type(x)}. Actual value: {x}."
530-
)
531-
if not (isinstance(y, int) or y == "random"):
532-
raise Exception(
533-
"y must be an integer or a string 'random'."
534-
f" Actual type: {type(y)}. Actual value: {y}."
535-
)
536-
537-
if x == "random" or y == "random":
538-
self.move_to_empty(agent)
539-
else:
540-
coords = (x, y)
541-
self.place_agent(agent, coords)
542-
543507
def place_agent(self, agent: Agent, pos: Coordinate) -> None:
544508
"""Place the agent at the specified location, and set its pos variable."""
545509
if self.is_cell_empty(pos):

tests/test_grid.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -268,25 +268,6 @@ def setUp(self):
268268
self.grid.place_agent(a, (x, y))
269269
self.num_agents = len(self.agents)
270270

271-
@patch.object(MockAgent, "model", create=True)
272-
def test_position_agent(self, mock_model):
273-
a = MockAgent(100, None)
274-
with self.assertRaises(Exception) as exc_info:
275-
self.grid.position_agent(a, (1, 1))
276-
expected = (
277-
"x must be an integer or a string 'random'."
278-
" Actual type: <class 'tuple'>. Actual value: (1, 1)."
279-
)
280-
assert str(exc_info.exception) == expected
281-
with self.assertRaises(Exception) as exc_info:
282-
self.grid.position_agent(a, "(1, 1)")
283-
expected = (
284-
"x must be an integer or a string 'random'."
285-
" Actual type: <class 'str'>. Actual value: (1, 1)."
286-
)
287-
assert str(exc_info.exception) == expected
288-
self.grid.position_agent(a, "random")
289-
290271
@patch.object(MockAgent, "model", create=True)
291272
def test_enforcement(self, mock_model):
292273
"""

tests/test_space.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ def test_empty_cells(self):
308308
if self.space.exists_empty_cells():
309309
for i, pos in enumerate(list(self.space.empties)):
310310
a = MockAgent(-i, pos)
311-
self.space.position_agent(a, x=pos[0], y=pos[1])
311+
self.space.place_agent(a, x=pos[0], y=pos[1])
312312
with self.assertRaises(Exception):
313313
self.space.move_to_empty(a)
314314

0 commit comments

Comments
 (0)