Skip to content

Commit a01ec77

Browse files
authored
Reup ruff linting & formatting [2025-07] (#795)
1 parent 8c4a244 commit a01ec77

40 files changed

+101
-123
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
files: "libpysal\/|docs\/"
22
repos:
33
- repo: https://github.com/astral-sh/ruff-pre-commit
4-
rev: "v0.6.9"
4+
rev: "v0.12.2"
55
hooks:
6-
- id: ruff
6+
- id: ruff-check
77
- id: ruff-format
88

99
ci:

docs/user-guide/graph/matching-graph.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@
111111
"f, ax = plt.subplots(1, 3)\n",
112112
"for i, g in enumerate((g1, g2, g3)):\n",
113113
" g.plot(gdf, ax=ax[i])\n",
114-
" ax[i].set_title(f\"k = {i+1}\")"
114+
" ax[i].set_title(f\"k = {i + 1}\")"
115115
]
116116
},
117117
{

docs/user-guide/weights/voronoi.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@
316316
"points_df.plot(ax=ax, color=\"red\")\n",
317317
"plt.xlim(minx, maxx)\n",
318318
"plt.ylim(miny, maxy)\n",
319-
"plt.title(\"buffer: %f, n: %d\" % (r, n_points))\n",
319+
"plt.title(f\"buffer: {r}, n: {n_points}\")\n",
320320
"plt.show()"
321321
]
322322
},
@@ -467,7 +467,7 @@
467467
"name": "python",
468468
"nbconvert_exporter": "python",
469469
"pygments_lexer": "ipython3",
470-
"version": "3.12.2"
470+
"version": "3.13.5"
471471
}
472472
},
473473
"nbformat": 4,

