Skip to content

Commit c1f5350

Browse files
authored
fix: support umap-learn 0.6 (#4480)
1 parent a0f08da commit c1f5350

4 files changed

Lines changed: 20 additions & 3 deletions

File tree

‎docs/release-notes/4480.fix.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix {func}`~scanpy.pp.neighbors` and {func}`~scanpy.tl.ingest` with `umap-learn` 0.6 {smaller}`P Angerer`

‎src/scanpy/neighbors/_connectivity.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,9 @@ def umap(
129129
n_neighbors,
130130
None,
131131
None,
132-
knn_indices=knn_indices,
133-
knn_dists=knn_dists,
132+
# umap ≥0.6 requires C-contiguous arrays
133+
knn_indices=np.ascontiguousarray(knn_indices),
134+
knn_dists=np.ascontiguousarray(knn_dists),
134135
set_op_mix_ratio=set_op_mix_ratio,
135136
local_connectivity=local_connectivity,
136137
)

‎src/scanpy/tools/_ingest.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import contextlib
44
from collections.abc import MutableMapping
5+
from inspect import signature
56
from typing import TYPE_CHECKING
67

78
import numpy as np
@@ -238,7 +239,14 @@ def _init_umap(self, adata: AnnData, keys: _EmbeddingKeys) -> None:
238239
from umap import UMAP
239240

240241
rng = self._get_rng(adata.uns[keys.uns]["params"])
242+
# we replicate the legacy (0.5.x) transform pipeline below
243+
compat = (
244+
dict(compatibility_layout=True)
245+
if "compatibility_layout" in signature(UMAP).parameters
246+
else {}
247+
)
241248
self._umap = UMAP(
249+
**compat,
242250
metric=self._metric,
243251
random_state=_legacy_random_state(rng),
244252
# umap can’t be run in parallel with `random_state is not None`

‎tests/test_ingest.py‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
from inspect import signature
34
from typing import TYPE_CHECKING
45

56
import anndata
@@ -215,7 +216,13 @@ def test_ingest_map_embedding_umap() -> None:
215216
ing.fit(adata_new)
216217
ing.map_embedding(method="umap")
217218

218-
reducer = UMAP(min_dist=0.5, random_state=0, n_neighbors=4, n_jobs=1)
219+
# ingest replicates the legacy (0.5.x) pipeline
220+
compat = (
221+
dict(compatibility_layout=True)
222+
if "compatibility_layout" in signature(UMAP).parameters
223+
else {}
224+
)
225+
reducer = UMAP(min_dist=0.5, random_state=0, n_neighbors=4, n_jobs=1, **compat)
219226
reducer.fit(X)
220227
umap_transformed_t = reducer.transform(T)
221228

0 commit comments

Comments
 (0)