@@ -81,7 +81,9 @@ def __init__(
81
81
node_attrs : Optional [dict [str , AttributeType ]] = None ,
82
82
edge_attrs : Optional [dict [str , AttributeType ]] = None ,
83
83
):
84
- assert mode in self .valid_modes , f"Mode '{ mode } ' not in allowed modes { self .valid_modes } "
84
+ assert (
85
+ mode in self .valid_modes
86
+ ), f"Mode '{ mode } ' not in allowed modes { self .valid_modes } "
85
87
self .mode = mode
86
88
87
89
if mode in self .read_modes :
@@ -135,8 +137,8 @@ def get(value, default):
135
137
136
138
self .directed = get (directed , False )
137
139
self .total_roi = get (
138
- total_roi ,
139
- Roi (( None ,) * self . ndims , ( None ,) * self . ndims ) )
140
+ total_roi , Roi (( None ,) * self . ndims , ( None ,) * self . ndims )
141
+ )
140
142
self .nodes_table_name = get (nodes_table , "nodes" )
141
143
self .edges_table_name = get (edges_table , "edges" )
142
144
self .endpoint_names = get (endpoint_names , ["u" , "v" ])
@@ -229,7 +231,7 @@ def read_graph(
229
231
edges = self .read_edges (
230
232
roi , nodes = nodes , read_attrs = edge_attrs , attr_filter = edges_filter
231
233
)
232
- u , v = self .endpoint_names
234
+ u , v = self .endpoint_names # type: ignore
233
235
try :
234
236
edge_list = [(e [u ], e [v ], self .__remove_keys (e , [u , v ])) for e in edges ]
235
237
except KeyError as e :
@@ -336,11 +338,7 @@ def read_nodes(
336
338
337
339
nodes = [
338
340
self ._columns_to_node_attrs (
339
- {
340
- key : val
341
- for key , val in zip (read_columns , values )
342
- },
343
- read_attrs
341
+ {key : val for key , val in zip (read_columns , values )}, read_attrs
344
342
)
345
343
for values in self ._select_query (select_statement )
346
344
]
@@ -375,11 +373,11 @@ def read_edges(
375
373
return []
376
374
377
375
node_ids = ", " .join ([str (node ["id" ]) for node in nodes ])
378
- node_condition = f"{ self .endpoint_names [0 ]} IN ({ node_ids } )"
376
+ node_condition = f"{ self .endpoint_names [0 ]} IN ({ node_ids } )" # type: ignore
379
377
380
378
logger .debug ("Reading nodes in roi %s" % roi )
381
379
# TODO: AND vs OR here
382
- desired_columns = ", " .join (self .endpoint_names + list (self .edge_attrs .keys ()))
380
+ desired_columns = ", " .join (self .endpoint_names + list (self .edge_attrs .keys ())) # type: ignore
383
381
select_statement = (
384
382
f"SELECT { desired_columns } FROM { self .edges_table_name } WHERE "
385
383
+ node_condition
@@ -390,7 +388,7 @@ def read_edges(
390
388
)
391
389
)
392
390
393
- edge_attrs = self .endpoint_names + (
391
+ edge_attrs = self .endpoint_names + ( # type: ignore
394
392
list (self .edge_attrs .keys ()) if read_attrs is None else read_attrs
395
393
)
396
394
attr_filter = attr_filter if attr_filter is not None else {}
@@ -401,7 +399,7 @@ def read_edges(
401
399
{
402
400
key : val
403
401
for key , val in zip (
404
- self .endpoint_names + list (self .edge_attrs .keys ()), values
402
+ self .endpoint_names + list (self .edge_attrs .keys ()), values # type: ignore
405
403
)
406
404
if key in edge_attrs
407
405
}
@@ -486,8 +484,8 @@ def update_edges(
486
484
if not roi .contains (pos_u ):
487
485
logger .debug (
488
486
(
489
- f"Skipping edge with { self .endpoint_names [0 ]} {{}}, { self .endpoint_names [1 ]} {{}},"
490
- + f"and data {{}} because { self .endpoint_names [0 ]} not in roi {{}}"
487
+ f"Skipping edge with { self .endpoint_names [0 ]} {{}}, { self .endpoint_names [1 ]} {{}}," # type: ignore
488
+ + f"and data {{}} because { self .endpoint_names [0 ]} not in roi {{}}" # type: ignore
491
489
).format (u , v , data , roi )
492
490
)
493
491
continue
@@ -497,7 +495,7 @@ def update_edges(
497
495
update_statement = (
498
496
f"UPDATE { self .edges_table_name } SET "
499
497
f"{ ', ' .join (setters )} WHERE "
500
- f"{ self .endpoint_names [0 ]} ={ u } AND { self .endpoint_names [1 ]} ={ v } "
498
+ f"{ self .endpoint_names [0 ]} ={ u } AND { self .endpoint_names [1 ]} ={ v } " # type: ignore
501
499
)
502
500
503
501
self ._update_query (update_statement , commit = False )
@@ -528,10 +526,7 @@ def write_nodes(
528
526
pos = self .__get_node_pos (data )
529
527
if roi is not None and not roi .contains (pos ):
530
528
continue
531
- values .append (
532
- [node_id ]
533
- + [data .get (attr , None ) for attr in attrs ]
534
- )
529
+ values .append ([node_id ] + [data .get (attr , None ) for attr in attrs ])
535
530
536
531
if len (values ) == 0 :
537
532
logger .debug ("No nodes to insert in %s" , roi )
@@ -602,12 +597,13 @@ def __load_metadata(self, metadata):
602
597
603
598
# simple attributes
604
599
for attr_name in [
605
- "position_attribute" ,
606
- "directed" ,
607
- "nodes_table_name" ,
608
- "edges_table_name" ,
609
- "endpoint_names" ,
610
- "ndims" ]:
600
+ "position_attribute" ,
601
+ "directed" ,
602
+ "nodes_table_name" ,
603
+ "edges_table_name" ,
604
+ "endpoint_names" ,
605
+ "ndims" ,
606
+ ]:
611
607
612
608
if getattr (self , attr_name ) is None :
613
609
setattr (self , attr_name , metadata [attr_name ])
@@ -657,7 +653,7 @@ def __remove_keys(self, dictionary, keys):
657
653
658
654
def __get_node_pos (self , n : dict [str , Any ]) -> Optional [Coordinate ]:
659
655
try :
660
- return Coordinate (n [self .position_attribute ])
656
+ return Coordinate (n [self .position_attribute ]) # type: ignore
661
657
except KeyError :
662
658
return None
663
659
@@ -681,11 +677,13 @@ def __attr_query(self, attrs: dict[str, Any]) -> str:
681
677
def __roi_query (self , roi : Roi ) -> str :
682
678
query = "WHERE "
683
679
pos_attr = self .position_attribute
684
- for dim in range (self .ndims ):
680
+ for dim in range (self .ndims ): # type: ignore
685
681
if dim > 0 :
686
682
query += " AND "
687
683
if roi .begin [dim ] is not None and roi .end [dim ] is not None :
688
- query += f"{ pos_attr } [{ dim + 1 } ] BETWEEN { roi .begin [dim ]} and { roi .end [dim ]} "
684
+ query += (
685
+ f"{ pos_attr } [{ dim + 1 } ] BETWEEN { roi .begin [dim ]} and { roi .end [dim ]} "
686
+ )
689
687
elif roi .begin [dim ] is not None :
690
688
query += f"{ pos_attr } [{ dim + 1 } ]>={ roi .begin [dim ]} "
691
689
elif roi .begin [dim ] is not None :
0 commit comments