Skip to content

Commit 45963c3

Browse files
wang-boyurht
authored andcommitted
ci: apply ruff autofix
1 parent b883e07 commit 45963c3

File tree

7 files changed

+13
-20
lines changed

7 files changed

+13
-20
lines changed

examples/geo_schelling/server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def schelling_draw(agent):
2828
"""
2929
Portrayal Method for canvas
3030
"""
31-
portrayal = dict()
31+
portrayal = {}
3232
if agent.atype is None:
3333
portrayal["color"] = "Grey"
3434
elif agent.atype == 0:

examples/geo_schelling_points/geo_schelling_points/model.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,8 @@ def __init__(self, red_percentage=0.5, similarity_threshold=0.5):
4949
def unhappy(self):
5050
num_unhappy = 0
5151
for agent in self.space.agents:
52-
if isinstance(agent, PersonAgent):
53-
if agent.is_unhappy:
54-
num_unhappy += 1
52+
if isinstance(agent, PersonAgent) and agent.is_unhappy:
53+
num_unhappy += 1
5554
return num_unhappy
5655

5756
@property

examples/geo_schelling_points/geo_schelling_points/server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def render(self, model):
2525

2626

2727
def schelling_draw(agent):
28-
portrayal = dict()
28+
portrayal = {}
2929
if isinstance(agent, RegionAgent):
3030
if agent.red_cnt > agent.blue_cnt:
3131
portrayal["color"] = "Red"

examples/geo_sir/server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def infected_draw(agent):
3232
"""
3333
Portrayal Method for canvas
3434
"""
35-
portrayal = dict()
35+
portrayal = {}
3636
if isinstance(agent, PersonAgent):
3737
portrayal["radius"] = "2"
3838
if agent.atype in ["hotspot", "infected"]:

examples/rainfall/rainfall/model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def step(self):
5252
),
5353
key=lambda cell: cell.elevation + cell.water_level,
5454
).pos
55-
if not lowest_pos == self.pos:
55+
if lowest_pos != self.pos:
5656
self.model.space.move_raindrop(self, lowest_pos)
5757

5858

examples/urban_growth/urban_growth/space.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,18 +97,17 @@ def load_datasets(
9797
"land_use": land_use_data,
9898
}
9999
for attribute_name, data_file in data.items():
100-
with gzip.open(data_file, "rb") as f:
101-
with rio.open(f, "r") as dataset:
102-
values = dataset.read()
100+
with gzip.open(data_file, "rb") as f, rio.open(f, "r") as dataset:
101+
values = dataset.read()
103102
self.raster_layer.apply_raster(values, attr_name=attribute_name)
104103

105104
for cell in self.raster_layer:
106-
cell.urban = True if cell.urban == 2 else False
105+
cell.urban = cell.urban == 2
107106
cell.old_urbanized = cell.urban
108107

109108
def check_road(self):
110109
for cell in self.raster_layer:
111-
cell.road = True if cell.road_1 > 0 else False
110+
cell.road = cell.road_1 > 0
112111

113112
@property
114113
def raster_layer(self):

mesa_geo/geoagent.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,6 @@ def step(self):
7373
Advance one step.
7474
"""
7575

76-
pass
77-
7876
def __geo_interface__(self):
7977
"""
8078
Return a GeoJSON Feature. Removes geometry from attributes.
@@ -191,14 +189,14 @@ def from_GeoDataFrame(self, gdf, unique_id="index", set_attributes=True):
191189
f"{self.__class__.__name__} and {gdf.__class__.__name__}."
192190
)
193191

194-
agents = list()
192+
agents = []
195193
for index, row in gdf.iterrows():
196194
geometry = row[gdf.geometry.name]
197195
new_agent = self.create_agent(geometry=geometry, unique_id=index)
198196

199197
if set_attributes:
200198
for col in row.index:
201-
if not col == gdf.geometry.name:
199+
if col != gdf.geometry.name:
202200
setattr(new_agent, col, row[col])
203201
agents.append(new_agent)
204202

@@ -230,10 +228,7 @@ def from_GeoJSON(self, GeoJSON, unique_id="index", set_attributes=True):
230228
:param set_attributes: Set agent attributes from GeoDataFrame columns. Default True.
231229
"""
232230

233-
if type(GeoJSON) is str:
234-
gj = json.loads(GeoJSON)
235-
else:
236-
gj = GeoJSON
231+
gj = json.loads(GeoJSON) if type(GeoJSON) is str else GeoJSON
237232

238233
gdf = gpd.GeoDataFrame.from_features(gj)
239234
# epsg:4326 is the CRS for all GeoJSON: https://datatracker.ietf.org/doc/html/rfc7946#section-4

0 commit comments

Comments
 (0)