Skip to content

Local variable referenced before assignment when drawing SVG #3273

Closed

Description

@alfroids

I am calling the draw_svg method from a Tree object and the root node's time is too far back, so I am trying to use the max_time option to draw only the relevant part. However, the method ends up giving an UnboundLocalError:

UnboundLocalError: local variable 'max_node_height' referenced before assignment

Activity

  1. hyanwong commented on Sep 18, 2025

    @hyanwong
    Member

    Oh dear, that shouldn't happen. Apologies. Would it be possible to provide a minimum working example? I see that the following does work:

    import tskit
    tskit.Tree.generate_balanced(5).draw_svg(max_time=0.1)
  2. added
    bug
    on Sep 19, 2025
  3. added a commit that references this issue on Sep 19, 2025
  4. benjeffery commented on Sep 19, 2025

    @benjeffery
    Member

    @alfroids Thanks for the report! I have fixed this issue in PR #3274

  5. added a commit that references this issue on Sep 19, 2025
  6. hyanwong commented on Sep 19, 2025

    @hyanwong
    Member

    The fix seems OK to me. @alfroids: could you possibly check whether it does what you expect in your use-case?

    You can install the latest GH version of tskit with this fix by using

    pip install git+https://github.com/tskit-dev/tskit#subdirectory=python
  7. alfroids commented on Sep 22, 2025

    @alfroids
    Author

    Hi @hyanwong, I just installed the fixed version and indeed the error went away and the file was created. Now, I don't know if I didn't understand this option correctly or if there's another bug, but the image that I got wasn't capped at the max_time I specified. Is there another option I should use if I want my tree to only render up to a given number of generations in the past?

  8. hyanwong commented on Sep 23, 2025

    @hyanwong
    Member

    Can you try again. The fix wasn't quite right.

  9. alfroids commented on Sep 23, 2025

    @alfroids
    Author

    It worked, thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions