Skip to content

Commit e09b854

Browse files
committed
Updated new linting issues
1 parent 7770bac commit e09b854

File tree

12 files changed

+49
-51
lines changed

12 files changed

+49
-51
lines changed

city2graph/graph.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ def _process_hetero_edges(
574574

575575
for edge_type, edge_gdf in edges_dict.items():
576576
# Extract source, relation, and destination types from edge_type tuple
577-
src_type, rel_type, dst_type = edge_type
577+
src_type, _, dst_type = edge_type
578578

579579
# Get the mapping dictionaries (not the full metadata)
580580
# The type system guarantees these are dictionaries based on _process_hetero_nodes
@@ -601,8 +601,6 @@ def _process_hetero_edges(
601601
)
602602
data[edge_type].edge_index = edge_index
603603

604-
data[edge_type].edge_index = edge_index
605-
606604
feature_cols = edge_feature_cols.get(edge_type) if edge_feature_cols else None
607605
data[edge_type].edge_attr = self._create_features(edge_gdf, feature_cols)
608606
else:
@@ -858,7 +856,7 @@ def _reconstruct_node_gdf(
858856
else:
859857
# Handle missing geometry
860858
length = len(next(iter(gdf_data.values()))) if gdf_data else 0
861-
empty_geom = gpd.GeoSeries([None] * length, crs=metadata.crs if metadata.crs else None)
859+
empty_geom = gpd.GeoSeries([None] * length, crs=metadata.crs or None)
862860
gdf = gpd.GeoDataFrame(gdf_data, geometry=empty_geom, index=index_values)
863861

864862
# Set index names and CRS
@@ -937,7 +935,7 @@ def _reconstruct_edge_gdf(
937935
else:
938936
# Handle missing geometry
939937
length = len(next(iter(gdf_data.values()))) if gdf_data else 0
940-
empty_geom = gpd.GeoSeries([None] * length, crs=metadata.crs if metadata.crs else None)
938+
empty_geom = gpd.GeoSeries([None] * length, crs=metadata.crs or None)
941939
gdf = gpd.GeoDataFrame(gdf_data, geometry=empty_geom, index=index_values)
942940

943941
# Set index names and CRS

city2graph/metapath.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ def add_metapaths_by_weight( # noqa: PLR0913
259259

260260
# Prepare data for sparse matrix construction
261261
(
262-
node_to_idx,
262+
_node_to_idx,
263263
idx_to_node,
264264
endpoint_indices,
265265
row_indices,
@@ -983,7 +983,7 @@ def _empty_metapath_frame(
983983
pandas.DataFrame
984984
Empty DataFrame with the requested columns and index structure.
985985
"""
986-
columns = ["weight"] + (edge_attrs if edge_attrs else [])
986+
columns = ["weight"] + (edge_attrs or [])
987987
frame = pd.DataFrame(columns=columns)
988988
frame.index = pd.MultiIndex.from_tuples([], names=[start_index_name, end_index_name])
989989
return frame

city2graph/morphology.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,7 @@ def _validate_input_gdfs(buildings_gdf: gpd.GeoDataFrame, segments_gdf: gpd.GeoD
806806
if not segments_gdf.empty:
807807
# Assuming LineString is required for operations like dual_graph
808808
segment_geom_types = segments_gdf.geometry.geom_type.unique()
809-
if not all(geom_type in {"LineString"} for geom_type in segment_geom_types):
809+
if not all(geom_type == "LineString" for geom_type in segment_geom_types):
810810
msg = (
811811
f"segments_gdf must contain only LineString geometries. "
812812
f"Found: {', '.join(segment_geom_types)}"

city2graph/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1785,7 +1785,7 @@ def dual_graph(
17851785
>>> dual_nodes, dual_edges = dual_graph((nodes, edges))
17861786
"""
17871787
# Validate input type and extract GeoDataFrames
1788-
nodes_gdf, edges_gdf = _validate_dual_graph_input(graph)
1788+
_nodes_gdf, edges_gdf = _validate_dual_graph_input(graph)
17891789

17901790
# Ensure edges have a CRS
17911791
if edges_gdf.crs is None:

tests/test_data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ def test_invalid_release(self, test_bbox: list[float]) -> None:
180180
),
181181
pytest.raises(
182182
ValueError,
183-
match="Invalid release: 2099-99-99.0. Valid releases are: 2025-08-20.0, 2025-08-20.1, 2025-09-24.0",
183+
match=r"Invalid release: 2099-99-99.0. Valid releases are: 2025-08-20.0, 2025-08-20.1, 2025-09-24.0",
184184
),
185185
):
186186
load_overture_data(test_bbox, types=["building"], release=invalid_release)

tests/test_graph.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -656,13 +656,13 @@ def test_tensor_validation_errors(self, sample_nodes_gdf: gpd.GeoDataFrame) -> N
656656
# Position tensor mismatch
657657
data = gdf_to_pyg(sample_nodes_gdf)
658658
data.pos = torch.randn(1, 2) # Wrong size
659-
with pytest.raises(ValueError, match="position tensor size.*doesn't match"):
659+
with pytest.raises(ValueError, match=r"position tensor size.*doesn't match"):
660660
validate_pyg(data)
661661

662662
# Label tensor mismatch
663663
data = gdf_to_pyg(sample_nodes_gdf, node_label_cols=["label1"])
664664
data.y = torch.randn(1, 1) # Wrong size
665-
with pytest.raises(ValueError, match="label tensor size.*doesn't match"):
665+
with pytest.raises(ValueError, match=r"label tensor size.*doesn't match"):
666666
validate_pyg(data)
667667

668668
def test_hetero_label_tensor_mismatch(
@@ -681,7 +681,7 @@ def test_hetero_label_tensor_mismatch(
681681

682682
with pytest.raises(
683683
ValueError,
684-
match="Node type 'building': label tensor size.*doesn't match",
684+
match=r"Node type 'building': label tensor size.*doesn't match",
685685
):
686686
validate_pyg(data)
687687

@@ -722,15 +722,15 @@ def test_homo_edge_validation_cases(
722722
data.edge_attr = torch.randn(2, 1) # Wrong size
723723
with pytest.raises(
724724
ValueError,
725-
match="Edge attribute tensor size.*doesn't match number of edges",
725+
match=r"Edge attribute tensor size.*doesn't match number of edges",
726726
):
727727
validate_pyg(data)
728728

729729
def test_heterogeneous_tensor_validation(self, sample_pyg_hetero_data: HeteroData) -> None:
730730
"""Test tensor validation for heterogeneous graphs."""
731731
node_type = next(iter(sample_pyg_hetero_data.node_types))
732732
sample_pyg_hetero_data[node_type].pos = torch.randn(1, 2) # Wrong size
733-
with pytest.raises(ValueError, match="position tensor size.*doesn't match"):
733+
with pytest.raises(ValueError, match=r"position tensor size.*doesn't match"):
734734
validate_pyg(sample_pyg_hetero_data)
735735

736736
def test_homogeneous_validation_errors(self, sample_nodes_gdf: gpd.GeoDataFrame) -> None:

tests/test_metapath.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ def test_add_metapaths_edge_direction_and_lookup(
359359
assert ("road", "metapath_0", "road") in edges_rev
360360
else:
361361
bad_mp = [("x", "y", "z"), ("z", "y", "x")]
362-
with pytest.raises(KeyError, match="Edge type .* not found"):
362+
with pytest.raises(KeyError, match=r"Edge type .* not found"):
363363
add_metapaths(
364364
(sample_hetero_nodes_dict, sample_hetero_edges_dict),
365365
sequence=bad_mp,

tests/test_mobility.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def test_edgelist_multi_weight_threshold_col(self, od_zones_gdf: gpd.GeoDataFram
5757
"w2": [10, 0, 2],
5858
}
5959
)
60-
nodes, edges = od_matrix_to_graph(
60+
_nodes, edges = od_matrix_to_graph(
6161
E,
6262
od_zones_gdf,
6363
zone_id_col="zone_id",
@@ -112,7 +112,7 @@ def test_undirected_sums_reciprocals_edgelist(self, od_zones_gdf: gpd.GeoDataFra
112112
"flow": [3, 2, 1, 4],
113113
}
114114
)
115-
nodes, edges = od_matrix_to_graph(
115+
_nodes, edges = od_matrix_to_graph(
116116
E,
117117
od_zones_gdf,
118118
zone_id_col="zone_id",
@@ -137,7 +137,7 @@ def test_undirected_threshold_after_sum(self, od_zones_gdf: gpd.GeoDataFrame) ->
137137
"flow": [1, 1, 1],
138138
}
139139
)
140-
nodes, edges = od_matrix_to_graph(
140+
_nodes, edges = od_matrix_to_graph(
141141
E,
142142
od_zones_gdf,
143143
zone_id_col="zone_id",
@@ -269,7 +269,7 @@ def test_include_self_loops_adjacency_and_nan_negative(
269269
index=od_zones_gdf["zone_id"],
270270
columns=od_zones_gdf["zone_id"],
271271
)
272-
nodes, edges = od_matrix_to_graph(
272+
_nodes, edges = od_matrix_to_graph(
273273
A,
274274
od_zones_gdf,
275275
zone_id_col="zone_id",
@@ -287,7 +287,7 @@ def test_align_edgelist_drops_unknown_and_no_overlap_raises(
287287
"""Unknown IDs are dropped; if nothing remains, ValueError is raised."""
288288
# One valid, one invalid edge -> should drop invalid
289289
E = pd.DataFrame({"source": ["A", "X"], "target": ["B", "A"], "flow": [1, 3]})
290-
nodes, edges = od_matrix_to_graph(
290+
_nodes, edges = od_matrix_to_graph(
291291
E,
292292
od_zones_gdf,
293293
zone_id_col="zone_id",
@@ -316,7 +316,7 @@ def test_empty_after_threshold_yields_empty_edgeframe_schema(
316316
) -> None:
317317
"""High threshold removes all edges but preserves schema columns."""
318318
E = pd.DataFrame({"source": ["A"], "target": ["B"], "w1": [1], "w2": [5]})
319-
nodes, edges = od_matrix_to_graph(
319+
_nodes, edges = od_matrix_to_graph(
320320
E,
321321
od_zones_gdf,
322322
zone_id_col="zone_id",
@@ -332,7 +332,7 @@ def test_empty_after_threshold_yields_empty_edgeframe_schema(
332332
def test_undirected_with_self_loop_preserved(self, od_zones_gdf: gpd.GeoDataFrame) -> None:
333333
"""In undirected mode, self-loops are preserved as-is after symmetrization."""
334334
E = pd.DataFrame({"source": ["A", "A"], "target": ["A", "B"], "flow": [2, 3]})
335-
nodes, edges = od_matrix_to_graph(
335+
_nodes, edges = od_matrix_to_graph(
336336
E,
337337
od_zones_gdf,
338338
zone_id_col="zone_id",
@@ -495,7 +495,7 @@ def test_missing_centroid_edges_dropped_in_geometry_creation(
495495
zones = od_zones_gdf.copy()
496496
zones.loc[1, "geometry"] = None # make B missing
497497
E = pd.DataFrame({"source": ["A", "B"], "target": ["B", "A"], "flow": [1, 2]})
498-
nodes, edges = od_matrix_to_graph(
498+
_nodes, edges = od_matrix_to_graph(
499499
E,
500500
zones,
501501
zone_id_col="zone_id",
@@ -515,7 +515,7 @@ def test_adjacency_all_zero_results_in_empty_edges(
515515
A = pd.DataFrame(
516516
np.zeros((3, 3)), index=od_zones_gdf["zone_id"], columns=od_zones_gdf["zone_id"]
517517
)
518-
nodes, edges = od_matrix_to_graph(
518+
_nodes, edges = od_matrix_to_graph(
519519
A, od_zones_gdf, zone_id_col="zone_id", matrix_type="adjacency"
520520
)
521521
assert edges.empty
@@ -585,7 +585,7 @@ def test_weight_column_nan_and_negative_handling(self, od_zones_gdf: gpd.GeoData
585585
"flow": [np.nan, -1, 0.5, 0],
586586
}
587587
)
588-
nodes, edges = od_matrix_to_graph(
588+
_nodes, edges = od_matrix_to_graph(
589589
E, od_zones_gdf, zone_id_col="zone_id", matrix_type="edgelist", weight_cols=["flow"]
590590
)
591591
# NaN->0 then drop zeros; negative retained but threshold None drops values <=0
@@ -596,7 +596,7 @@ def test_weight_column_nan_and_negative_handling(self, od_zones_gdf: gpd.GeoData
596596
def test_self_loop_removed_when_not_included(self, od_zones_gdf: gpd.GeoDataFrame) -> None:
597597
"""Self-loop is removed by default include_self_loops=False."""
598598
E = pd.DataFrame({"source": ["A", "A"], "target": ["A", "B"], "flow": [5, 1]})
599-
nodes, edges = od_matrix_to_graph(
599+
_nodes, edges = od_matrix_to_graph(
600600
E,
601601
od_zones_gdf,
602602
zone_id_col="zone_id",
@@ -616,7 +616,7 @@ def test_align_adjacency_partial_overlap_warns_and_reindexes(
616616
index=["A", "B", "X"],
617617
columns=["A", "B", "X"],
618618
)
619-
nodes, edges = od_matrix_to_graph(
619+
_nodes, edges = od_matrix_to_graph(
620620
A, od_zones_gdf, zone_id_col="zone_id", matrix_type="adjacency"
621621
)
622622
# Only edges among A,B retained
@@ -630,7 +630,7 @@ def test_missing_crs_emits_warning(self, od_zones_gdf: gpd.GeoDataFrame) -> None
630630
# Remove CRS in a version-robust way (GeoPandas requires allow_override when overriding)
631631
zones = zones.set_crs(None, allow_override=True)
632632
E = pd.DataFrame({"source": ["A"], "target": ["B"], "flow": [1]})
633-
nodes, edges = od_matrix_to_graph(
633+
nodes, _edges = od_matrix_to_graph(
634634
E,
635635
zones,
636636
zone_id_col="zone_id",
@@ -682,7 +682,7 @@ def test_undirected_multi_weight_sums_all_columns(self, od_zones_gdf: gpd.GeoDat
682682
"w2": [10, 20, 30, 40],
683683
}
684684
)
685-
nodes, edges = od_matrix_to_graph(
685+
_nodes, edges = od_matrix_to_graph(
686686
E,
687687
od_zones_gdf,
688688
zone_id_col="zone_id",

tests/test_morphology.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ def test_negative_parameters(
247247
Point(0, 0)
248248

249249
# Test negative clipping buffer (this should raise ValueError)
250-
with pytest.raises(ValueError, match="clipping_buffer cannot be negative."):
250+
with pytest.raises(ValueError, match=r"clipping_buffer cannot be negative."):
251251
morphological_graph(
252252
sample_buildings_gdf,
253253
sample_segments_gdf,
@@ -433,7 +433,7 @@ def test_public_to_public_networkx(self, sample_segments_gdf: gpd.GeoDataFrame)
433433

434434
def test_public_to_public_edge_structure(self, sample_segments_gdf: gpd.GeoDataFrame) -> None:
435435
"""Test public-to-public edge structure."""
436-
nodes, edges = public_to_public_graph(sample_segments_gdf)
436+
_nodes, edges = public_to_public_graph(sample_segments_gdf)
437437
self.validate_edge_columns(edges, ["from_public_id", "to_public_id"])
438438

439439
def test_public_to_public_multiindex_handling(self, sample_crs: str) -> None:

tests/test_proximity.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ def test_group_nodes_predicate_alias_within() -> None:
310310
"""Predicate 'within' excludes boundary point so only interior point remains."""
311311
polys, pts = make_poly_points_pair()
312312
# Shift third point to be strictly outside
313-
nodes, edges = group_nodes(polys, pts, predicate="within")
313+
_nodes, edges = group_nodes(polys, pts, predicate="within")
314314
edge_key = next(iter(edges))
315315
# Points 1 only strictly within (point 2 is on boundary so excluded for within)
316316
e = edges[edge_key]
@@ -361,7 +361,7 @@ class TestContiguityPublicAPI:
361361
def test_small_grid(self) -> None:
362362
"""Smoke test small grid contiguity output symmetry."""
363363
gdf = make_square_polygons()
364-
nodes, edges = contiguity_graph(gdf)
364+
nodes, _edges = contiguity_graph(gdf)
365365
assert set(nodes.index) == set(gdf.index)
366366
# Edges GeoDataFrame stores undirected edges once (u,v where u<v maybe);
367367
# validate symmetry by converting to networkx graph and checking neighbors.
@@ -422,7 +422,7 @@ def test_delaunay_network_metric(
422422
network_edges: gpd.GeoDataFrame, small_points: gpd.GeoDataFrame
423423
) -> None:
424424
"""Delaunay with network metric attaches network-based weights/geometries."""
425-
nodes, edges = delaunay_graph(
425+
_nodes, edges = delaunay_graph(
426426
small_points, distance_metric="network", network_gdf=network_edges
427427
)
428428
if len(small_points) >= 3:
@@ -451,7 +451,7 @@ def test_mst_network_metric(
451451
network_edges: gpd.GeoDataFrame, small_points: gpd.GeoDataFrame
452452
) -> None:
453453
"""Minimum spanning tree under network metric (complete graph fallback)."""
454-
nodes, edges = euclidean_minimum_spanning_tree(
454+
_nodes, edges = euclidean_minimum_spanning_tree(
455455
small_points, distance_metric="network", network_gdf=network_edges
456456
)
457457
# Tree edges <= n-1
@@ -470,7 +470,7 @@ def test_fixed_radius_network_metric(
470470

471471
def test_waxman_basic(small_points: gpd.GeoDataFrame) -> None:
472472
"""Waxman graph probabilistic construction (schema validation)."""
473-
nodes, edges = waxman_graph(small_points, beta=0.5, r0=3.0, seed=123)
473+
_nodes, edges = waxman_graph(small_points, beta=0.5, r0=3.0, seed=123)
474474
assert set(edges.columns) >= {"weight", "geometry"}
475475

476476

@@ -571,7 +571,7 @@ def test_group_nodes_network_metric_success() -> None:
571571
lines.append(LineString([poly_centroid, p]))
572572
mi = pd.MultiIndex.from_arrays([src, dst], names=("source_id", "target_id"))
573573
net = gpd.GeoDataFrame({"geometry": lines}, index=mi, crs=polys.crs)
574-
nodes, edges = group_nodes(polys, pts, distance_metric="network", network_gdf=net)
574+
_nodes, edges = group_nodes(polys, pts, distance_metric="network", network_gdf=net)
575575
edge_key = next(iter(edges))
576576
e = edges[edge_key]
577577
assert len(e) == 2 # two contained points
@@ -593,7 +593,7 @@ def test_group_nodes_network_with_length_weight() -> None:
593593
lengths.append(seg.length)
594594
mi = pd.MultiIndex.from_arrays([src, dst], names=("source_id", "target_id"))
595595
net = gpd.GeoDataFrame({"length": lengths, "geometry": lines}, index=mi, crs=polys.crs)
596-
nodes, edges = group_nodes(polys, pts, distance_metric="network", network_gdf=net)
596+
_nodes, edges = group_nodes(polys, pts, distance_metric="network", network_gdf=net)
597597
edge_key = next(iter(edges))
598598
e = edges[edge_key]
599599
assert len(e) == 2
@@ -613,7 +613,7 @@ def test_group_nodes_no_matches_nonempty() -> None:
613613
geometry=[Point(0, 0), Point(1, 1)],
614614
crs="EPSG:3857",
615615
).set_index("pid")
616-
nodes, edges = group_nodes(polys, pts)
616+
_nodes, edges = group_nodes(polys, pts)
617617
edge_key = next(iter(edges))
618618
assert edges[edge_key].empty
619619

@@ -650,7 +650,7 @@ def test_contiguity_network_metric_success() -> None:
650650
index=pd.MultiIndex.from_arrays([[0], [1]], names=("source_id", "target_id")),
651651
crs=gdf.crs,
652652
)
653-
nodes, edges = contiguity_graph(gdf, distance_metric="network", network_gdf=net)
653+
_nodes, edges = contiguity_graph(gdf, distance_metric="network", network_gdf=net)
654654
assert len(edges) == 1
655655

656656

@@ -681,7 +681,7 @@ def test_contiguity_network_length_weight_branch() -> None:
681681
index=pd.MultiIndex.from_arrays([[0], [1]], names=("source_id", "target_id")),
682682
crs=gdf.crs,
683683
)
684-
nodes, edges = contiguity_graph(gdf, distance_metric="network", network_gdf=net)
684+
_nodes, edges = contiguity_graph(gdf, distance_metric="network", network_gdf=net)
685685
assert len(edges) == 1
686686
# Ensure geometry and weight present (path weight via 'length')
687687
assert set(edges.columns) >= {"weight", "geometry"}

0 commit comments

Comments
 (0)