Convert from networkx without the scipy detour - #600
Open
eriknw wants to merge 4 commits into
Open
Conversation
eriknw
marked this pull request as ready for review
August 4, 2026 16:07
eriknw
force-pushed
the
20-networkx-ingestion
branch
from
August 4, 2026 16:12
89c3e75 to
5f347b7
Compare
eriknw
force-pushed
the
20-networkx-ingestion
branch
2 times, most recently
from
August 5, 2026 03:18
b339cb8 to
d088e70
Compare
eriknw
force-pushed
the
20-networkx-ingestion
branch
from
August 5, 2026 17:44
d088e70 to
3e0c056
Compare
eriknw
force-pushed
the
20-networkx-ingestion
branch
from
August 5, 2026 18:03
3e0c056 to
14e68f5
Compare
eriknw
force-pushed
the
20-networkx-ingestion
branch
from
August 5, 2026 18:05
14e68f5 to
a6e6e62
Compare
eriknw
force-pushed
the
20-networkx-ingestion
branch
from
August 6, 2026 07:59
a6e6e62 to
2901f07
Compare
eriknw
force-pushed
the
20-networkx-ingestion
branch
from
August 6, 2026 15:39
2901f07 to
5839782
Compare
eriknw
force-pushed
the
20-networkx-ingestion
branch
from
August 6, 2026 15:41
5839782 to
9ed5084
Compare
eriknw
force-pushed
the
20-networkx-ingestion
branch
from
August 6, 2026 20:36
9ed5084 to
4dc2ee7
Compare
eriknw
force-pushed
the
20-networkx-ingestion
branch
from
August 6, 2026 20:42
4dc2ee7 to
6ad41be
Compare
eriknw
force-pushed
the
20-networkx-ingestion
branch
from
August 7, 2026 02:48
6ad41be to
7e083a0
Compare
from_networkx always routed nx -> scipy CSR -> Matrix, so every conversion paid for scipy.sparse (importing it alone costs over 100ms) plus an extra coo -> csr materialization. Simple graphs with numeric weights now build COO arrays straight from the nx adjacency and call Matrix.from_coo. The node selection preamble mirrors nx.to_scipy_sparse_array so ordering, subsetting, and error behavior match exactly; undirected graphs are symmetrized with the same diagonal correction nx uses (self-loop entries appear as wt + wt - wt under dup_op=plus, which is exact in IEEE arithmetic). Kept on the scipy fallback automatically: multigraphs (scipy's duplicate-coordinate summation matches exactly) and weights that do not form a 1-D numeric array. That second condition covers non-numeric attributes, including all-string weights, which infer a <U dtype rather than object; the fallback raises the identical ValueError. It also covers array-valued weights: sequence attributes of uniform length infer a 2-D numeric array, which passes a dtype-kind test but which from_coo would read as a UDT, so they keep raising ValueError as before rather than quietly widening what from_networkx accepts. graphblas without scipy installed can now convert simple graphs (previously ImportError); multigraphs still need scipy.
A networkx multigraph fell back to scipy in from_networkx because the direct path could not sum the weights of parallel edges. The directed branch now passes dup_op=plus when the graph is a multigraph, so parallel edges accumulate exactly as scipy's coo -> csr summation does. Simple graphs keep dup_op=None and are unchanged, and the undirected branch already summed because it uses plus for the self-loop diagonal correction. Numeric multigraphs no longer need scipy at all; non-numeric weights still defer to it. Parity with the retained scipy path holds for MultiGraph and MultiDiGraph with parallel edges, parallel self-loops, reciprocal parallel edges, parallel edges whose weights cancel to zero (both sides keep the explicit zero), absent weight attributes (nx defaults to 1), weight=None, bool and int weights, and nodelist permutations and subsets. New tests pin the multigraph diagonal sum and assert the numeric path never reaches the scipy fallback.
eriknw
force-pushed
the
20-networkx-ingestion
branch
from
August 7, 2026 05:09
7e083a0 to
29c4957
Compare
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.
from_networkx routed every conversion through scipy CSR, paying the
scipy.sparse import (over 100ms) plus an extra coo to csr materialization.
It now builds COO arrays straight from the networkx adjacency and calls
Matrix.from_coo.
preamble mirrors nx.to_scipy_sparse_array, so ordering, subsetting, and
error behavior match exactly; undirected graphs symmetrize with the same
diagonal correction nx uses. Non-numeric and array-valued weights keep
the scipy fallback and its identical errors. graphblas without scipy
installed can now convert simple graphs (previously ImportError).
parallel edges accumulate exactly as scipy's coo to csr summation does.
Numeric multigraphs no longer need scipy at all; non-numeric weights
still defer to it.
Parity with the retained scipy path is pinned by tests over parallel edges,
parallel self-loops, reciprocal parallel edges, weights that cancel to zero,
absent weight attributes, weight=None, bool and int weights, and nodelist
permutations and subsets.
Stack created with GitHub Stacks CLI • Give Feedback 💬