Skip to content

Commit

Permalink
Access the left and right as an interval
Browse files Browse the repository at this point in the history
  • Loading branch information
hyanwong authored and mergify[bot] committed Sep 24, 2024
1 parent d6b2303 commit 8a958e9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions python/CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
- Add ``Interval.mid`` and ``Tree.mid`` properties to return the midpoint of the interval.
(:user:`currocam`, :pr:`2960`)

- Edges now have an ``.interval`` attribute returning a ``tskit.Interval`` object.
(:user:`hyanwong`, :pr:`2531`)

--------------------
[0.5.8] - 2024-06-27
Expand Down
8 changes: 8 additions & 0 deletions python/tests/test_highlevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -1576,6 +1576,14 @@ def test_edge_span_property(self, ts):
for edge in ts.edges():
assert edge.span == edge.right - edge.left

@pytest.mark.parametrize("ts", get_example_tree_sequences())
def test_edge_interval_property(self, ts):
for edge in ts.edges():
assert edge.interval == (edge.left, edge.right)
if ts.num_trees == 1 and ts.num_edges > 0:
for edge in ts.edges():
assert edge.interval == ts.first().interval

def test_edgesets(self):
tested = False
# We manual loop in this test to test the example tree sequences are working
Expand Down
10 changes: 10 additions & 0 deletions python/tskit/trees.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,16 @@ def span(self):
"""
return self.right - self.left

@property
def interval(self):
"""
Returns the left and right positions of this edge as an :class:`Interval`
:return: The interval covered by this edge.
:rtype: :class:`Interval`
"""
return Interval(self.left, self.right)


@metadata_module.lazy_decode()
@dataclass
Expand Down

0 comments on commit 8a958e9

Please sign in to comment.