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

Add order argument to ts.nodes() #2471

Merged
merged 1 commit into from
Sep 5, 2022
Merged

Conversation

hyanwong
Copy link
Member

@hyanwong hyanwong commented Aug 23, 2022

Fixes #2370

This uses a lambda function, which make it quite a neat and flexible change without affecting performance of the SimpleContainerSequence.__getitem__ function. Is that OK?

It also means we can do things like:

ts = tskit.Tree.generate_balanced(10).tree_sequence
nodes_in_time_order = ts.nodes(order="timedesc")
nodes_in_time_order[0]  # returns node 18

But I think that's quite reasonable behaviour. If this seems like the right approach, I'll add some tests.

@codecov
Copy link

codecov bot commented Aug 23, 2022

Codecov Report

Merging #2471 (42fbc5f) into main (70de29f) will decrease coverage by 0.02%.
The diff coverage is n/a.

❗ Current head 42fbc5f differs from pull request most recent head c4684cd. Consider uploading reports for the commit c4684cd to get more accurate results

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2471      +/-   ##
==========================================
- Coverage   93.43%   93.40%   -0.03%     
==========================================
  Files          28       28              
  Lines       27401    27321      -80     
  Branches     1255     1246       -9     
==========================================
- Hits        25601    25520      -81     
  Misses       1766     1766              
- Partials       34       35       +1     
Flag Coverage Δ
c-tests 92.24% <0.00%> (ø)
lwt-tests 89.05% <0.00%> (ø)
python-c-tests 71.17% <0.00%> (-0.01%) ⬇️
python-tests 98.94% <0.00%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
python/tskit/trees.py 98.64% <0.00%> (-0.09%) ⬇️
python/tskit/tables.py 98.92% <0.00%> (-0.04%) ⬇️
python/tskit/combinatorics.py 99.36% <0.00%> (-0.01%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 70de29f...c4684cd. Read the comment docs.

@hyanwong hyanwong force-pushed the ts-node-order branch 2 times, most recently from d536a03 to 0398cdf Compare August 24, 2022 09:18
@jeromekelleher
Copy link
Member

LGTM. Not obvious to me why timedesc would have ascending node ID as the secondary key though (or at least I can't think of any practical usage of this). Wouldn't it be simpler if timedesc was equal to reversed timeasc?

@hyanwong
Copy link
Member Author

hyanwong commented Aug 24, 2022

Wouldn't it be simpler if timedesc was equal to reversed timeasc

There's no need to have a "timedesc" in that case, as the iterator is reversible: reversed(ts.nodes(order="timeasc")). I put "timedesc" in there in case the alternative was needed, for instance traversing down through an ARG while retaining the "standard" order for ties. But it's a very niche case. Maybe we remove "timedesc" until such time as someone else wants that particular functionality.

@jeromekelleher
Copy link
Member

Let's remove timedesc then, so we're not painting ourselves into a corner with the semantics. Maybe document the trick about for reversing?

@hyanwong hyanwong marked this pull request as ready for review August 24, 2022 15:54
@hyanwong
Copy link
Member Author

@Mergifyio rebase

@mergify
Copy link
Contributor

mergify bot commented Aug 26, 2022

rebase

✅ Branch has been successfully rebased

Copy link
Member

@jeromekelleher jeromekelleher left a comment

Choose a reason for hiding this comment

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

LGTM, some comments on testing.

python/tests/test_highlevel.py Outdated Show resolved Hide resolved
python/tests/test_highlevel.py Outdated Show resolved Hide resolved
@benjeffery
Copy link
Member

@hyanwong Shall I review now?

@hyanwong
Copy link
Member Author

hyanwong commented Sep 5, 2022

@hyanwong Shall I review now?

Yes please.

@benjeffery benjeffery added the AUTOMERGE-REQUESTED Ask Mergify to merge this PR label Sep 5, 2022
@mergify mergify bot merged commit b59a80f into tskit-dev:main Sep 5, 2022
@mergify mergify bot removed the AUTOMERGE-REQUESTED Ask Mergify to merge this PR label Sep 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add order argument to TreeSequence.nodes
3 participants