tskit icon indicating copy to clipboard operation
tskit copied to clipboard

Warning for `draw_svg` plot uses `logging` module instead of `warnings`

Open duncanMR opened this issue 2 years ago • 2 comments
trafficstars

I came across a minor issue with the plotting code: the draw_svg warning for mutations above unplotted nodes uses the logging module instead of the warnings module, that we'd usually use for user warnings. I discovered this because I couldn't find a way to suppress it. The warning is currently this:

if len(unplotted) > 0:
     logging.warning(
          f"Mutations {unplotted} are above nodes which are not present in the "
          "displayed tree, so are not plotted on the topology."
     )

If we were to use warnings instead, I'm guessing we'd do something like this? I'm not sure what stack level is appropriate here.

if len(unplotted) > 0:
     warnings.warn(
          f"Mutations {unplotted} are above nodes which are not present in the "
          "displayed tree, so are not plotted on the topology.",
          UserWarning,
          stacklevel=2
     )

duncanMR avatar Nov 14 '23 15:11 duncanMR

PR welcome!

jeromekelleher avatar Nov 14 '23 15:11 jeromekelleher

I realised we forgot to update the changelog to track this bugfix (we should really note anything that's fixing a bug, even if it is fairly trivial like this) so opening this again to track that.

jeromekelleher avatar Nov 15 '23 13:11 jeromekelleher