-
Notifications
You must be signed in to change notification settings - Fork 1
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
Fix ancestor removal logic #6
Conversation
tests/graph_test.py
Outdated
g2 = nx.DiGraph() | ||
g2.add_edge('b', 'c') | ||
graph['c'] = cb.Graph(g2) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no assert here.
tests/graph_test.py
Outdated
g.add_edge('c', 'd') | ||
graph = cb.Graph(g) | ||
graph['c'] = graph['c'] | ||
assert 'a' in graph.to_networkx() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this work?
assert 'a' in graph.to_networkx() | |
assert graph.to_networkx() == g |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be nx.utils.graphs_equal(graph.to_networkx(), g)
for equality.
src/cyclebane/graph.py
Outdated
ancestors_descendants = { | ||
ancestor: nx.descendants(graph_without_node, ancestor) for ancestor in ancestors | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could use
ancestors_descendants = { | |
ancestor: nx.descendants(graph_without_node, ancestor) for ancestor in ancestors | |
} | |
ancestors_descendants = [ | |
(ancestor, nx.descendants(graph_without_node, ancestor)) for ancestor in ancestors | |
] |
to avoid computing hashes. And technically, you could also express the whole construction of to_remove
as a list comprehension. (I'm surprised ruff didn't suggest the latter.)
See first commit for actual change, second commit fixes ruff (mostly unrelated to this change).