Skip to content

Commit

Permalink
Initialise population dataframe with dict comprehension (#1186)
Browse files Browse the repository at this point in the history
Avoids `PerformanceWarning` due to repeated column insertion
  • Loading branch information
matt-graham authored Nov 13, 2023
1 parent 85e322c commit dc7f521
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/tlo/population.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,14 @@ def _create_props(self, size):
:param size: the number of rows to create
"""
props = pd.DataFrame(index=pd.RangeIndex(stop=size, name="person"))
for module in self.sim.modules.values():
for prop_name, prop in module.PROPERTIES.items():
props[prop_name] = prop.create_series(prop_name, size)
return props
return pd.DataFrame(
data={
property_name: property.create_series(property_name, size)
for module in self.sim.modules.values()
for property_name, property in module.PROPERTIES.items()
},
index=pd.RangeIndex(stop=size, name="person")
)

def do_birth(self):
"""Create a new person within the population.
Expand Down

0 comments on commit dc7f521

Please sign in to comment.