Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Sep 10, 2024
1 parent 89dc6c0 commit dc4fa7a
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 26 deletions.
9 changes: 2 additions & 7 deletions mesa_geo/geoagent.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import copy
import json
import warnings

import geopandas as gpd
import numpy as np
Expand Down Expand Up @@ -201,9 +200,7 @@ def from_file(self, filename, set_attributes=True):
"""

gdf = gpd.read_file(filename)
agents = self.from_GeoDataFrame(
gdf, set_attributes=set_attributes
)
agents = self.from_GeoDataFrame(gdf, set_attributes=set_attributes)
return agents

def from_GeoJSON(
Expand All @@ -223,7 +220,5 @@ def from_GeoJSON(
gdf = gpd.GeoDataFrame.from_features(gj)
# epsg:4326 is the CRS for all GeoJSON: https://datatracker.ietf.org/doc/html/rfc7946#section-4
gdf.crs = "epsg:4326"
agents = self.from_GeoDataFrame(
gdf, set_attributes=set_attributes
)
agents = self.from_GeoDataFrame(gdf, set_attributes=set_attributes)
return agents
8 changes: 2 additions & 6 deletions tests/test_AgentCreator.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,15 @@ def tearDown(self) -> None:
pass

def test_create_agent_with_crs(self):
agent = self.agent_creator_with_crs.create_agent(
geometry=Point(1, 1)
)
agent = self.agent_creator_with_crs.create_agent(geometry=Point(1, 1))
self.assertIsInstance(agent, mg.GeoAgent)
self.assertEqual(agent.geometry, Point(1, 1))
self.assertEqual(agent.model, self.model)
self.assertEqual(agent.crs, self.agent_creator_with_crs.crs)

def test_create_agent_without_crs(self):
with self.assertRaises(TypeError):
self.agent_creator_without_crs.create_agent(
geometry=Point(1, 1)
)
self.agent_creator_without_crs.create_agent(geometry=Point(1, 1))

def test_from_GeoDataFrame_with_default_geometry_name(self):
gdf = gpd.GeoDataFrame(
Expand Down
7 changes: 1 addition & 6 deletions tests/test_GeoSpace.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import random
import unittest
import uuid
import warnings

import geopandas as gpd
import mesa
import numpy as np
import pandas as pd
from shapely.geometry import Point, Polygon

import mesa_geo as mg
Expand Down Expand Up @@ -140,10 +138,7 @@ def test_get_neighbors_within_distance(self):
def test_get_agents_as_GeoDataFrame(self):
self.geo_space.add_agents(self.agents)

agents_list = [
{"geometry": agent.geometry}
for agent in self.agents
]
agents_list = [{"geometry": agent.geometry} for agent in self.agents]
agents_gdf = gpd.GeoDataFrame.from_records(agents_list)
# workaround for geometry column not being set in `from_records`
# see https://github.com/geopandas/geopandas/issues/3152
Expand Down
10 changes: 3 additions & 7 deletions tests/test_MapModule.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import unittest
import uuid

import mesa
import numpy as np
Expand All @@ -20,18 +19,15 @@ def setUp(self) -> None:
)
self.points = [Point(1, 1)] * 7
self.point_agents = [
self.agent_creator.create_agent(point)
for point in self.points
self.agent_creator.create_agent(point) for point in self.points
]
self.lines = [LineString([(1, 1), (2, 2)])] * 9
self.line_agents = [
self.agent_creator.create_agent(line)
for line in self.lines
self.agent_creator.create_agent(line) for line in self.lines
]
self.polygons = [Polygon([(1, 1), (2, 2), (4, 4)])] * 3
self.polygon_agents = [
self.agent_creator.create_agent(polygon)
for polygon in self.polygons
self.agent_creator.create_agent(polygon) for polygon in self.polygons
]
self.raster_layer = mg.RasterLayer(
1, 1, crs="epsg:4326", total_bounds=[0, 0, 1, 1], model=self.model
Expand Down

0 comments on commit dc4fa7a

Please sign in to comment.