libpysal/cg/alpha_shapes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ def alpha_shape_auto(
557557
geoms_prev = _alpha_geoms((1 / radii.max()) - EPS, triangles, radii, xys)
558558
points = shapely.points(xys)
559559
if verbose:
560-
print("Step set to %i" % step)
560+
print(f"Step set to {step}")
561561
for i in range(0, len(radii), step):
562562
radi = radii[i]
563563
alpha = (1 / radi) - EPS

libpysal/cg/rtree.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1197,7 +1197,7 @@ def k_means_cluster(root, k, nodes):
11971197
for c in clusters:
11981198
if len(c) == 0:
11991199
print("Error....")
1200-
print("Nodes: %d, centers: %s." % (len(ns), repr(cluster_centers)))
1200+
print(f"Nodes: {len(ns)}, centers: {repr(cluster_centers)}.")
12011201

12021202
assert len(c) > 0
12031203

libpysal/cg/segmentLocator.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -367,11 +367,11 @@ def brute_check(segments, qpoints): # noqa: ARG001
367367
t0 = time.time()
368368
g2 = BruteSegmentLocator(segs)
369369
t1 = time.time()
370-
print("Created Brute in %0.4f seconds" % (t1 - t0))
370+
print(f"Created Brute in {t1 - t0:0.4f} seconds")
371371
t2 = time.time()
372372
q = list(map(g2.nearest, qpoints))
373373
t3 = time.time()
374-
print("Brute Found %d matches in %0.4f seconds" % (len(qpoints), t3 - t2))
374+
print(f"Brute Found {len(qpoints)} matches in {t3 - t2:0.4f} seconds")
375375
print("Total Brute Time:", t3 - t0)
376376
print()
377377
return q
@@ -383,8 +383,8 @@ def grid_check(bins, segments, qpoints, visualize=False):
383383
t1 = time.time()
384384
g.grid.kd # noqa: B018
385385
t2 = time.time()
386-
print("Created Grid in %0.4f seconds" % (t1 - t0))
387-
print("Created KDTree in %0.4f seconds" % (t2 - t1))
386+
print(f"Created Grid in {t1 - t0:0.4f} seconds")
387+
print(f"Created KDTree in {t2 - t1:0.4f} seconds")
388388
if visualize:
389389
pylab.matshow(
390390
g.grid.mask, origin="lower", extent=g.grid.x_range + g.grid.y_range
@@ -393,7 +393,7 @@ def grid_check(bins, segments, qpoints, visualize=False):
393393
t2 = time.time()
394394
list(map(g.nearest, qpoints))
395395
t3 = time.time()
396-
print("Grid Found %d matches in %0.4f seconds" % (len(qpoints), t3 - t2))
396+
print(f"Grid Found {len(qpoints)} matches in {t3 - t2:0.4f} seconds")
397397
print("Total Grid Time:", t3 - t0)
398398
qps = len(qpoints) / (t3 - t2)
399399
print("q/s:", qps)

libpysal/examples/remotes.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
},
2121
"Atlanta": {
2222
"download_url": (
23-
"https://geodacenter.github.io/data-and-lab/" "/data/atlanta_hom.zip"
23+
"https://geodacenter.github.io/data-and-lab//data/atlanta_hom.zip"
2424
),
2525
"explain_url": "https://geodacenter.github.io/data-and-lab//atlanta_old/",
2626
"n": "90",
@@ -197,8 +197,7 @@
197197
"https://geodacenter.github.io/data-and-lab//data/income_diversity.zip"
198198
),
199199
"explain_url": (
200-
"https://geodacenter.github.io/data-and-lab/"
201-
"/co_income_diversity_variables/"
200+
"https://geodacenter.github.io/data-and-lab//co_income_diversity_variables/"
202201
),
203202
"n": " 3,984",
204203
"k": " 64",
@@ -507,15 +506,13 @@
507506
},
508507
"SanFran Crime": {
509508
"download_url": (
510-
"https://geodacenter.github.io/data-and-lab/"
511-
"/data/SFCrime_July_Dec2012.zip"
509+
"https://geodacenter.github.io/data-and-lab//data/SFCrime_July_Dec2012.zip"
512510
),
513511
"explain_url": "https://geodacenter.github.io/data-and-lab//SFcrimes_vars/",
514512
"n": " 3,384",
515513
"k": " 13",
516514
"description": (
517-
" July-Dec 2012 crime incidents in San Francisco "
518-
"(points + area) - for CAST"
515+
" July-Dec 2012 crime incidents in San Francisco (points + area) - for CAST"
519516
),
520517
},
521518
"Savannah1": {

libpysal/graph/_kernel.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,9 @@ def _kernel(
140140
coordinates, ids=ids, valid_geometry_types=_VALID_GEOMETRY_TYPES
141141
)
142142
else:
143-
assert (
144-
coordinates.shape[0] == coordinates.shape[1]
145-
), "coordinates should represent a distance matrix if metric='precomputed'"
143+
assert coordinates.shape[0] == coordinates.shape[1], (
144+
"coordinates should represent a distance matrix if metric='precomputed'"
145+
)
146146
if ids is None:
147147
ids = numpy.arange(coordinates.shape[0])
148148

libpysal/graph/_summary.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -227,40 +227,40 @@ def __init__(self, graph, asymmetries=False):
227227
def __repr__(self):
228228
n_asymmetries = f"{self.n_asymmetries:>12.0f}" if self.asymmetries else "NA"
229229
return f"""Graph Summary Statistics
230-
{'='*24}
230+
{"=" * 24}
231231
Graph indexed by:
232232
{self._graph._get_ids_repr(57)}
233-
{'='*62}
233+
{"=" * 62}
234234
{"Number of nodes:":<50}{self.n_nodes:>12.0f}
235235
{"Number of edges:":<50}{self.n_edges:>12.0f}
236236
{"Number of connected components:":<50}{self.n_components:>12.0f}
237237
{"Number of isolates:":<50}{self.n_isolates:12.0f}
238238
{"Number of non-zero edges:":<50}{self.nonzero:>12.0f}
239239
{"Percentage of non-zero edges:":<50}{self.pct_nonzero:>11.2f}%
240240
{"Number of asymmetries:":<50}{n_asymmetries}
241-
{'-'*62}
241+
{"-" * 62}
242242
Cardinalities
243-
{'='*62}
243+
{"=" * 62}
244244
{"Mean:":<20}{self.cardinalities_mean:>9.0f} {"25%:":<20}{self.cardinalities_25:>9.0f}
245245
{"Standard deviation:":<20}{self.cardinalities_std:>9.0f} {"50%:":<20}{self.cardinalities_50:>9.0f}
246246
{"Min:":<20}{self.cardinalities_min:>9.0f} {"75%:":<20}{self.cardinalities_75:>9.0f}
247247
{"Max:":<20}{self.cardinalities_max:>9.0f}
248-
{'-'*62}
248+
{"-" * 62}
249249
Weights
250-
{'='*62}
250+
{"=" * 62}
251251
{"Mean:":<20}{self.weights_mean:>9.0f} {"25%:":<20}{self.weights_25:>9.0f}
252252
{"Standard deviation:":<20}{self.weights_std:>9.0f} {"50%:":<20}{self.weights_50:>9.0f}
253253
{"Min:":<20}{self.weights_min:>9.0f} {"75%:":<20}{self.weights_75:>9.0f}
254254
{"Max:":<20}{self.weights_max:>9.0f}
255-
{'-'*62}
255+
{"-" * 62}
256256
Sum of weights
257-
{'='*62}
257+
{"=" * 62}
258258
{"S0:":<50}{self.s0:>12.0f}
259259
{"S1:":<50}{self.s1:>12.0f}
260260
{"S2:":<50}{self.s2:>12.0f}
261-
{'-'*62}
261+
{"-" * 62}
262262
Traces
263-
{'='*62}
263+
{"=" * 62}
264264
{"GG:":<50}{self.trace_g2:>12.0f}
265265
{"G'G:":<50}{self.trace_gtg:>12.0f}
266266
{"G'G + GG:":<50}{self.trace_gtg_gg:>12.0f}

libpysal/graph/tests/test_base.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,7 @@ def test_init(self):
139139

140140
def test___repr__(self):
141141
expected = (
142-
"<Graph of 10 nodes and 25 nonzero edges indexed by\n"
143-
" [0, 1, 2, 3, 4, ...]>"
142+
"<Graph of 10 nodes and 25 nonzero edges indexed by\n [0, 1, 2, 3, 4, ...]>"
144143
)
145144
assert repr(self.g_int) == expected
146145

@@ -371,9 +370,9 @@ def test_from_sparse(self):
371370
],
372371
np.ones(10),
373372
)
374-
assert (
375-
g == expected
376-
), "sparse csr nybb with ids does not match arrays constructor"
373+
assert g == expected, (
374+
"sparse csr nybb with ids does not match arrays constructor"
375+
)
377376
np.testing.assert_array_equal(g.sparse.todense(), sp.todense())
378377

379378
with pytest.raises(ValueError, match="The length of ids "):

0 commit comments

Comments
 (0)