-
Notifications
You must be signed in to change notification settings - Fork 73
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
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:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, needs some tweaks as the semantics aren't quite right.
python/tskit/trees.py
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
python/tskit/trees.py
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 nodeu
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 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
e6e24b7
to
2f60e98
Compare
Should be good to go now |
python/tskit/trees.py
Outdated
<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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need backticks:
:ref:`tutorials:sec_analysing_trees_traversals`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
python/tskit/trees.py
Outdated
<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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need backticks:
:ref:`tutorials:sec_analysing_trees_traversals`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it does
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trivial nitpicks
python/tskit/trees.py
Outdated
""" | ||
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"last element"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More nitpicks, sorry!
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