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 HITS raise exceptions consistent with power iterations #7084

Merged
merged 1 commit into from Nov 5, 2023

Conversation

eriknw
Copy link
Contributor

@eriknw eriknw commented Nov 2, 2023

Specifically, instead of raising ValueError or sp.sparse.linalg.ArpackNoConvergence, change nx.hits to raise nx.PowerIterationFailedConvergence just like other algorithms that have power iterations. This makes it easier for backends to raise consistent exceptions (ArpackNoConvergence is particularly awkward to match).

Specifically, instead of raising `ValueError` or `sp.sparse.linalg.ArpackNoConvergence`,
change `nx.hits` to raise `nx.PowerIterationFailedConvergence` just like other algorithms
that have power iterations. This makes it easier for backends to raise consistent exceptions
(`ArpackNoConvergence` is particularly awkward to match).
Copy link
Member

@dschult dschult left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me! Thanks!

@MridulS
Copy link
Member

MridulS commented Nov 2, 2023

This is an API change. Should we do the deprecation workflow?

@eriknw
Copy link
Contributor Author

eriknw commented Nov 4, 2023

No opinion from me, but I think you're right it is technically an API change. What's the networkx deprecation mechanism for this? Raise a warning and/or put a notice in the docstring that the exceptions will change?

@rossbar
Copy link
Contributor

rossbar commented Nov 4, 2023

This is an API change. Should we do the deprecation workflow?

I'm inclined to see if we can get away without one. AFAICT this will only burn folks that are explicitly catching sp.sparse.linalg.ArpackNoConvergence errors.

Comment on lines +82 to +83
if max_iter <= 0:
raise nx.PowerIterationFailedConvergence(max_iter)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a nit, but I think a ValueError may be better here. "Practicality over Purity" though, so if this is a huge pain for backends then not a blocker!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PowerIterationFailedConvergence was chosen here to match pagerank, eigenvector_centrality, and katz_centrality. I agree ValueError can make sense (esp. for max_iter < 0), but I would want to update the other algorithms too.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for consistency then, thanks!

@rossbar rossbar merged commit 1e5933d into networkx:main Nov 5, 2023
38 of 39 checks passed
@jarrodmillman jarrodmillman added this to the 3.3 milestone Nov 5, 2023
cvanelteren pushed a commit to cvanelteren/networkx that referenced this pull request Apr 22, 2024
…#7084)

Specifically, instead of raising `ValueError` or `sp.sparse.linalg.ArpackNoConvergence`,
change `nx.hits` to raise `nx.PowerIterationFailedConvergence` just like other algorithms
that have power iterations. This makes it easier for backends to raise consistent exceptions
(`ArpackNoConvergence` is particularly awkward to match).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

None yet

5 participants