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

Make IDViews respect order #482

Merged
merged 4 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion tests/core/test_diviews.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,15 @@ def test_view_len(diedgelist2):

def test_bunch_view(diedgelist2):
H = xgi.DiHypergraph(diedgelist2)
bunch_view = H.edges.from_view(H.edges, bunch=[1, 2])
bunch_view = H.edges.from_view(H.edges, bunch=[2, 1])
assert len(bunch_view) == 2
assert (1 in bunch_view) and (2 in bunch_view)
assert 0 not in bunch_view
assert bunch_view.members(dtype=dict) == {1: {1, 2, 4}, 2: {2, 3, 4, 5}}
with pytest.raises(IDNotFound):
bunch_view.members(0)
# test ID order
assert list(bunch_view) == [1, 2]


def test_call_wrong_bunch():
Expand Down
4 changes: 3 additions & 1 deletion tests/core/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,14 +210,16 @@ def test_view_len(edgelist2):

def test_bunch_view(edgelist1):
H = xgi.Hypergraph(edgelist1)
bunch_view = H.edges.from_view(H.edges, bunch=[1, 2])
bunch_view = H.edges.from_view(H.edges, bunch=[2, 1])
assert len(bunch_view) == 2
assert (1 in bunch_view) and (2 in bunch_view)
assert 0 not in bunch_view
assert bunch_view.members(dtype=dict) == {1: {4}, 2: {5, 6}}
with pytest.raises(IDNotFound):
bunch_view.members(0)

assert list(bunch_view) == [1, 2]


def test_call_wrong_bunch():
H = xgi.Hypergraph()
Expand Down
2 changes: 1 addition & 1 deletion xgi/core/diviews.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ def from_view(cls, view, bunch=None):
wrong = bunch - all_ids
if wrong:
raise IDNotFound(f"IDs {wrong} not in the hypergraph")
newview._ids = bunch
newview._ids = [i for i in view._in_id_dict if i in bunch]
return newview

def _from_iterable(self, it):
Expand Down
2 changes: 1 addition & 1 deletion xgi/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ def from_view(cls, view, bunch=None):
wrong = bunch - all_ids
if wrong:
raise IDNotFound(f"IDs {wrong} not in the hypergraph")
newview._ids = bunch
newview._ids = [i for i in view._id_dict if i in bunch]
return newview

def _from_iterable(self, it):
Expand Down
Loading