Skip to content
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

Delete magic agent attributes #116

Merged
merged 8 commits into from
Oct 24, 2024
Merged

Conversation

mariuzka
Copy link
Owner

No description provided.

@mariuzka
Copy link
Owner Author

Any idea why it failed @luerhard ?

@luerhard
Copy link
Collaborator

The error is:

/home/lukas/.pyenv/versions/3.12.3/lib/python3.12/importlib/__init__.py:90: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
<frozen importlib._bootstrap>:1387: in _gcd_import
    ???
<frozen importlib._bootstrap>:1360: in _find_and_load
    ???
<frozen importlib._bootstrap>:1331: in _find_and_load_unlocked
    ???
<frozen importlib._bootstrap>:935: in _load_unlocked
    ???
.venv/lib/python3.12/site-packages/_pytest/assertion/rewrite.py:184: in exec_module
    exec(co, module.__dict__)
/mnt/nvme_storage/git/pop2net/tests/test_location/test_combinations/test_split_nest.py:97: in <module>
    ???
/mnt/nvme_storage/git/pop2net/tests/test_location/test_combinations/test_split_nest.py:42: in test_1
    ???
/mnt/nvme_storage/git/pop2net/tests/test_location/test_combinations/test_split_nest.py:46: in <genexpr>
    ???
.venv/lib/python3.12/site-packages/agentpy/objects.py:27: in __getattr__
    raise AttributeError(f"{self} has no attribute '{key}'.")
E   AttributeError: Agent (Obj 1) has no attribute 'School'.

First of all, @schorki9 -- please DO NOT execute test functions in these files (see the following line):

@luerhard
Copy link
Collaborator

Secondly, this is the line that breaks.

assert not all(
location.agents[0].School == location.agents[1].School
for location in model.locations
if location.type == "Classroom"
)

@luerhard
Copy link
Collaborator

Once this is fixed, it will most certainly break again here:

assert all(agent.School == nghbr.School for nghbr in agent.neighbors())

@luerhard
Copy link
Collaborator

Just for reference, this is the actual test-output when the test runner itself does not crash from wrongly executed code:

================================================================== FAILURES ==================================================================
___________________________________________________________________ test_1 ___________________________________________________________________

    def test_1():
        df = pd.DataFrame(
            {
                "status": ["pupil", "pupil", "pupil", "pupil", "pupil", "pupil", "pupil", "pupil"],
                "group": [1, 2, 1, 2, 1, 2, 1, 2],
                "_id": [1, 2, 3, 4, 5, 6, 7, 8],
            }
        )

        class School(p2n.MagicLocation):
            n_agents = 4

        class Classroom(p2n.MagicLocation):
            n_agents = 2

            def split(self, agent):
                return agent.group

        model = p2n.Model()
        creator = p2n.Creator(model=model)
        creator.create(df=df, location_classes=[School, Classroom])

        assert len(model.agents) == 8
        assert len(model.locations) == 6

        for location in model.locations:
            if location.type == "School":
                assert len(location.agents) == 4
                counter = Counter([agent.group for agent in location.agents])
                assert counter[1] == 2
                assert counter[2] == 2

>       assert not all(
            location.agents[0].School == location.agents[1].School
            for location in model.locations
            if location.type == "Classroom"
        )

tests/test_location/test_combinations/test_split_nest.py:42:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
tests/test_location/test_combinations/test_split_nest.py:46: in <genexpr>
    )
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = Agent (Obj 1), key = 'School'

    def __getattr__(self, key):
>       raise AttributeError(f"{self} has no attribute '{key}'.")
E       AttributeError: Agent (Obj 1) has no attribute 'School'.

.venv/lib/python3.12/site-packages/agentpy/objects.py:27: AttributeError

@mariuzka mariuzka merged commit 3833de7 into dev Oct 24, 2024
4 checks passed
@mariuzka mariuzka deleted the delete-magic-attributes-and-methods branch October 24, 2024 09:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants