Retrieve a single sub-component from a network data object.
Source code in /opt/hostedtoolcache/Python/3.11.4/x64/lib/python3.11/site-packages/kiara_plugin/network_analysis/modules/filters.py
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72 | def filter__component(self, value: Value, filter_inputs: Mapping[str, Any]):
"""Retrieve a single sub-component from a network data object."""
component_id = filter_inputs["component_id"]
component_column = filter_inputs["component_column"]
network_data: NetworkData = value.data
if component_column not in network_data.nodes.column_names:
msg = f"Component column `{component_column}` not valid for this network_data instance.\n\nAvailable column names:\n\n"
for attr in network_data.nodes.column_names:
msg += f" - {attr}\n"
if component_column == COMPONENT_ID_COLUMN_NAME:
msg = f"{msg}\n\nTry to run the `network_data.extract_components` module on your network_data before using this module."
raise KiaraProcessingException(msg)
network_data.nodes.arrow_table.column(component_column).type
# filter_item = pa.scalar(component_id, type=pa.int32())
query = f"select {NODE_ID_COLUMN_NAME} from nodes where {component_column} = {component_id}"
node_result = network_data.query_nodes(query)
network_data = NetworkData.from_filtered_nodes(
network_data=network_data,
nodes_list=node_result.column(NODE_ID_COLUMN_NAME).to_pylist(),
)
return network_data
|