Skip to content

RFC Supporting scipy.sparse.sparray #26418

Open
@jjerphan

Description

@jjerphan

Context

SciPy is now favoring sparse arrays (i.e. scipy.sparse.sparray and its subclasses) over sparse matrices (i.e. scipy.sparse.spmatrix and its subclasses) to enlarge the scope of matrices to $n$-dimensional data-structures since SciPy 1.8 (see scipy/scipy#14822).

Sparse matrices now subclass their associated sparse arrays (see scipy/scipy#18440).

scikit-learn has been supporting sparse matrices but now also needs to support SciPy sparse arrays.

Proposed solutions

Ordered by preference:

  • Use scipy.sparse.issparse and the format attribute everywhere and not use isinstance at all
  • Use isinstance on private compatibility class defined to be scipy.sparse.spmatrix or scipy.sparse.sparray conditionally on SciPy's version (i.e. use scipy.sparse.sparray if available)
  • Rely on duck-typing or the class name to check for sparse arrays

cc @ivirshup

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions