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

Warn on unknown type of degree assortativity #533

Merged
merged 2 commits into from
Apr 15, 2024
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
6 changes: 6 additions & 0 deletions tests/algorithms/test_assortativity.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ def test_degree_assortativity(edgelist1, edgelist5):
with pytest.raises(XGIError):
xgi.degree_assortativity(H)

# test wrong kind
with pytest.raises(XGIError):
xgi.degree_assortativity(H1, kind="no-idea")
with pytest.raises(XGIError):
xgi.degree_assortativity(H1, kind="no-idea", exact=True)


def test_choose_degrees(edgelist1, edgelist6):
H1 = xgi.Hypergraph(edgelist1)
Expand Down
4 changes: 3 additions & 1 deletion xgi/algorithms/assortativity.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ def degree_assortativity(H, kind="uniform", exact=False, num_samples=1000):
for d in permutations(_choose_degrees(members[e], k, "top-bottom"), 2)
# permutations is so that k1 and k2 have the same variance
]
else:
raise XGIError("Invalid type of degree assortativity!")
else:
edges = [e for e in H.edges if len(H.edges.members(e)) > 1]
k1k2 = [
Expand Down Expand Up @@ -202,6 +204,6 @@ def _choose_degrees(e, k, kind="uniform"):
return sorted([k[i] for i in e])[:: len(e) - 1]

else:
raise XGIError("Invalid choice function!")
raise XGIError("Invalid type of degree assortativity!")
else:
raise XGIError("Edge must have more than one member!")
Loading