Skip to content
This repository has been archived by the owner on Mar 5, 2024. It is now read-only.

Commit

Permalink
chore: fix mypy issues
Browse files Browse the repository at this point in the history
  • Loading branch information
makkus committed Nov 13, 2023
1 parent d437bc7 commit 64dbbfe
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 17 deletions.
10 changes: 8 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,14 @@ plugins = [
"pydantic.mypy"
]


# mypy per-module options:
[[tool.mypy.overrides]]
module = ["placholder.dummy.*"]
module = [
"kiara_plugin.streamlit.*",
"networkx.*",
"pyarrow.*",
"pyvis.*",
"ruamel.*",
"streamlit.*"
]
ignore_missing_imports = true
5 changes: 5 additions & 0 deletions src/kiara_plugin/network_analysis/data_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ def parse_python_obj(self, data: Any) -> NetworkData:
augment_tables=False,
)

if not isinstance(data, NetworkData):
raise KiaraException(
f"Can't parse object to network data: invalid type '{type(data)}'."
)

return data

def _validate(cls, value: Any) -> None:
Expand Down
8 changes: 4 additions & 4 deletions src/kiara_plugin/network_analysis/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def from_filtered_nodes(

node_columns = [NODE_ID_COLUMN_NAME, LABEL_COLUMN_NAME]
for column_name, metadata in network_data.nodes.column_metadata.items():
attr_prop: Union[None, NetworkNodeAttributeMetadata] = metadata.get(
attr_prop: Union[None, NetworkNodeAttributeMetadata] = metadata.get( # type: ignore
ATTRIBUTE_PROPERTY_KEY, None
)
if attr_prop is None or not attr_prop.computed_attribute:
Expand All @@ -271,7 +271,7 @@ def from_filtered_nodes(
edges_table = network_data.edges.arrow_table # noqa
edge_columns = [SOURCE_COLUMN_NAME, TARGET_COLUMN_NAME]
for column_name, metadata in network_data.edges.column_metadata.items():
attr_prop = metadata.get(ATTRIBUTE_PROPERTY_KEY, None)
attr_prop = metadata.get(ATTRIBUTE_PROPERTY_KEY, None) # type: ignore
if attr_prop is None or not attr_prop.computed_attribute:
edge_columns.append(column_name)

Expand Down Expand Up @@ -390,7 +390,7 @@ def _calculate_node_attributes(
if incl_node_attributes is False:
node_attr_names: List[str] = [NODE_ID_COLUMN_NAME, LABEL_COLUMN_NAME]
else:
all_node_attr_names = self.nodes.column_names
all_node_attr_names: List[str] = self.nodes.column_names # type: ignore
if incl_node_attributes is True:
node_attr_names = [NODE_ID_COLUMN_NAME]
node_attr_names.extend((x for x in all_node_attr_names if x != NODE_ID_COLUMN_NAME)) # type: ignore
Expand Down Expand Up @@ -598,7 +598,7 @@ def add_edge(_source: int, _target: int, **attrs):
)

if attach_node_id_map:
graph.attrs = {"node_id_map": node_map}
graph.attrs = {"node_id_map": node_map} # type: ignore

return graph

Expand Down
2 changes: 1 addition & 1 deletion src/kiara_plugin/network_analysis/models/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class AttributeMapStrategy(KiaraModel):

@model_validator(mode="before")
@classmethod
def validate(cls, values: Dict[str, Any]):
def pre_validate_model(cls, values: Dict[str, Any]):

if len(values) == 1 and DEFAULT_MODEL_KEY in values.keys():

Expand Down
4 changes: 2 additions & 2 deletions src/kiara_plugin/network_analysis/modules/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from typing import Any, Dict, List, Union
from typing import Any, Dict, List, Mapping, Union

from kiara.api import KiaraModule, ValueMap, ValueMapSchema
from kiara.exceptions import KiaraProcessingException
Expand Down Expand Up @@ -28,7 +28,7 @@ class RedefineNetworkEdgesModule(KiaraModule):
def create_inputs_schema(
self,
) -> ValueMapSchema:
result = {
result: Mapping[str, Mapping[str, Any]] = {
"network_data": {
"type": "network_data",
"doc": "The network data to flatten.",
Expand Down
17 changes: 10 additions & 7 deletions src/kiara_plugin/network_analysis/modules/components.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from typing import Any, Dict
from typing import TYPE_CHECKING, Any, Dict

from kiara.api import KiaraModule, ValueMap, ValueMapSchema
from kiara.exceptions import KiaraException
Expand All @@ -11,6 +11,9 @@
from kiara_plugin.network_analysis.models import NetworkData
from kiara_plugin.network_analysis.models.metadata import NetworkNodeAttributeMetadata

if TYPE_CHECKING:
from kiara.models import KiaraModel

KIARA_METADATA = {
"authors": [
{"name": "Lena Jaskov", "email": "helena.jaskov@uni.lu"},
Expand Down Expand Up @@ -86,9 +89,9 @@ def process(self, inputs: ValueMap, outputs: ValueMap):
omit_self_loops=False,
attach_node_id_map=True,
)
undir_components = rx.connected_components(undir_graph)
undir_components = rx.connected_components(undir_graph) # type: ignore

nodes_columns_metadata = {
nodes_columns_metadata: Dict[str, Dict[str, KiaraModel]] = {
COMPONENT_ID_COLUMN_NAME: {
ATTRIBUTE_PROPERTY_KEY: COMPONENT_COLUMN_METADATA
}
Expand All @@ -115,7 +118,7 @@ def process(self, inputs: ValueMap, outputs: ValueMap):

number_of_components = len(undir_components)
is_connected = False
node_id_map = undir_graph.attrs["node_id_map"]
node_id_map = undir_graph.attrs["node_id_map"] # type: ignore

node_components = {}
for idx, component in enumerate(
Expand Down Expand Up @@ -192,9 +195,9 @@ def process(self, inputs, outputs) -> None:
attach_node_id_map=True,
)

node_id_map = undir_graph.attrs["node_id_map"]
node_id_map = undir_graph.attrs["node_id_map"] # type: ignore

cut_points = rx.articulation_points(undir_graph)
cut_points = rx.articulation_points(undir_graph) # type: ignore
translated_cut_points = [node_id_map[x] for x in cut_points]
if not cut_points:
raise NotImplementedError()
Expand All @@ -208,7 +211,7 @@ def process(self, inputs, outputs) -> None:
IS_CUTPOINT_COLUMN_NAME, pa.array(cut_points_column, type=pa.bool_())
)

nodes_columns_metadata = {
nodes_columns_metadata: Dict[str, Dict[str, KiaraModel]] = {
IS_CUTPOINT_COLUMN_NAME: {
ATTRIBUTE_PROPERTY_KEY: CUT_POINTS_COLUMN_METADATA
}
Expand Down
2 changes: 1 addition & 1 deletion src/kiara_plugin/network_analysis/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def extract_networkx_edges_as_table(

def augment_nodes_table_with_connection_counts(
nodes_table: Union["pa.Table", "pl.DataFrame"],
edges_table: Union["pa.Table", "pl.Dataframe"],
edges_table: Union["pa.Table", "pl.DataFrame"],
) -> "pa.Table":

import duckdb
Expand Down

0 comments on commit 64dbbfe

Please sign in to comment.