Open
Description
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
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 theformat
attribute everywhere and not useisinstance
at all - Use
isinstance
on private compatibility class defined to bescipy.sparse.spmatrix
orscipy.sparse.sparray
conditionally on SciPy's version (i.e. usescipy.sparse.sparray
if available) - Rely on duck-typing or the class name to check for sparse arrays
cc @ivirshup