Skip to content

Skip empty #2670

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

Closed
wants to merge 2 commits into from
Closed

Skip empty #2670

wants to merge 2 commits into from

Conversation

hyanwong
Copy link
Member

Description

Based off #2668, and fixes #2600. I'm not sure if storing the skip_empty value as a python attribute in the Tree class is the right approach (it's not what's done for root_threshold) but from the tests it appears as if the call signature of Tree() and ts.trees() should be the same. Otherwise I would just have this as a parameter sent to the TreeIterator iterator class from the ts.trees() method, and not bother storing it in the Tree class itself.

Suggestions for other approaches welcome

PR Checklist:

  • Tests that fully cover new/changed functionality.
  • Documentation including tutorial content if appropriate.
  • Changelogs, if there are API changes.

@codecov
Copy link

codecov bot commented Dec 24, 2022

Codecov Report

Merging #2670 (cf6cd53) into main (ec992da) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #2670   +/-   ##
=======================================
  Coverage   93.91%   93.91%           
=======================================
  Files          27       28    +1     
  Lines       27657    27697   +40     
  Branches     1270     1275    +5     
=======================================
+ Hits        25973    26013   +40     
  Misses       1647     1647           
  Partials       37       37           
Flag Coverage Δ
c-tests 92.25% <ø> (ø)
lwt-tests 89.05% <ø> (ø)
python-c-tests 72.24% <42.10%> (+0.01%) ⬆️
python-tests 98.97% <100.00%> (+<0.01%) ⬆️

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

Impacted Files Coverage Δ
python/tskit/trees.py 98.76% <100.00%> (+<0.01%) ⬆️
python/tskit/__init__.py 100.00% <0.00%> (ø)

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 ec992da...cf6cd53. Read the comment docs.

@hyanwong hyanwong mentioned this pull request Jan 6, 2023
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.

Looks good, but I'm certain now that having a single simple definition of is_empty is the right approach. There's no need to add attributes to the tree object then, since it's purely a property of the iterator.

@@ -3822,6 +3853,7 @@ def __init__(self, tree):
self.tree = tree
self.more_trees = True
self.forward = True
self.no_skip_empty = True if tree.skip_empty is None else not tree.skip_empty
Copy link
Member

Choose a reason for hiding this comment

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

More natural to make skip_empty a parameter of the TreeIterator class, so we call it like:

return TreeIterator(tree, skip_empty=skip_empty)

self.more_trees = self.more_trees and self.tree.prev()
if not self.more_trees:
raise StopIteration()
while True:
Copy link
Member

@jeromekelleher jeromekelleher Jan 8, 2023

Choose a reason for hiding this comment

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

This looks correct, but I think we'd need a good bit of testing to check what happens when we have runs of empty trees in the middle. Although, come to think of it I don't think we can have two adjacent empty trees, so maybe this while look could be replace with something simpler?

For example, you could simply wrap this iterator like so:

trees = TreeIterator(tree)
if skip_empty:
     for tree in trees:
           if not tree.is_empty():
                 yield tree
else:
    return trees

@hyanwong
Copy link
Member Author

Closed due to #2600 (comment)

@hyanwong hyanwong closed this Jan 10, 2023
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.

How to skip empty regions at the start and end of a tree seq
2 participants