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

ValueError crash in "nx.degree_pearson_correlation_coefficient" when input graph with no edges #6913

Open
joyemang33 opened this issue Sep 7, 2023 · 5 comments · May be fixed by #7392
Open

Comments

@joyemang33
Copy link

joyemang33 commented Sep 7, 2023

Hello! I am so sorry to bother you to investigate again, but I have no idea about this probable issue.
When testing NetworkX with a graph without edges, I found a strange crash in nx.degree_pearson_correlation_coefficient, with the following message:

Exception has occurred: ValueError
File "/home/qiuyang/.local/lib/python3.10/site-packages/networkx/algorithms/assortativity/correlation.py", line 156, in degree_pearson_correlation_coefficient
    x, y = zip(*xy)
ValueError: not enough values to unpack (expected 2, got 0)

The statement that triggers the crash is here.
Since I am not sure whether degree_pearson_correlation_coefficient has a good definition in such graphs, it would be highly appreciated if you could help me further confirm and investigate this issue.
If there is no good definition, maybe we could throw a NetworkX Exception for users instead of the system exception.

Best regard,
Joye

Step to Reproduce

Running the following Python code:

G = nx.DiGraph()
G.add_node(0)
G.add_node(1)
print(nx.degree_pearson_correlation_coefficient(G))

Result:

Exception has occurred: ValueError

Environment

NetworkX 3.1
Python 3.10

@joyemang33
Copy link
Author

After the investigation, I also found a similar issue in networkx.k_components.

Step to Reproduce

import networkx as nx
G = nx.Graph()
G.add_node(0)
G.add_node(1)
print(nx.k_components(G))

Result:

ValueError: max() arg is an empty sequence

Best regards,
Joye

@rossbar
Copy link
Contributor

rossbar commented Sep 7, 2023

Hello! I am so sorry to bother you

No need to apologize @joyemang33 , we very much appreciate the work you're doing by finding & reporting these cases!

Out of curiosity - are you using some sort of "fuzzing" tool or otherwise procedural workflow to find corner-cases?

@joyemang33
Copy link
Author

Hi @rossbar! Thanks for your response. We are trying to develop a fully automated tool for graph libraries, including a fuzzing component to detect such corner cases, as well as a method based on metamorphic testing to detect potential logic issues (i.e., strange results).
I will try my best to reduce and check the test cases before reporting. But it may still cause some burdens of false alarm to you since I can not be an expert on all algorithms here. Thanks again for your kind understanding!

Best regards,
Joye

@dschult
Copy link
Member

dschult commented Sep 8, 2023

This one occurs because there are no edges in the graph... It shouldn't matter how many nodes. So adding a check with nx.is_empty(G) and raising a NetworkXPointlessConcept sounds like a good approach.
Thanks!

@joyemang33
Copy link
Author

joyemang33 commented Sep 8, 2023

Hi @dschult @rossbar @MridulS ! Thanks a lot for your kind review of these corner cases #6913 #6914 #6915 #6916. I will create PRs to fix them one by one in the future, as well as report the remaining cases in one new report.

For #6912, I have no idea about the root cause of the crash. It would be appreciated if you could help me take a look at that :).

Best regards,
Joye

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

3 participants