11
11
12
12
@tg .typechecked
13
13
class ExampleAgentSetPandas (AgentSetPandas ):
14
- def __init__ (self , model : ModelDF , index : pd . Index ):
14
+ def __init__ (self , model : ModelDF ):
15
15
super ().__init__ (model )
16
- self .starting_wealth = pd .Series ([1 , 2 , 3 , 4 ], name = "wealth" , index = index )
16
+ self .starting_wealth = pd .Series ([1 , 2 , 3 , 4 ], name = "wealth" )
17
17
18
18
def add_wealth (self , amount : int ) -> None :
19
19
self .agents ["wealth" ] += amount
@@ -25,7 +25,7 @@ def step(self) -> None:
25
25
@pytest .fixture
26
26
def fix1_AgentSetPandas () -> ExampleAgentSetPandas :
27
27
model = ModelDF ()
28
- agents = ExampleAgentSetPandas (model , pd . Index ([ 0 , 1 , 2 , 3 ], name = "unique_id" ) )
28
+ agents = ExampleAgentSetPandas (model )
29
29
agents .add ({"unique_id" : [0 , 1 , 2 , 3 ]})
30
30
agents ["wealth" ] = agents .starting_wealth
31
31
agents ["age" ] = [10 , 20 , 30 , 40 ]
@@ -36,7 +36,7 @@ def fix1_AgentSetPandas() -> ExampleAgentSetPandas:
36
36
@pytest .fixture
37
37
def fix2_AgentSetPandas () -> ExampleAgentSetPandas :
38
38
model = ModelDF ()
39
- agents = ExampleAgentSetPandas (model , pd . Index ([ 4 , 5 , 6 , 7 ], name = "unique_id" ) )
39
+ agents = ExampleAgentSetPandas (model )
40
40
agents .add ({"unique_id" : [4 , 5 , 6 , 7 ]})
41
41
agents ["wealth" ] = agents .starting_wealth + 10
42
42
agents ["age" ] = [100 , 200 , 300 , 400 ]
@@ -55,7 +55,7 @@ def fix1_AgentSetPandas_with_pos(fix1_AgentSetPandas) -> ExampleAgentSetPandas:
55
55
class Test_AgentSetPandas :
56
56
def test__init__ (self ):
57
57
model = ModelDF ()
58
- agents = ExampleAgentSetPandas (model , pd . Index ([ 0 , 1 , 2 , 3 ]) )
58
+ agents = ExampleAgentSetPandas (model )
59
59
assert agents .model == model
60
60
assert isinstance (agents .agents , pd .DataFrame )
61
61
assert agents .agents .index .name == "unique_id"
@@ -86,7 +86,6 @@ def test_add(
86
86
# Test with a dict[str, Any]
87
87
agents .add ({"unique_id" : [4 , 5 ], "wealth" : [5 , 6 ], "age" : [50 , 60 ]})
88
88
assert agents .agents .wealth .tolist () == [1 , 2 , 3 , 4 , 5 , 6 ]
89
- assert agents .agents .index .tolist () == [0 , 1 , 2 , 3 , 4 , 5 ]
90
89
assert agents .agents .age .tolist () == [10 , 20 , 30 , 40 , 50 , 60 ]
91
90
assert agents .agents .index .name == "unique_id"
92
91
@@ -287,7 +286,6 @@ def test__add__(
287
286
288
287
# Test with an AgentSetPandas and a dict
289
288
agents3 = agents + {"unique_id" : 10 , "wealth" : 5 }
290
- assert agents3 .agents .index .tolist () == [0 , 1 , 2 , 3 , 10 ]
291
289
assert agents3 .agents .wealth .tolist () == [1 , 2 , 3 , 4 , 5 ]
292
290
293
291
def test__contains__ (self , fix1_AgentSetPandas : ExampleAgentSetPandas ):
@@ -360,7 +358,6 @@ def test__iadd__(
360
358
# Test with an AgentSetPandas and a dict
361
359
agents = deepcopy (fix1_AgentSetPandas )
362
360
agents += {"unique_id" : 10 , "wealth" : 5 }
363
- assert agents .agents .index .tolist () == [0 , 1 , 2 , 3 , 10 ]
364
361
assert agents .agents .wealth .tolist () == [1 , 2 , 3 , 4 , 5 ]
365
362
366
363
def test__iter__ (self , fix1_AgentSetPandas : ExampleAgentSetPandas ):
@@ -439,24 +436,24 @@ def test_agents(
439
436
440
437
# Test agents.setter
441
438
agents .agents = agents2 .agents
442
- assert agents .agents . index . tolist ( ) == [ 4 , 5 , 6 , 7 ]
439
+ assert len ( agents .active_agents ) == 4
443
440
444
441
def test_active_agents (self , fix1_AgentSetPandas : ExampleAgentSetPandas ):
445
442
agents = fix1_AgentSetPandas
446
443
447
444
# Test with select
448
445
agents .select (agents ["wealth" ] > 2 , inplace = True )
449
- assert agents .active_agents . index . tolist ( ) == [ 2 , 3 ]
446
+ assert len ( agents .active_agents ) == 2
450
447
451
448
# Test with active_agents.setter
452
449
agents .active_agents = agents .agents .wealth > 2
453
- assert agents .active_agents . index . to_list ( ) == [ 2 , 3 ]
450
+ assert len ( agents .active_agents ) == 2
454
451
455
452
def test_inactive_agents (self , fix1_AgentSetPandas : ExampleAgentSetPandas ):
456
453
agents = fix1_AgentSetPandas
457
454
458
455
agents .select (agents ["wealth" ] > 2 , inplace = True )
459
- assert agents .inactive_agents . index . to_list ( ) == [ 0 , 1 ]
456
+ assert len ( agents .active_agents ) == 2
460
457
461
458
def test_pos (self , fix1_AgentSetPandas_with_pos : ExampleAgentSetPandas ):
462
459
pos = fix1_AgentSetPandas_with_pos .pos
0 commit comments