Skip to content

Commit

Permalink
test: ✨ Fix mypy errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
rhoadesScholar committed Mar 27, 2024
1 parent 211a1a7 commit c2d205d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 18 deletions.
8 changes: 4 additions & 4 deletions funlib/persistence/graphs/pgsql_graph_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ def __init__(
nodes_table=nodes_table,
edges_table=edges_table,
endpoint_names=endpoint_names,
node_attrs=node_attrs,
edge_attrs=edge_attrs,
node_attrs=node_attrs, # type: ignore
edge_attrs=edge_attrs, # type: ignore
)

def _drop_tables(self) -> None:
Expand Down Expand Up @@ -101,12 +101,12 @@ def _create_tables(self) -> None:
f"{self.nodes_table_name}({self.position_attribute})"
)

columns = list(self.edge_attrs.keys())
columns = list(self.edge_attrs.keys()) # type: ignore
types = list([self.__sql_type(t) for t in self.edge_attrs.values()])
column_types = [f"{c} {t}" for c, t in zip(columns, types)]
self.__exec(
f"CREATE TABLE IF NOT EXISTS {self.edges_table_name}("
f"{self.endpoint_names[0]} BIGINT not null, "
f"{self.endpoint_names[0]} BIGINT not null, " # type: ignore
f"{self.endpoint_names[1]} BIGINT not null, "
f"{' '.join([c + ',' for c in column_types])}"
f"PRIMARY KEY ({self.endpoint_names[0]}, {self.endpoint_names[1]})"
Expand Down
20 changes: 10 additions & 10 deletions funlib/persistence/graphs/sql_graph_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def read_graph(
edges = self.read_edges(
roi, nodes=nodes, read_attrs=edge_attrs, attr_filter=edges_filter
)
u, v = self.endpoint_names
u, v = self.endpoint_names # type: ignore
try:
edge_list = [(e[u], e[v], self.__remove_keys(e, [u, v])) for e in edges]
except KeyError as e:
Expand Down Expand Up @@ -373,11 +373,11 @@ def read_edges(
return []

node_ids = ", ".join([str(node["id"]) for node in nodes])
node_condition = f"{self.endpoint_names[0]} IN ({node_ids})"
node_condition = f"{self.endpoint_names[0]} IN ({node_ids})" # type: ignore

logger.debug("Reading nodes in roi %s" % roi)
# TODO: AND vs OR here
desired_columns = ", ".join(self.endpoint_names + list(self.edge_attrs.keys()))
desired_columns = ", ".join(self.endpoint_names + list(self.edge_attrs.keys())) # type: ignore
select_statement = (
f"SELECT {desired_columns} FROM {self.edges_table_name} WHERE "
+ node_condition
Expand All @@ -388,7 +388,7 @@ def read_edges(
)
)

edge_attrs = self.endpoint_names + (
edge_attrs = self.endpoint_names + ( # type: ignore
list(self.edge_attrs.keys()) if read_attrs is None else read_attrs
)
attr_filter = attr_filter if attr_filter is not None else {}
Expand All @@ -399,7 +399,7 @@ def read_edges(
{
key: val
for key, val in zip(
self.endpoint_names + list(self.edge_attrs.keys()), values
self.endpoint_names + list(self.edge_attrs.keys()), values # type: ignore
)
if key in edge_attrs
}
Expand Down Expand Up @@ -484,8 +484,8 @@ def update_edges(
if not roi.contains(pos_u):
logger.debug(
(
f"Skipping edge with {self.endpoint_names[0]} {{}}, {self.endpoint_names[1]} {{}},"
+ f"and data {{}} because {self.endpoint_names[0]} not in roi {{}}"
f"Skipping edge with {self.endpoint_names[0]} {{}}, {self.endpoint_names[1]} {{}}," # type: ignore
+ f"and data {{}} because {self.endpoint_names[0]} not in roi {{}}" # type: ignore
).format(u, v, data, roi)
)
continue
Expand All @@ -495,7 +495,7 @@ def update_edges(
update_statement = (
f"UPDATE {self.edges_table_name} SET "
f"{', '.join(setters)} WHERE "
f"{self.endpoint_names[0]}={u} AND {self.endpoint_names[1]}={v}"
f"{self.endpoint_names[0]}={u} AND {self.endpoint_names[1]}={v}" # type: ignore
)

self._update_query(update_statement, commit=False)
Expand Down Expand Up @@ -653,7 +653,7 @@ def __remove_keys(self, dictionary, keys):

def __get_node_pos(self, n: dict[str, Any]) -> Optional[Coordinate]:
try:
return Coordinate(n[self.position_attribute])
return Coordinate(n[self.position_attribute]) # type: ignore
except KeyError:
return None

Expand All @@ -677,7 +677,7 @@ def __attr_query(self, attrs: dict[str, Any]) -> str:
def __roi_query(self, roi: Roi) -> str:
query = "WHERE "
pos_attr = self.position_attribute
for dim in range(self.ndims):
for dim in range(self.ndims): # type: ignore
if dim > 0:
query += " AND "
if roi.begin[dim] is not None and roi.end[dim] is not None:
Expand Down
8 changes: 4 additions & 4 deletions funlib/persistence/graphs/sqlite_graph_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,16 @@ def _create_tables(self) -> None:
f"{', '.join(node_columns)}"
")"
)
if self.ndims > 1:
if self.ndims > 1: # type: ignore
position_columns = self.node_array_columns[self.position_attribute]
else:
position_columns = self.position_attribute
self.cur.execute(
f"CREATE INDEX IF NOT EXISTS pos_index ON {self.nodes_table_name}({','.join(position_columns)})"
)
edge_columns = [
f"{self.endpoint_names[0]} INTEGER not null",
f"{self.endpoint_names[1]} INTEGER not null",
f"{self.endpoint_names[0]} INTEGER not null", # type: ignore
f"{self.endpoint_names[1]} INTEGER not null", # type: ignore
]
for attr in self.edge_attrs.keys():
if attr in self.edge_array_columns:
Expand All @@ -115,7 +115,7 @@ def _create_tables(self) -> None:
self.cur.execute(
f"CREATE TABLE IF NOT EXISTS {self.edges_table_name}("
+ f"{', '.join(edge_columns)}"
+ f", PRIMARY KEY ({self.endpoint_names[0]}, {self.endpoint_names[1]})"
+ f", PRIMARY KEY ({self.endpoint_names[0]}, {self.endpoint_names[1]})" # type: ignore
+ ")"
)

Expand Down
3 changes: 3 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@ ignore_missing_imports = True
ignore_missing_imports = True

[mypy-h5py.*]
ignore_missing_imports = True

[mypy-psycopg2.*]
ignore_missing_imports = True

0 comments on commit c2d205d

Please sign in to comment.