xgi
xgi copied to clipboard
EdgeView comparison only checks edge ID, not contents
This is Bad.
In [11]: H1 = xgi.Hypergraph([{0, 1, 2}, {0}, {1, 2}])
In [12]: H2 = xgi.Hypergraph([{1, 2, 3}, {0}, {1, 3}])
In [13]: H1 == H2
Out[13]: False
In [14]: H1.edges == H2.edges
Out[14]: True
OK to be honest, what I wrote in the title is my current hunch as to why this is happening, but I might be wrong.
An easy (temporary?) fix is to encourage the user to do this instead:
H1.edges.members(dtype=dict) == H2.edges.members(dtype=dict)
Is this a bug though? H.edges
contains edges IDs, so your example is not so surprising.
Although a user might write
In [14]: H1.edges == H2.edges
and expect
Out[14]: False
assuming it's gonna compare edges members rather than IDs.
We could implement =
between H.edges
as checking for the full dict {ID: members} as the fix you suggested. In both cases, we should clarify this in the doc.
Yeah coming back to this the main problem I see is that the user may inadvertently compare two views from two different network instead of two views from the same network. And the question is whether we want EdgeViews to compare only based on the IDs rather than also take into account which network those IDs belong to.
Okay I think my preference would be that comparing two views only works when they come from the same network. If the user wants to compare only the IDs contained, they can use view.ids
. So we'd have:
H1.edges == H2.edges
# -> always False, regardless of edge IDs
H1.edges.ids == H2.edges.ids
# -> may be True, if H1 and H2 have the same edge IDs
Will work on this after #406 is merged.
What do we want if the two have the same hyperedges (based on members) but different IDs?
That sounds dangerously close to determining whether two hypergraphs are isomorphic :grin: