Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Prototype] Node grouping #4427

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions kedro/pipeline/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,30 @@ def grouped_nodes(self) -> list[list[Node]]:

return [list(group) for group in self._toposorted_groups]

@property
def grouped_nodes_by_namespace(self) -> dict[str, dict[str, Any]]:
grouped_nodes: dict[str, dict[str, Any]] = defaultdict(dict)
for node in self.nodes:
key = node.namespace or node.name
if key not in grouped_nodes:
grouped_nodes[key] = {}
grouped_nodes[key]["name"] = key
grouped_nodes[key]["type"] = "namespace" if node.namespace else "node"
grouped_nodes[key]["nodes"] = [*grouped_nodes[key].get("nodes", []), node]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we have O(Nˆ2) complexity here, as every time we add a node, we recreate a list based on what was already there. So maybe it makes sense to initialize grouped_nodes[key]["nodes"] and then just append to it.

deps = set()
for parent in self.node_dependencies[node]:
if parent.namespace and parent.namespace != key:
deps.add(parent.namespace)
elif parent.namespace and parent.namespace == key:
continue
else:
deps.add(parent.name)
grouped_nodes[key]["dependencies"] = (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here is the same as the above

grouped_nodes[key].get("dependencies", set()) | deps
)

return grouped_nodes

def only_nodes(self, *node_names: str) -> Pipeline:
"""Create a new ``Pipeline`` which will contain only the specified
nodes by name.
Expand Down
Loading