Skip to content

Conversation

@SimonHeybrock
Copy link
Member

See first commit for actual change, second commit fixes ruff (mostly unrelated to this change).

g2 = nx.DiGraph()
g2.add_edge('b', 'c')
graph['c'] = cb.Graph(g2)

Copy link
Member

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.

g.add_edge('c', 'd')
graph = cb.Graph(g)
graph['c'] = graph['c']
assert 'a' in graph.to_networkx()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work?

Suggested change
assert 'a' in graph.to_networkx()
assert graph.to_networkx() == g

Copy link
Member

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.

Comment on lines 34 to 36
ancestors_descendants = {
ancestor: nx.descendants(graph_without_node, ancestor) for ancestor in ancestors
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could use

Suggested change
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.)

@SimonHeybrock SimonHeybrock requested a review from jl-wynen June 6, 2024 06:47
@SimonHeybrock SimonHeybrock merged commit d9c159f into main Jun 10, 2024
@SimonHeybrock SimonHeybrock deleted the fix-ancestor-removal-logic branch June 10, 2024 03:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants