Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/release-notes/4031.fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{func}`scanpy.tl.umap` no longer silently mutates `adata.obsp['connectivities']` via a shared sparse buffer {smaller}`N Justice`
2 changes: 1 addition & 1 deletion src/scanpy/tools/_umap.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def umap( # noqa: PLR0913, PLR0915
n_epochs = default_epochs if maxiter is None else maxiter
x_umap, _ = simplicial_set_embedding(
data=x,
graph=neighbors["connectivities"].tocoo(),
graph=neighbors["connectivities"].tocoo(copy=True),
n_components=n_components,
initial_alpha=alpha,
a=a,
Expand Down
15 changes: 15 additions & 0 deletions tests/test_embedding.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,21 @@ def test_umap_init_paga(layout):
sc.tl.umap(pbmc, init_pos="paga")


def test_umap_preserves_connectivities():
# https://github.com/scverse/scanpy/issues/4028
pbmc = pbmc68k_reduced()[:100, :].copy()
conn = pbmc.obsp["connectivities"]
data_before = conn.data.copy()
nnz_before = conn.nnz

sc.tl.umap(pbmc)

assert_array_equal(data_before, conn.data)
assert conn.nnz == nnz_before
assert (conn.data == 0).sum() == 0, "CSR should have no explicit zeros"
assert "X_umap" in pbmc.obsm


def test_diffmap():
pbmc = pbmc68k_reduced()

Expand Down
Loading