From 921fccaca86ce86974ad91348498991714452bc6 Mon Sep 17 00:00:00 2001 From: Isaac Virshup Date: Sat, 23 Mar 2024 00:32:24 +1100 Subject: [PATCH] Fix paga (#2943) * Stop reporting durations * Fix compatibility with scipy 1.13 * release note --- .azure-pipelines.yml | 2 +- docs/release-notes/1.10.0.md | 1 + scanpy/_utils/__init__.py | 19 ------------------- scanpy/tools/_paga.py | 8 ++++---- 4 files changed, 6 insertions(+), 24 deletions(-) diff --git a/.azure-pipelines.yml b/.azure-pipelines.yml index 009b1b5d8b..c1b928c9f0 100644 --- a/.azure-pipelines.yml +++ b/.azure-pipelines.yml @@ -4,7 +4,7 @@ trigger: variables: python.version: '3.12' - PYTEST_ADDOPTS: '-v --color=yes --durations=0 --nunit-xml=test-data/test-results.xml' + PYTEST_ADDOPTS: '-v --color=yes --nunit-xml=test-data/test-results.xml' TEST_EXTRA: 'test-full' DEPENDENCIES_VERSION: "latest" # |"pre-release" | "minimum-version" TEST_TYPE: "standard" # | "coverage" diff --git a/docs/release-notes/1.10.0.md b/docs/release-notes/1.10.0.md index d1d83b3420..fab39ca94f 100644 --- a/docs/release-notes/1.10.0.md +++ b/docs/release-notes/1.10.0.md @@ -48,6 +48,7 @@ * Fix warnings caused by internal usage of `pandas.DataFrame.stack` with `pandas>=2.1` {pr}`2864`{smaller}`I Virshup` * {func}`scanpy.get.aggregate` now always returns {class}`numpy.ndarray` {pr}`2893` {smaller}`S Dicks` * Removes self from array of neighbors for `use_approx_neighbors = True` in {func}`~scanpy.pp.scrublet` {pr}`2896`{smaller}`S Dicks` +* Compatibility with scipy 1.13 {pr}`2943` {smaller}`I Virshup` diff --git a/scanpy/_utils/__init__.py b/scanpy/_utils/__init__.py index 8511465eab..a2254ad0cd 100644 --- a/scanpy/_utils/__init__.py +++ b/scanpy/_utils/__init__.py @@ -271,25 +271,6 @@ def get_igraph_from_adjacency(adjacency, directed=None): return g -def get_sparse_from_igraph(graph, weight_attr=None): - from scipy.sparse import csr_matrix - - edges = graph.get_edgelist() - if weight_attr is None: - weights = [1] * len(edges) - else: - weights = graph.es[weight_attr] - if not graph.is_directed(): - edges.extend([(v, u) for u, v in edges]) - weights.extend(weights) - shape = graph.vcount() - shape = (shape, shape) - if len(edges) > 0: - return csr_matrix((weights, zip(*edges)), shape=shape) - else: - return csr_matrix(shape) - - # -------------------------------------------------------------------------------- # Group stuff # -------------------------------------------------------------------------------- diff --git a/scanpy/tools/_paga.py b/scanpy/tools/_paga.py index 6f513a22b5..b8c1d66c99 100644 --- a/scanpy/tools/_paga.py +++ b/scanpy/tools/_paga.py @@ -186,7 +186,7 @@ def _compute_connectivities_v1_2(self): n = sum(ns) es_inner_cluster = [vc.subgraph(i).ecount() for i in range(len(ns))] cg = vc.cluster_graph(combine_edges="sum") - inter_es = _utils.get_sparse_from_igraph(cg, weight_attr="weight") + inter_es = cg.get_adjacency_sparse(attribute="weight") es = np.array(es_inner_cluster) + inter_es.sum(axis=1).A1 inter_es = inter_es + inter_es.T # \epsilon_i + \epsilon_j connectivities = inter_es.copy() @@ -220,7 +220,7 @@ def _compute_connectivities_v1_0(self): ) ns = vc.sizes() cg = vc.cluster_graph(combine_edges="sum") - inter_es = _utils.get_sparse_from_igraph(cg, weight_attr="weight") / 2 + inter_es = cg.get_adjacency_sparse(attribute="weight") / 2 connectivities = inter_es.copy() inter_es = inter_es.tocoo() n_neighbors_sq = self._neighbors.n_neighbors**2 @@ -301,7 +301,7 @@ def compute_transitions(self): ) # set combine_edges to False if you want self loops cg_full = vc.cluster_graph(combine_edges="sum") - transitions = _utils.get_sparse_from_igraph(cg_full, weight_attr="weight") + transitions = cg_full.get_adjacency_sparse(attribute="weight") transitions = transitions - transitions.T transitions_conf = transitions.copy() transitions = transitions.tocoo() @@ -343,7 +343,7 @@ def compute_transitions_old(self): g_bool, membership=self._adata.obs[self._groups_key].cat.codes.values ) cg_bool = vc_bool.cluster_graph(combine_edges="sum") # collapsed version - transitions = _utils.get_sparse_from_igraph(cg_bool, weight_attr="weight") + transitions = cg_bool.get_adjacency_sparse(attribute="weight") total_n = self._neighbors.n_neighbors * np.array(vc_bool.sizes()) transitions_ttest = transitions.copy() transitions_confidence = transitions.copy()