From bc9c37e65ea993059afd72007165b7bc1671db99 Mon Sep 17 00:00:00 2001 From: Maxime Lucas Date: Mon, 28 Aug 2023 14:19:57 +0200 Subject: [PATCH 1/2] test: for node order --- tests/core/test_hypergraph.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/core/test_hypergraph.py b/tests/core/test_hypergraph.py index 142156d41..dcc7f1709 100644 --- a/tests/core/test_hypergraph.py +++ b/tests/core/test_hypergraph.py @@ -72,7 +72,9 @@ def test_lshift(edgelist1, edgelist2, hyperwithattrs): H2 = xgi.Hypergraph(edgelist2) H3 = hyperwithattrs H = H1 << H2 - assert set(H.nodes) == {1, 2, 3, 4, 5, 6, 7, 8} + nodes1 = list(H1.nodes) + assert nodes1 == [1, 2, 3, 4, 5, 6, 8, 7] + assert list(H.nodes) == nodes1 assert H.num_edges == 7 assert H.edges.members(0) == {1, 2, 3} From 599b635797fa2de69bbed9da9bcd2e187d3fa366 Mon Sep 17 00:00:00 2001 From: Maxime Lucas Date: Mon, 28 Aug 2023 14:20:25 +0200 Subject: [PATCH 2/2] fix: consistent node order --- xgi/core/hypergraph.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/xgi/core/hypergraph.py b/xgi/core/hypergraph.py index a4aa50a7e..3d1539ba4 100644 --- a/xgi/core/hypergraph.py +++ b/xgi/core/hypergraph.py @@ -273,11 +273,12 @@ def __lshift__(self, H2): [{1, 2}, {2, 3}, {1, 3, 4}] """ tempH = Hypergraph() - tempH.add_edges_from(zip(self._edge.values(), self._edge_attr.values())) + tempH.add_nodes_from(zip(self._node.keys(), self._node_attr.values())) + tempH.add_nodes_from(zip(H2._node.keys(), H2._node_attr.values())) + tempH.add_edges_from(zip(self._edge.values(), self._edge_attr.values())) tempH.add_edges_from(zip(H2._edge.values(), H2._edge_attr.values())) - tempH.add_nodes_from(zip(H2._node.keys(), H2._node_attr.values())) tempH._hypergraph = deepcopy(self._hypergraph) tempH._hypergraph.update(deepcopy(H2._hypergraph))