Skip to content

sc.pp.scale leads to UserWarning: zero-centering a sparse array/matrix densifies it. #3719

@jpintar

Description

@jpintar

Please make sure these conditions are met

  • I have checked that this issue has not already been reported.
  • I have confirmed this bug exists on the latest version of scanpy.
  • (optional) I have confirmed this bug exists on the main branch of scanpy.

What happened?

Running sc.pp.scale(adata) where adata.X is a csr_matrix leads to

.../functools.py:934: UserWarning: zero-centering a sparse array/matrix densifies it.
  return dispatch(args[0].__class__)(*args, **kw)

Minimal code sample

import scanpy as sc
import anndata as ad
import scipy as sp

adata = ad.AnnData(X=sp.sparse.rand(1000, 1000, format="csr"))
sc.pp.scale(adata)

Error output

Versions

Affects versions 1.11.3 and 1.11.2, but not 1.11.1.

Details
scanpy	1.11.3
anndata	0.12.0
scipy	1.15.3
----	----
PyYAML	6.0.2
typing_extensions	4.14.1
threadpoolctl	3.6.0
six	1.17.0
natsort	8.4.0
legacy-api-wrap	1.4.1
zarr	3.1.0
pandas	2.3.1
donfig	0.8.1.post1
pyparsing	3.2.3
setuptools	80.9.0
kiwisolver	1.4.8
packaging	25.0
joblib	1.5.1
llvmlite	0.44.0
numpy	2.2.6
h5py	3.14.0
scikit-learn	1.7.1
pytz	2025.2
matplotlib	3.10.3
numba	0.61.2
crc32c	2.7.1
cycler	0.12.1
session-info2	0.1.2
numcodecs	0.16.1
python-dateutil	2.9.0.post0
pillow	11.3.0
----	----
Python	3.12.11 | packaged by conda-forge | (main, Jun  4 2025, 14:45:31) [GCC 13.3.0]
OS	Linux-4.18.0-425.19.2.el8_7.x86_64-x86_64-with-glibc2.28

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions