Iterate over all nodes in this tree, including both self and all descendants. Iterates breadth-first. See Also -------- DataTree.subtree_with_keys DataTree.descendants group_subtrees
(self)
| 394 | |
| 395 | @property |
| 396 | def subtree(self) -> Iterator[Self]: |
| 397 | """ |
| 398 | Iterate over all nodes in this tree, including both self and all descendants. |
| 399 | |
| 400 | Iterates breadth-first. |
| 401 | |
| 402 | See Also |
| 403 | -------- |
| 404 | DataTree.subtree_with_keys |
| 405 | DataTree.descendants |
| 406 | group_subtrees |
| 407 | """ |
| 408 | # https://en.wikipedia.org/wiki/Breadth-first_search#Pseudocode |
| 409 | queue = collections.deque([self]) |
| 410 | while queue: |
| 411 | node = queue.popleft() |
| 412 | yield node |
| 413 | queue.extend(node.children.values()) |
| 414 | |
| 415 | @property |
| 416 | def subtree_with_keys(self) -> Iterator[tuple[str, Self]]: |