scverse / scanpy

Single-cell analysis in Python. Scales to >1M cells.
https://scanpy.readthedocs.io
BSD 3-Clause "New" or "Revised" License
1.92k stars 602 forks source link

Scipy getnnz deprecation? #2773

Open gjhuizing opened 11 months ago

gjhuizing commented 11 months ago

Please make sure these conditions are met

What happened?

Hi!

My recent PR (https://github.com/scverse/scanpy/pull/2772) made me realize that .getnnz(axis=xx) is used in several places in the codebase.

From the Scipy docs for sparse arrays:

Deprecated since version 1.11.0: This method will be removed in SciPy 1.13.0. Use X.nnz instead. The axis argument will no longer be supported; please let us know if you still need this functionality.

From what I understand, sparse matrices should be fine. Can we assume that an AnnData contains a sparse matrix and not a sparse array? If not, it may be good to do one or more of the following:

Best,

GJ

(edited because I originally confused csr_array and csr_matrix)

Minimal code sample

N/A

Error output

No response

Versions

``` latest ```
flying-sheep commented 11 months ago

We only support matrices so far, and as far as I know, only one spot uses the axis parameter. And we can support this use case in a different way.

the use case is a fast conversion from nearest neighbors csr_matrix to a pair of index/distance matrices. an alternative implementation is something like

-if is_constant(nns.getnnz(axis=1)):
+if is_constant(np.diff(nns.indptr)):

or so.