Skip to content

Graph.Weighted_Adjacency (and friends) don’t support scipy.sparse.sparrays #886

Description

@flying-sheep

Describe the bug
See title. We’re about to change everything to that API, since it’s very mature at this point. And generally also very well-supported, which is why this surprised me!

To reproduce

import igraph
import scipy.sparse

igraph.Graph.Weighted_Adjacency(scipy.sparse.random_array((50, 50)))
TypeError                                 Traceback (most recent call last)
Cell In[3], line 4
      1 import igraph
      2 import scipy.sparse
----> 4 igraph.Graph.Weighted_Adjacency(scipy.sparse.random_array((50, 50)))

File /usr/lib/python3.14/site-packages/igraph/io/adjacency.py:148, in _construct_graph_from_weighted_adjacency(cls, matrix, mode, attr, loops)
    145 if (np is not None) and isinstance(matrix, np.ndarray):
    146     matrix = matrix.tolist()
--> 148 graph, weights = super(Graph, cls)._Weighted_Adjacency(
    149     matrix,
    150     mode=mode,
    151     loops=loops,
    152 )
    153 graph.es[attr] = weights
    155 # Add vertex names if present

File /usr/lib/python3.14/site-packages/scipy/sparse/_base.py:448, in _spbase.__len__(self)
    447 def __len__(self):
--> 448     raise TypeError("sparse array length is ambiguous; use getnnz()"
    449                     " or shape[0]")

TypeError: sparse array length is ambiguous; use getnnz() or shape[0]

Version information
1.0.0

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions