lmcinnes / umap

Uniform Manifold Approximation and Projection
BSD 3-Clause "New" or "Revised" License
7.46k stars 809 forks source link

Interactive plot argument: tool - 'NoneType' object is not iterable #1057

Closed timoleistner closed 1 year ago

timoleistner commented 1 year ago

If I try to create an interactive plot (like in the docs) with hover_data provided as argument, there is no check if the argument tools is None.

p = umap.plot.interactive(
    mapper,
    labels=fmnist.target[:30000],
    hover_data=hover_data,
    point_size=2
)
umap.plot.show(p)

https://github.com/lmcinnes/umap/blob/5f7512b95061e72b362017abd1e4cb9517c9c8bc/umap/plot.py#L1443C1-L1453C26

This is a simple fix with either the following

            if tools:
                for _tool in tools:
                    if _tool.__class__.__name__ == "HoverTool":
                        tooltip_needed = False
                        break

or more explicit and on par with the rest of the code style

            if tools is not None:
                for _tool in tools:
                    if _tool.__class__.__name__ == "HoverTool":
                        tooltip_needed = False
                        break

or with changing the default value of the argument to an empty list.

p = umap.plot.interactive(
    mapper,
    labels=fmnist.target[:30000],
    hover_data=hover_data,
    tools=[],
    point_size=2
)
umap.plot.show(p)

Or update the docs and include my last code snippet with the empty list argument. If you decide on a solution I can also make a pull request :)

Edit: made a pull request