diff --git a/tests/core/test_simplicialcomplex.py b/tests/core/test_simplicialcomplex.py index b5e80212..23b4d1b8 100644 --- a/tests/core/test_simplicialcomplex.py +++ b/tests/core/test_simplicialcomplex.py @@ -462,7 +462,7 @@ def test_remove_simplex_id(edgelist6): assert set(S.edges.members()) == set(edges) -def test_remove_simplex_ids_from(edgelist6): +def test_remove_simplex_ids_from(edgelist6, edgelist4): S = xgi.SimplicialComplex() S.add_simplices_from(edgelist6) @@ -480,6 +480,12 @@ def test_remove_simplex_ids_from(edgelist6): ] assert set(S.edges.members()) == set(edges) + # test issue 580 + S1 = xgi.SimplicialComplex(edgelist4) + id_all = list(S1.edges) + S1.remove_simplex_ids_from(id_all) + assert S1.num_edges == 0 + def test_freeze(edgelist1): SC = xgi.SimplicialComplex(edgelist1) diff --git a/xgi/core/simplicialcomplex.py b/xgi/core/simplicialcomplex.py index 61980992..09885251 100644 --- a/xgi/core/simplicialcomplex.py +++ b/xgi/core/simplicialcomplex.py @@ -745,12 +745,12 @@ def remove_simplex_id(self, id): remove_edges_from : remove a collection of edges """ try: - # remove all simplices that contain simplex + # Remove all simplices that contain the given simplex supfaces_ids = self._supfaces_id(self._edge[id]) for sup_id in supfaces_ids: self._remove_simplex_id(sup_id) - # remove simplex + # Remove simplex itself self._remove_simplex_id(id) except KeyError as e: @@ -775,7 +775,10 @@ def remove_simplex_ids_from(self, ebunch): remove_simplex_id : remove a single simplex by ID. """ + all_ids = set(self._edge.keys()) for id in ebunch: + if id in all_ids and id not in self._edge.keys(): + continue self.remove_simplex_id(id) def has_simplex(self, simplex):