Skip to content

Commit

Permalink
fix AttributeError when creating geodataframe from geoagents
Browse files Browse the repository at this point in the history
  • Loading branch information
wang-boyu committed Mar 23, 2024
1 parent a256729 commit c307dbc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions mesa_geo/geospace.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,5 +458,9 @@ def get_agents_as_GeoDataFrame(self, agent_cls=GeoAgent) -> gpd.GeoDataFrame:
}
agents_list.append(agent_dict)
agents_gdf = gpd.GeoDataFrame.from_records(agents_list, index="unique_id")
# workaround for geometry column not being set in `from_records`
# see https://github.com/geopandas/geopandas/issues/3152
# may be removed when the issue is resolved
agents_gdf.set_geometry("geometry", inplace=True)
agents_gdf.crs = crs
return agents_gdf
4 changes: 4 additions & 0 deletions tests/test_GeoSpace.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ def test_get_agents_as_GeoDataFrame(self):
for agent in self.agents
]
agents_gdf = gpd.GeoDataFrame.from_records(agents_list, index="unique_id")
# workaround for geometry column not being set in `from_records`
# see https://github.com/geopandas/geopandas/issues/3152
# may be removed when the issue is resolved
agents_gdf.set_geometry("geometry", inplace=True)
agents_gdf.crs = self.geo_space.crs

pd.testing.assert_frame_equal(
Expand Down

0 comments on commit c307dbc

Please sign in to comment.