Skip to content

Commit 7c1d30a

Browse files
authored
linting & formatting for benchmarks/* and docs/* (pysal#578)
* update pre-commit ruff * update pre-commit & pyproject * update pyproject * lint & format benchmarks/* and docs/* * update pre-commit config * add ruff.toml to docs * test commit * test commit [2] * test commit [3] * fine-tuned ruff
1 parent 36b13f8 commit 7c1d30a

25 files changed

+4397
-3880
lines changed

.pre-commit-config.yaml

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
files: 'momepy\/'
21
repos:
32
- repo: https://github.com/astral-sh/ruff-pre-commit
4-
rev: "v0.3.5"
3+
rev: "v0.4.4"
54
hooks:
65
- id: ruff
76
- id: ruff-format

docs/conf.py

+12-5
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
# -- Project information -----------------------------------------------------
4343

4444
project = "momepy"
45-
copyright = "2018-, Martin Fleischmann and PySAL Developers"
45+
copyright = "2018-, Martin Fleischmann and PySAL Developers" # noqa: A001
4646
author = "Martin Fleischmann"
4747

4848
# The short X.Y version
@@ -186,7 +186,13 @@ def setup(app):
186186
# (source start file, target name, title,
187187
# author, documentclass [howto, manual, or own class]).
188188
latex_documents = [
189-
(master_doc, "momepy.tex", "momepy Documentation", "Martin Fleischmann", "manual")
189+
(
190+
master_doc,
191+
"momepy.tex",
192+
"momepy Documentation",
193+
"Martin Fleischmann",
194+
"manual",
195+
)
190196
]
191197

192198

@@ -232,10 +238,11 @@ def setup(app):
232238
# A list of files that should not be packed into the epub file.
233239
epub_exclude_files = ["search.html"]
234240

235-
# Add redirect for previously existing pages, each item is like `(from_old, to_new)`
241+
# Add redirect for previously existing pages,
242+
# each item is like `(from_old, to_new)`
236243

237244
rediraffe_redirects = {
238-
"user_guide/elements/preprocessing.ipynb": "user_guide/preprocessing/simple_preprocessing.ipynb", # noqa
245+
"user_guide/elements/preprocessing.ipynb": "user_guide/preprocessing/simple_preprocessing.ipynb", # noqa: E501
239246
}
240247

241248
# -- Extension configuration -------------------------------------------------
@@ -261,7 +268,7 @@ def setup(app):
261268
| Interactive online version: :raw-html:`<a href="https://mybinder.org/v2/gh/pysal/momepy/master?urlpath=lab/tree/docs/{{ docname }}"><img alt="Binder badge" src="https://mybinder.org/badge_logo.svg" style="vertical-align:text-bottom"></a>`
262269
263270
__ https://github.com/pysal/momepy/blob/master/docs/{{ docname }}
264-
"""
271+
""" # noqa: E501
265272

266273

267274
def linkcode_resolve(domain, info):

docs/examples/clustering.ipynb

+3,109-3,049
Large diffs are not rendered by default.

docs/ruff.toml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
line-length = 80
2+
lint.select = ["E", "F", "W", "I", "UP", "N", "B", "A", "C4", "SIM", "ARG"]
3+
lint.ignore = ["B006", "SIM108"]
4+
include = ["*.py", "*.ipynb"]

docs/user_guide/combined/distribution.ipynb

+79-60
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@
1515
"metadata": {},
1616
"outputs": [],
1717
"source": [
18-
"import momepy\n",
19-
"import geopandas as gpd\n",
20-
"import matplotlib.pyplot as plt"
18+
"import matplotlib.pyplot as plt\n",
19+
"import momepy"
2120
]
2221
},
2322
{
@@ -52,12 +51,16 @@
5251
"source": [
5352
"import osmnx as ox\n",
5453
"\n",
55-
"gdf = ox.geometries.geometries_from_place('Kahla, Germany', tags={'building': True})\n",
54+
"gdf = ox.geometries.geometries_from_place(\n",
55+
" \"Kahla, Germany\", tags={\"building\": True}\n",
56+
")\n",
5657
"buildings = ox.projection.project_gdf(gdf)\n",
5758
"\n",
58-
"buildings['uID'] = momepy.unique_id(buildings)\n",
59+
"buildings[\"uID\"] = momepy.unique_id(buildings)\n",
5960
"limit = momepy.buffered_limit(buildings)\n",
60-
"tessellation = momepy.Tessellation(buildings, unique_id='uID', limit=limit).tessellation"
61+
"tessellation = momepy.Tessellation(\n",
62+
" buildings, unique_id=\"uID\", limit=limit\n",
63+
").tessellation"
6164
]
6265
},
6366
{
@@ -66,10 +69,15 @@
6669
"metadata": {},
6770
"outputs": [],
6871
"source": [
69-
"streets_graph = ox.graph_from_place('Kahla, Germany', network_type='drive')\n",
72+
"streets_graph = ox.graph_from_place(\"Kahla, Germany\", network_type=\"drive\")\n",
7073
"streets_graph = ox.projection.project_graph(streets_graph)\n",
71-
"edges = ox.graph_to_gdfs(streets_graph, nodes=False, edges=True,\n",
72-
" node_geometry=False, fill_edge_geometry=True)"
74+
"edges = ox.graph_to_gdfs(\n",
75+
" streets_graph,\n",
76+
" nodes=False,\n",
77+
" edges=True,\n",
78+
" node_geometry=False,\n",
79+
" fill_edge_geometry=True,\n",
80+
")"
7381
]
7482
},
7583
{
@@ -123,8 +131,8 @@
123131
}
124132
],
125133
"source": [
126-
"buildings['orientation'] = momepy.Orientation(buildings).series\n",
127-
"tessellation['orientation'] = momepy.Orientation(tessellation).series"
134+
"buildings[\"orientation\"] = momepy.Orientation(buildings).series\n",
135+
"tessellation[\"orientation\"] = momepy.Orientation(tessellation).series"
128136
]
129137
},
130138
{
@@ -150,8 +158,9 @@
150158
}
151159
],
152160
"source": [
153-
"buildings.plot(column='orientation', legend=True, cmap='Spectral',\n",
154-
" figsize=(10, 10)).set_axis_off()"
161+
"buildings.plot(\n",
162+
" column=\"orientation\", legend=True, cmap=\"Spectral\", figsize=(10, 10)\n",
163+
").set_axis_off()"
155164
]
156165
},
157166
{
@@ -167,10 +176,10 @@
167176
"metadata": {},
168177
"outputs": [],
169178
"source": [
170-
"blg_cell_align = momepy.CellAlignment(buildings, tessellation,\n",
171-
" 'orientation', 'orientation',\n",
172-
" 'uID', 'uID')\n",
173-
"buildings['cell_align'] = blg_cell_align.series"
179+
"blg_cell_align = momepy.CellAlignment(\n",
180+
" buildings, tessellation, \"orientation\", \"orientation\", \"uID\", \"uID\"\n",
181+
")\n",
182+
"buildings[\"cell_align\"] = blg_cell_align.series"
174183
]
175184
},
176185
{
@@ -196,8 +205,9 @@
196205
}
197206
],
198207
"source": [
199-
"buildings.plot(column='cell_align', legend=True, cmap='Reds',\n",
200-
" figsize=(10, 10)).set_axis_off()"
208+
"buildings.plot(\n",
209+
" column=\"cell_align\", legend=True, cmap=\"Reds\", figsize=(10, 10)\n",
210+
").set_axis_off()"
201211
]
202212
},
203213
{
@@ -244,9 +254,10 @@
244254
}
245255
],
246256
"source": [
247-
"edges['networkID'] = momepy.unique_id(edges)\n",
248-
"buildings['networkID'] = momepy.get_network_id(buildings, edges,\n",
249-
" 'networkID').values"
257+
"edges[\"networkID\"] = momepy.unique_id(edges)\n",
258+
"buildings[\"networkID\"] = momepy.get_network_id(\n",
259+
" buildings, edges, \"networkID\"\n",
260+
").values"
250261
]
251262
},
252263
{
@@ -332,10 +343,10 @@
332343
}
333344
],
334345
"source": [
335-
"str_align = momepy.StreetAlignment(buildings_net, edges,\n",
336-
" 'orientation', 'networkID',\n",
337-
" 'networkID')\n",
338-
"buildings_net['str_align'] = str_align.series"
346+
"str_align = momepy.StreetAlignment(\n",
347+
" buildings_net, edges, \"orientation\", \"networkID\", \"networkID\"\n",
348+
")\n",
349+
"buildings_net[\"str_align\"] = str_align.series"
339350
]
340351
},
341352
{
@@ -361,8 +372,8 @@
361372
}
362373
],
363374
"source": [
364-
"ax = edges.plot(color='grey', linewidth=0.5, figsize=(10, 10))\n",
365-
"buildings_net.plot(ax=ax, column='str_align', legend=True)\n",
375+
"ax = edges.plot(color=\"grey\", linewidth=0.5, figsize=(10, 10))\n",
376+
"buildings_net.plot(ax=ax, column=\"str_align\", legend=True)\n",
366377
"ax.set_axis_off()"
367378
]
368379
},
@@ -383,9 +394,11 @@
383394
"source": [
384395
"point = (40.731603, -73.977857)\n",
385396
"dist = 1000\n",
386-
"gdf = ox.geometries.geometries_from_point(point, dist=dist, tags={'building':True})\n",
397+
"gdf = ox.geometries.geometries_from_point(\n",
398+
" point, dist=dist, tags={\"building\": True}\n",
399+
")\n",
387400
"buildings = ox.projection.project_gdf(gdf)\n",
388-
"buildings = buildings[buildings.geom_type.isin(['Polygon', 'MultiPolygon'])]"
401+
"buildings = buildings[buildings.geom_type.isin([\"Polygon\", \"MultiPolygon\"])]"
389402
]
390403
},
391404
{
@@ -400,7 +413,8 @@
400413
" except ValueError:\n",
401414
" return 0\n",
402415
"\n",
403-
"buildings['height'] = buildings['height'].fillna(0).apply(clean_heights)\n",
416+
"\n",
417+
"buildings[\"height\"] = buildings[\"height\"].fillna(0).apply(clean_heights)\n",
404418
"buildings = buildings.reset_index().explode()\n",
405419
"buildings.reset_index(inplace=True, drop=True)"
406420
]
@@ -411,10 +425,15 @@
411425
"metadata": {},
412426
"outputs": [],
413427
"source": [
414-
"streets_graph = ox.graph_from_point(point, dist, network_type='drive')\n",
428+
"streets_graph = ox.graph_from_point(point, dist, network_type=\"drive\")\n",
415429
"streets_graph = ox.projection.project_graph(streets_graph)\n",
416-
"edges = ox.graph_to_gdfs(streets_graph, nodes=False, edges=True,\n",
417-
" node_geometry=False, fill_edge_geometry=True)"
430+
"edges = ox.graph_to_gdfs(\n",
431+
" streets_graph,\n",
432+
" nodes=False,\n",
433+
" edges=True,\n",
434+
" node_geometry=False,\n",
435+
" fill_edge_geometry=True,\n",
436+
")"
418437
]
419438
},
420439
{
@@ -440,7 +459,7 @@
440459
}
441460
],
442461
"source": [
443-
"ax = buildings.plot(figsize=(10, 10), color='lightgrey')\n",
462+
"ax = buildings.plot(figsize=(10, 10), color=\"lightgrey\")\n",
444463
"edges.plot(ax=ax)\n",
445464
"ax.set_axis_off()"
446465
]
@@ -462,7 +481,7 @@
462481
}
463482
],
464483
"source": [
465-
"profile = momepy.StreetProfile(edges, buildings, heights='height')"
484+
"profile = momepy.StreetProfile(edges, buildings, heights=\"height\")"
466485
]
467486
},
468487
{
@@ -478,12 +497,12 @@
478497
"metadata": {},
479498
"outputs": [],
480499
"source": [
481-
"edges['widths'] = profile.w\n",
482-
"edges['width_deviations'] = profile.wd\n",
483-
"edges['openness'] = profile.o\n",
484-
"edges['heights'] = profile.h\n",
485-
"edges['heights_deviations'] = profile.hd\n",
486-
"edges['profile'] = profile.p"
500+
"edges[\"widths\"] = profile.w\n",
501+
"edges[\"width_deviations\"] = profile.wd\n",
502+
"edges[\"openness\"] = profile.o\n",
503+
"edges[\"heights\"] = profile.h\n",
504+
"edges[\"heights_deviations\"] = profile.hd\n",
505+
"edges[\"profile\"] = profile.p"
487506
]
488507
},
489508
{
@@ -510,30 +529,30 @@
510529
],
511530
"source": [
512531
"f, axes = plt.subplots(figsize=(15, 25), ncols=2, nrows=3)\n",
513-
"edges.plot(ax=axes[0][0], column='widths', legend=True, cmap='Blues_r')\n",
514-
"buildings.plot(ax=axes[0][0], color='lightgrey')\n",
515-
"edges.plot(ax=axes[0][1], column='width_deviations', legend=True)\n",
516-
"buildings.plot(ax=axes[0][1], color='lightgrey')\n",
532+
"edges.plot(ax=axes[0][0], column=\"widths\", legend=True, cmap=\"Blues_r\")\n",
533+
"buildings.plot(ax=axes[0][0], color=\"lightgrey\")\n",
534+
"edges.plot(ax=axes[0][1], column=\"width_deviations\", legend=True)\n",
535+
"buildings.plot(ax=axes[0][1], color=\"lightgrey\")\n",
517536
"axes[0][0].set_axis_off()\n",
518-
"axes[0][0].set_title('widths')\n",
537+
"axes[0][0].set_title(\"widths\")\n",
519538
"axes[0][1].set_axis_off()\n",
520-
"axes[0][1].set_title('width_deviations')\n",
521-
"edges.plot(ax=axes[1][0], column='profile', legend=True, cmap='Spectral')\n",
522-
"buildings.plot(ax=axes[1][0], color='lightgrey')\n",
523-
"edges.plot(ax=axes[1][1], column='openness', legend=True, cmap='Greens')\n",
524-
"buildings.plot(ax=axes[1][1], color='lightgrey')\n",
539+
"axes[0][1].set_title(\"width_deviations\")\n",
540+
"edges.plot(ax=axes[1][0], column=\"profile\", legend=True, cmap=\"Spectral\")\n",
541+
"buildings.plot(ax=axes[1][0], color=\"lightgrey\")\n",
542+
"edges.plot(ax=axes[1][1], column=\"openness\", legend=True, cmap=\"Greens\")\n",
543+
"buildings.plot(ax=axes[1][1], color=\"lightgrey\")\n",
525544
"axes[1][0].set_axis_off()\n",
526-
"axes[1][0].set_title('profile')\n",
545+
"axes[1][0].set_title(\"profile\")\n",
527546
"axes[1][1].set_axis_off()\n",
528-
"axes[1][1].set_title('openness')\n",
529-
"edges.plot(ax=axes[2][0], column='heights', legend=True, cmap='Reds')\n",
530-
"buildings.plot(ax=axes[2][0], color='lightgrey')\n",
531-
"edges.plot(ax=axes[2][1], column='heights_deviations', legend=True)\n",
532-
"buildings.plot(ax=axes[2][1], color='lightgrey')\n",
547+
"axes[1][1].set_title(\"openness\")\n",
548+
"edges.plot(ax=axes[2][0], column=\"heights\", legend=True, cmap=\"Reds\")\n",
549+
"buildings.plot(ax=axes[2][0], color=\"lightgrey\")\n",
550+
"edges.plot(ax=axes[2][1], column=\"heights_deviations\", legend=True)\n",
551+
"buildings.plot(ax=axes[2][1], color=\"lightgrey\")\n",
533552
"axes[2][0].set_axis_off()\n",
534-
"axes[2][0].set_title('heights')\n",
553+
"axes[2][0].set_title(\"heights\")\n",
535554
"axes[2][1].set_axis_off()\n",
536-
"axes[2][1].set_title('heights_deviations')\n",
555+
"axes[2][1].set_title(\"heights_deviations\")\n",
537556
"plt.show()"
538557
]
539558
}

0 commit comments

Comments
 (0)