Skip to content

Commit

Permalink
fix #580 + related test (#581)
Browse files Browse the repository at this point in the history
* fix #580 + related tests

* fix: changed logic to modify only remove_simplex_ids_from

* fix test: edgelist2 -> edgelist4

Co-authored-by: Maxime Lucas <[email protected]>

* fix test: edgelist2 -> edgelist4

Co-authored-by: Maxime Lucas <[email protected]>

* fix: restored original call in remove_simplex_is

---------

Co-authored-by: Maxime Lucas <[email protected]>
  • Loading branch information
thomasrobiglio and maximelucas authored Sep 9, 2024
1 parent 5ff749e commit 4d26fc8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
8 changes: 7 additions & 1 deletion tests/core/test_simplicialcomplex.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
Expand Down
7 changes: 5 additions & 2 deletions xgi/core/simplicialcomplex.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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):
Expand Down

0 comments on commit 4d26fc8

Please sign in to comment.