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

Fix ancestor removal logic #6

Merged
merged 4 commits into from
Jun 10, 2024
Merged

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 merged commit d9c159f into main Jun 10, 2024
3 checks passed
@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.

3 participants