Skip to content

Commit 8b615e5

Browse files
committed
Fix issue #3273
1 parent 2710dcc commit 8b615e5

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

python/CHANGELOG.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@
5151
"self" comparisons for `TreeSequence.genetic_relatedness`. This changes the
5252
error code returned in some situations.
5353
(:user:`andrewkern`, :user:`petrelharp`, :pr:`3235`, :issue:`3055`)
54-
54+
55+
- Fix ``UnboundLocalError`` in ``draw_svg()`` when using numeric ``max_time``
56+
values with mutations over roots.
57+
(:user:`benjeffery`, :pr:`3274`, :issue:`3273`)
58+
5559

5660
**Breaking changes**
5761

python/tests/test_drawing.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1868,6 +1868,22 @@ def test_min_ts_time(self):
18681868
svg3 = ts.draw_svg(min_time=min(ts.tables.nodes.time), y_axis=True)
18691869
assert svg2 == svg3
18701870

1871+
def test_numeric_max_time_with_mutations_over_roots(self):
1872+
t = self.get_mutations_over_roots_tree()
1873+
max_time_value = 10.0 # Use a numeric max_time value
1874+
1875+
with pytest.warns(
1876+
UserWarning, match="Mutations .* are above nodes which are not present"
1877+
):
1878+
svg = t.draw_svg(max_time=max_time_value)
1879+
self.verify_basic_svg(svg)
1880+
1881+
with pytest.warns(
1882+
UserWarning, match="Mutations .* are above nodes which are not present"
1883+
):
1884+
svg_log = t.draw_svg(max_time=max_time_value, time_scale="log_time")
1885+
self.verify_basic_svg(svg_log)
1886+
18711887
#
18721888
# TODO: update the tests below here to check the new SVG based interface.
18731889
#

python/tskit/drawing.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2003,6 +2003,8 @@ def assign_y_coordinates(
20032003
max_node_height = self.ts.max_root_time
20042004
max_mut_height = np.nanmax(np.append(mut_time, 0))
20052005
max_time = max(max_node_height, max_mut_height) # Reuse variable
2006+
else:
2007+
max_node_height = max(self.node_height.values())
20062008
if min_time == "tree":
20072009
min_time = min(self.node_height.values())
20082010
# don't need to check mutation times, as they must be above a node

0 commit comments

Comments
 (0)