Document numpy traversals#1952
Conversation
Codecov Report
@@ Coverage Diff @@
## main #1952 +/- ##
=======================================
Coverage 93.32% 93.32%
=======================================
Files 27 27
Lines 25212 25212
Branches 1108 1108
=======================================
Hits 23530 23530
Misses 1648 1648
Partials 34 34
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
|
Yay, I was just about to do this @benjeffery but you beat me to it! A couple of things:
|
jeromekelleher
left a comment
There was a problem hiding this comment.
Looks good, needs some tweaks as the semantics aren't quite right.
| Also see :ref:`tutorials:sec_analysing_trees_traversals` for examples of how | ||
| to use traversals. | ||
|
|
||
| :param int u: The node to start from, defaults to the virtual root. |
There was a problem hiding this comment.
This isn't quite right. If we start from the virtual root we return the virtual root in the arrays, but this isn't what we usually want. It's more like "if specified, return all nodes in the subtree rooted at u (including u) in traversal order".
| # https://github.com/tskit-dev/tskit/issues/1788 | ||
| def preorder(self, u=NULL): | ||
| """ | ||
| Returns a numpy array of node ids. Starting at `u`, yield the current node, |
There was a problem hiding this comment.
This isn't quite right I think. How about
Returns a number array of node ids in
preorder <https://en.wikipedia.org/wiki/Tree_traversal#Pre-order_(NLR)>. If the nodeuthe traversal is rooted at this node (and it will be the first element in the returned array). Otherwise, all nodes reachable from the tree roots will be returned. See :ref:tutorials:sec_analysing_trees_traversalsfor examples.
I don't think need to describe what "preorder" is, the wikipedia link is fine. I think talking about "yielding" here is more confusing, since this isn't a generator.
e6e24b7 to
2f60e98
Compare
|
Should be good to go now |
| <https://en.wikipedia.org/wiki/Tree_traversal##Post-order_(LRN)>. If the node u | ||
| is specified the traversal is rooted at this node (and it will be the first | ||
| element in the returned array). Otherwise, all nodes reachable from the tree | ||
| roots will be returned. See :ref:tutorials:sec_analysing_trees_traversals for |
There was a problem hiding this comment.
Does this need backticks:
:ref:`tutorials:sec_analysing_trees_traversals`
| <https://en.wikipedia.org/wiki/Tree_traversal#Pre-order_(NLR)>. If the node u | ||
| is specified the traversal is rooted at this node (and it will be the first | ||
| element in the returned array). Otherwise, all nodes reachable from the tree | ||
| roots will be returned. See :ref:tutorials:sec_analysing_trees_traversals for |
There was a problem hiding this comment.
Does this need backticks:
:ref:`tutorials:sec_analysing_trees_traversals`
| """ | ||
| Returns a number array of node ids in postorder | ||
| <https://en.wikipedia.org/wiki/Tree_traversal##Post-order_(LRN)>. If the node u | ||
| is specified the traversal is rooted at this node (and it will be the first |
Great. It might be good to add something about the order of traversal if there are multiple roots. Something like: but I can add that as a further PR if you like. It would be good to merge this, then I can push my doc PR properly. |
2f60e98 to
b6364f8
Compare
|
Thanks @hyanwong should be good now |
|
Needs another pass @benjeffery |
|
We should discuss the semantics of the virtual root too - but, possibly simpler to merge this once the cross references have been fixed so that @hyanwong can merge in his version? |
b6364f8 to
e2f3424
Compare
|
Fixed |
|
@Mergifyio rebase |
e2f3424 to
c9abc72
Compare
✅ Branch has been successfully rebased |
c9abc72 to
c943632
Compare
|
Ok, hopefully that does it. FML. |
|
Do you want me to merge stuff into this before it's merged into |
|
Let's do a follow-up @hyanwong |
c943632 to
7ff7a17
Compare
Fixes #1788
Added for follow up work tskit-dev/tutorials#150