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

[Draft] Node grouping #4427

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all 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
40 changes: 40 additions & 0 deletions kedro/pipeline/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,46 @@ def grouped_nodes(self) -> list[list[Node]]:

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

@property
def grouped_by_namespace(self):
"""Return a dictionary of the pipeline nodes grouped by namespace.

Returns:
The pipeline nodes grouped by namespace.
"""
nodes_by_namespace = defaultdict(list)
for node in self.nodes:
if node.namespace:
nodes_by_namespace[node.namespace].append(node)
else:
nodes_by_namespace[node.name].append(node)
return nodes_by_namespace

@property
def node_dependencies_by_namespace(self):
"""Return a dictionary of the pipeline nodes dependencies grouped by namespace.

Returns:
The pipeline nodes dependencies grouped by namespace.
"""
node_dependencies_by_namespace = defaultdict(dict)
for node in self.nodes:
key = node.namespace if node.namespace else node.name
for parent in self.node_dependencies[node]:
if key not in node_dependencies_by_namespace:
node_dependencies_by_namespace[key] = []
if parent.namespace and parent.namespace != key:
node_dependencies_by_namespace[key].append(parent.namespace)
elif parent.namespace and parent.namespace == key:
continue
else:
node_dependencies_by_namespace[key].append(parent.name)

node_dependencies_by_namespace = {
key: set(value) for key, value in node_dependencies_by_namespace.items()
}
return node_dependencies_by_namespace

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