Skip to content

Commit facd4fd

Browse files
committed
chore: format code
1 parent deceb8d commit facd4fd

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

src/ssspx/io.py

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ def _iter_edges(G: Graph) -> Iterable[Tuple[int, int, float]]:
2121
G: The graph object containing adjacency information.
2222
2323
Yields:
24-
A tuple representing an edge in the graph, where the first element
25-
is the source node index (u), the second element is the destination
24+
A tuple representing an edge in the graph, where the first element
25+
is the source node index (u), the second element is the destination
2626
node index (v), and the third element is the edge weight (w).
2727
"""
2828
for u in range(G.n):
@@ -34,14 +34,14 @@ def _read_csv(path: Path) -> Tuple[int, EdgeList]:
3434
"""Read a CSV file containing edge data and return the number of nodes and edge list.
3535
3636
Each line in the file should contain at least three columns: source node,
37-
target node, and edge weight. Lines starting with '#' or empty lines are
37+
target node, and edge weight. Lines starting with '#' or empty lines are
3838
ignored. Columns can be separated by commas or tabs.
3939
4040
Args:
4141
path: The path to the CSV file.
4242
4343
Returns:
44-
A tuple containing the number of nodes (max node id + 1) and a list
44+
A tuple containing the number of nodes (max node id + 1) and a list
4545
of edges, where each edge is represented as a tuple (u, v, w).
4646
4747
Raises:
@@ -95,7 +95,7 @@ def _read_jsonl(path: Path) -> Tuple[int, EdgeList]:
9595
path: Path to the JSONL file.
9696
9797
Returns:
98-
A tuple containing the number of nodes (max node id + 1) and a list
98+
A tuple containing the number of nodes (max node id + 1) and a list
9999
of edges as (u, v, w) tuples.
100100
101101
Raises:
@@ -149,7 +149,7 @@ def _read_mtx(path: Path) -> Tuple[int, EdgeList]:
149149
Notes:
150150
Lines starting with '%' are treated as comments and skipped.
151151
Assumes the file contains at least three columns: source, target,
152-
and weight. Node indices in the file are assumed to be 1-based
152+
and weight. Node indices in the file are assumed to be 1-based
153153
and are converted to 0-based.
154154
"""
155155
edges: EdgeList = []
@@ -201,8 +201,8 @@ def _read_graphml(path: Path) -> Tuple[int, EdgeList]:
201201
path: Path to the GraphML file.
202202
203203
Returns:
204-
A tuple containing the number of nodes (as max node id + 1) and a
205-
list of edges, where each edge is represented as a tuple (u, v, w)
204+
A tuple containing the number of nodes (as max node id + 1) and a
205+
list of edges, where each edge is represented as a tuple (u, v, w)
206206
with integer node IDs and float weights.
207207
208208
Raises:
@@ -228,7 +228,11 @@ def _read_graphml(path: Path) -> Tuple[int, EdgeList]:
228228
w_attr = edge.attrib.get("weight")
229229
if w_attr is None:
230230
data = edge.find(f"{ns}data[@key='w']")
231-
w = float(data.text) if (data is not None and data.text is not None) else 1.0
231+
w = (
232+
float(data.text)
233+
if (data is not None and data.text is not None)
234+
else 1.0
235+
)
232236
else:
233237
w = float(w_attr)
234238
edges.append((u, v, w)) # Now u and v are definitely integers
@@ -243,13 +247,13 @@ def _write_graphml(path: Path, G: Graph) -> None:
243247
244248
Args:
245249
path: The file path where the GraphML output will be written.
246-
G: The graph object to serialize, expected to have an attribute `n`
250+
G: The graph object to serialize, expected to have an attribute `n`
247251
for the number of nodes.
248252
249253
Notes:
250-
The function assumes the graph is directed. Each node is assigned an
251-
ID in the format "n{i}". Edges are written with source, target, and
252-
weight attributes. The helper function `_iter_edges(G)` should yield
254+
The function assumes the graph is directed. Each node is assigned an
255+
ID in the format "n{i}". Edges are written with source, target, and
256+
weight attributes. The helper function `_iter_edges(G)` should yield
253257
tuples of (u, v, w) for each edge.
254258
"""
255259
lines: List[str] = []
@@ -287,7 +291,7 @@ def _detect_format(path: Path) -> Optional[str]:
287291
path: The path to the file whose format is to be detected.
288292
289293
Returns:
290-
The detected format as a string ("csv", "jsonl", "mtx", "graphml"),
294+
The detected format as a string ("csv", "jsonl", "mtx", "graphml"),
291295
or None if the format is not recognized.
292296
"""
293297
ext = path.suffix.lower()
@@ -329,7 +333,7 @@ def write_graph(G: Graph, path: str, fmt: Optional[str] = None) -> None:
329333
Args:
330334
G: The graph object to be written.
331335
path: The file path where the graph will be saved.
332-
fmt: The format to use for writing the graph. If None, the format is
336+
fmt: The format to use for writing the graph. If None, the format is
333337
auto-detected from the file extension.
334338
335339
Raises:

src/ssspx/transform.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def constant_outdegree_transform(
5050
remaining = edges
5151
while len(remaining) > delta:
5252
chunks.append(remaining[: delta - 1])
53-
remaining = remaining[delta - 1:]
53+
remaining = remaining[delta - 1 :]
5454
chunks.append(remaining) # last chunk size <= delta
5555
clones = [next_id + i for i in range(len(chunks))]
5656
mapping[u] = clones

0 commit comments

Comments
 (0)