Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VertexCover.__plot__ mark_groups argument does not behave correctly and can cause a crash #789

Closed
Aethor opened this issue Jul 10, 2024 · 1 comment

Comments

@Aethor
Copy link

Aethor commented Jul 10, 2024

Describe the bug
VertexCover.__plot__ mark_groups specifies in the doc that it accepts a "dict mapping cluster indices or tuples of vertex indices to color names". However, giving such a dict results in an AttributeError:

AttributeError: 'dict' object has no attribute 'iteritems'

This is because mark_groups is parsed using igraph.clustering._handle_mark_groups_arg_for_clustering, which uses iteritems that was removed in Python3. Using items instead fixes the issues. I'm happy to provide a PR if needed.

To reproduce

import igraph as ig
import matplotlib.pyplot as plt


g = ig.Graph(edges=[[0, 1], [2, 3]])
clusters = [[0, 1], [2, 3]]
cover = ig.VertexCover(g, clusters)
fig, ax = plt.subplots()
ig.plot(
    cover,
    target=ax,
    mark_groups={0: "red", 1: "green"},
)
plt.show()

Note that there is a workaround:

import igraph as ig
import matplotlib.pyplot as plt


g = ig.Graph(edges=[[0, 1], [2, 3]])
clusters = [[0, 1], [2, 3]]
cover = ig.VertexCover(g, clusters)
fig, ax = plt.subplots()
ig.plot(
    cover,
    target=ax,
    mark_groups={0: "red", 1: "green"}.items(), # <= ensure correct parsingof mark_groups
)
plt.show()

Version information
0.11.3, obtained from pypi using pip. (but 0.11.6 should also be subject to the bug as the related code is the same)

@ntamas ntamas closed this as completed in 7caa934 Jul 15, 2024
@ntamas
Copy link
Member

ntamas commented Jul 15, 2024

Thanks for the report, this is now fixed in the source.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants