Repository navigation
Conversation
A call that reads complex edge values now raises NotImplementedError
in the backend, so that NetworkX answers it or raises its own error.
GraphBLAS has no complex min or max, nor the min_plus semiring, so
shortest paths and the names built on them raised KeyError ("plus does
not work with FC64") where NetworkX raises TypeError; and pagerank,
closeness, harmonic and others answered where NetworkX raises.
The check is in drop_unrequested_values, which every wrapper calls
with the attribute it reads. It tests the matrix's type, which the
conversion inferred from the values, so it needs no pass over the
edges, and it sees every graph a call gets: a conversion made for it,
one NetworkX cached for another call and serves to this one, or a
backend graph given directly. A call that reads no values is still
served, as is a rebuild that carries them (k_core, union, reverse).
edge_boundary with data=True and ego_graph with distance read the
values of a conversion that keeps every attribute, so they now ask
the check by the attribute's name. all_pairs_bellman_ford_path_length
converts on the call rather than when its generator is first read,
where NetworkX could no longer answer instead.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## 20-wiener-efficiency #149 +/- ##
========================================================
+ Coverage 92.88% 92.94% +0.05%
========================================================
Files 182 183 +1
Lines 11227 11406 +179
Branches 1274 1299 +25
========================================================
+ Hits 10428 10601 +173
- Misses 546 549 +3
- Partials 253 256 +3 🚀 New features to boost your workflow:
|
This was referenced Dec 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Leave every call that reads complex edge weights to NetworkX, which answers it or raises its own error. Calls that read no values, and rebuilds that only carry them, are still served.
TypeErroron Python complex weights and on mixes of complex and float. On numpy complex weights some names answer in complex numbers.edge_boundarytwice, withdata="weight"anddata=True), on undirected and directed random graphs, with six kinds of complex weights: Python complex,np.complex64,np.complex128, complex beside floats, one complex among floats, and complex with no imaginary part. Each call went through NetworkX's dispatcher with graphblas first and fallback on. Of 690 calls (678 in NetworkX 3.6.1), 396 differed from NetworkX (394 in 3.6.1):KeyError, in 20 names: the shortest-path names, the eccentricity and Wiener families,clustering,average_clusteringandego_graph. GraphBLAS has no complexminormax, nor themin_plussemiring: the errors read "min does not work with FC64", or "plus does not work with FC64" formin_plus.pagerank,hits,closeness_centrality,harmonic_centrality,average_shortest_path_length,eigenvector_centrality,katz_centrality,google_matrixandharmonic_diameter.np.complex64, for one.drop_unrequested_values. Every wrapper calls it throughto_graph,to_directed_graphorto_undirected_graph, with the attribute it reads.NotImplementedError, and NetworkX tries the next backend: NetworkX itself.k_corekeeps every attribute, and NetworkX serves that conversion to a later weightedpagerank. It also sees a backend graph that was given directly."weight"whatever they are asked (hits,tournament_matrix) pass through it as well.edge_boundary(data=True)andego_graph(distance=...)read values from a conversion that keeps every attribute, so they now also ask by the attribute's name.all_pairs_bellman_ford_path_lengthconverted inside its generator, so a refusal would have reached the caller reading it, where NetworkX can no longer answer instead. It now converts on the call and returns the generator.compose,disjoint_union,union,reverse,k_core,k_corona,k_crust,k_shell,k_truss, andego_graphwithoutdistance. The graph it returns equals NetworkX's, value for value.np.complex64as a Python complex, a float beside a complex as a complex. These are equal values; the existing rule for rebuilds lets a change of type alone through.adjacency_matrixandtournament_matrixmatched NetworkX in every call of the sweep, and a few other names matched for some kinds of weight.modularitymatched for Python complex weights, but with numpy complex weights it gave a Python complex where NetworkX givesnp.complex64(with float32 rounding) ornp.complex128.adjacency_matrix'sdtype).graphblas_algorithms.nxapi) on a NetworkX graph, outside the dispatcher. There the function converts the graph itself, for some names to floats, and is not checked; nothing could answer instead.graphblas_algorithms/tests/test_complex_weights.py):np.complex64, and one complex with no imaginary part among floats, on undirected and directed graphs. Through the dispatcher, with graphblas first and fallback on, the result equals NetworkX's value, within 1e-12 and of the same type, or NetworkX's exception type and message. Called withbackend="graphblas", it raisesNotImplementedError.1.5 + 0.5j, the cached rebuild conversion, a backend graph given directly, and the all-pairs Bellman-Ford refusal on the call.modularitywith complex weights expected the backend's answer, and now expects the call to be declined.Stacked on #121.