Skip to content

Rename 'agents' property to 'df' for AgentContainer for issue # 68 #148

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions mesa_frames/abstract/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
Series,
)

import warnings

if TYPE_CHECKING:
from mesa_frames.abstract.space import SpaceDF
from mesa_frames.concrete.agents import AgentSetDF
Expand Down Expand Up @@ -645,6 +647,26 @@
"""
return self.model.space

@property
@abstractmethod
def df(self) -> DataFrame | dict[str, DataFrame]:
"""The agents in the AgentContainer.

Returns
-------
DataFrame | dict[str, DataFrame]
"""

@df.setter
@abstractmethod
def df(self, agents: DataFrame | list[AgentSetDF]) -> None:
"""Set the agents in the AgentContainer.

Parameters
----------
agents : DataFrame | list[AgentSetDF]
"""

@property
@abstractmethod
def agents(self) -> DataFrame | dict[str, DataFrame]:
Expand All @@ -664,6 +686,11 @@
----------
agents : DataFrame | list[AgentSetDF]
"""
warnings.warn(

Check warning on line 689 in mesa_frames/abstract/agents.py

View check run for this annotation

Codecov / codecov/patch

mesa_frames/abstract/agents.py#L689

Added line #L689 was not covered by tests
"Setting 'agents' is deprecated. Use 'df' instead.",
DeprecationWarning,
stacklevel=2,
)

@property
@abstractmethod
Expand Down Expand Up @@ -1038,8 +1065,28 @@
def __reversed__(self) -> Iterator:
return reversed(self._agents)

@property
def df(self) -> DataFrame:
return self._agents

Check warning on line 1070 in mesa_frames/abstract/agents.py

View check run for this annotation

Codecov / codecov/patch

mesa_frames/abstract/agents.py#L1070

Added line #L1070 was not covered by tests

@df.setter
def df(self, agents: DataFrame) -> None:
"""Set the agents in the AgentSetDF.

Parameters
----------
agents : DataFrame
The agents to set.
"""
self._agents = agents

Check warning on line 1081 in mesa_frames/abstract/agents.py

View check run for this annotation

Codecov / codecov/patch

mesa_frames/abstract/agents.py#L1081

Added line #L1081 was not covered by tests

@property
def agents(self) -> DataFrame:
warnings.warn(

Check warning on line 1085 in mesa_frames/abstract/agents.py

View check run for this annotation

Codecov / codecov/patch

mesa_frames/abstract/agents.py#L1085

Added line #L1085 was not covered by tests
"'agents' is deprecated. Use 'df' instead.",
DeprecationWarning,
stacklevel=2,
)
return self._agents

@agents.setter
Expand All @@ -1051,6 +1098,11 @@
agents : DataFrame
The agents to set.
"""
warnings.warn(

Check warning on line 1101 in mesa_frames/abstract/agents.py

View check run for this annotation

Codecov / codecov/patch

mesa_frames/abstract/agents.py#L1101

Added line #L1101 was not covered by tests
"Setting 'agents' is deprecated. Use 'df' instead.",
DeprecationWarning,
stacklevel=2,
)
self._agents = agents

@property
Expand Down
27 changes: 27 additions & 0 deletions mesa_frames/concrete/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@
Series,
)

import warnings

if TYPE_CHECKING:
from mesa_frames.concrete.model import ModelDF

Expand Down Expand Up @@ -553,12 +555,37 @@

@property
def agents(self) -> dict[AgentSetDF, DataFrame]:
warnings.warn(
"'agents' is deprecated. Use 'df' instead.",
DeprecationWarning,
stacklevel=2,
)
return {agentset: agentset.agents for agentset in self._agentsets}

@agents.setter
def agents(self, other: Iterable[AgentSetDF]) -> None:
"""Set the agents in the AgentsDF.

Parameters
----------
other : Iterable[AgentSetDF]
The AgentSetDFs to set.
"""
warnings.warn(

Check warning on line 574 in mesa_frames/concrete/agents.py

View check run for this annotation

Codecov / codecov/patch

mesa_frames/concrete/agents.py#L574

Added line #L574 was not covered by tests
"Setting 'agents' is deprecated. Use 'df' instead.",
DeprecationWarning,
stacklevel=2,
)
self._agentsets = list(other)

Check warning on line 579 in mesa_frames/concrete/agents.py

View check run for this annotation

Codecov / codecov/patch

mesa_frames/concrete/agents.py#L579

Added line #L579 was not covered by tests

@property
def df(self) -> dict[AgentSetDF, DataFrame]:
return {agentset: agentset.agents for agentset in self._agentsets}

Check warning on line 583 in mesa_frames/concrete/agents.py

View check run for this annotation

Codecov / codecov/patch

mesa_frames/concrete/agents.py#L583

Added line #L583 was not covered by tests

@agents.setter
def df(self, other: Iterable[AgentSetDF]) -> None:
"""Set the agents in the AgentsDF.

Parameters
----------
other : Iterable[AgentSetDF]
Expand Down
21 changes: 21 additions & 0 deletions mesa_frames/concrete/agentset.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
from mesa_frames.concrete.model import ModelDF

import numpy as np
import warnings


@copydoc(AgentSetDF)
Expand Down Expand Up @@ -495,12 +496,32 @@
def __reversed__(self) -> Iterator:
return reversed(iter(self._agents.iter_rows(named=True)))

@property
def df(self) -> pl.DataFrame:
return self._agents

@df.setter
def df(self, agents: pl.DataFrame) -> None:
if "unique_id" not in agents.columns:
raise KeyError("DataFrame must have a unique_id column.")

Check warning on line 506 in mesa_frames/concrete/agentset.py

View check run for this annotation

Codecov / codecov/patch

mesa_frames/concrete/agentset.py#L506

Added line #L506 was not covered by tests
self._agents = agents

@property
def agents(self) -> pl.DataFrame:
warnings.warn(
"'agents' is deprecated. Use 'df' instead.",
DeprecationWarning,
stacklevel=2,
)
return self._agents

@agents.setter
def agents(self, agents: pl.DataFrame) -> None:
warnings.warn(

Check warning on line 520 in mesa_frames/concrete/agentset.py

View check run for this annotation

Codecov / codecov/patch

mesa_frames/concrete/agentset.py#L520

Added line #L520 was not covered by tests
"Setting 'agents' is deprecated. Use 'df' instead.",
DeprecationWarning,
stacklevel=2,
)
if "unique_id" not in agents.columns:
raise KeyError("DataFrame must have a unique_id column.")
self._agents = agents
Expand Down
Loading