From 387795b81b3d3d9e1c8ca9721100976c26f624f5 Mon Sep 17 00:00:00 2001 From: Shahul Alam Date: Mon, 23 Sep 2024 03:39:37 -0400 Subject: [PATCH 1/4] Fix sparse matrix interactions in `sq.gr.utils`. Made to be compatible with new `anndata` release. --- pyproject.toml | 2 +- src/squidpy/gr/_utils.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 8cc85ffd..494a0a0c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -47,7 +47,7 @@ maintainers = [ dependencies = [ "aiohttp>=3.8.1", - "anndata>=0.9", + "anndata>=0.11.0rc1", "cycler>=0.11.0", "dask-image>=0.5.0", "dask[array]>=2021.02.0", diff --git a/src/squidpy/gr/_utils.py b/src/squidpy/gr/_utils.py index f9f72e24..74f1c64d 100644 --- a/src/squidpy/gr/_utils.py +++ b/src/squidpy/gr/_utils.py @@ -9,7 +9,7 @@ import numpy as np import pandas as pd from anndata import AnnData -from anndata._core.views import ArrayView, SparseCSCView, SparseCSRView +from anndata._core.views import ArrayView, SparseCSCMatrixView, SparseCSRMatrixView from anndata.utils import make_index_unique from pandas import CategoricalDtype from pandas.api.types import infer_dtype @@ -233,7 +233,7 @@ def _extract_expression( # handle views if isinstance(res, ArrayView): return np.asarray(res), genes - if isinstance(res, (SparseCSRView, SparseCSCView)): + if isinstance(res, (SparseCSRMatrixView, SparseCSCMatrixView)): mro = type(res).mro() if csr_matrix in mro: return csr_matrix(res), genes From dff6eb1f1899ec55c925467ac758c34c2ef88fea Mon Sep 17 00:00:00 2001 From: Shahul Alam Date: Wed, 9 Oct 2024 23:25:17 -0400 Subject: [PATCH 2/4] Make import depend on `anndata` version. --- src/squidpy/gr/_utils.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/squidpy/gr/_utils.py b/src/squidpy/gr/_utils.py index 74f1c64d..ac334f42 100644 --- a/src/squidpy/gr/_utils.py +++ b/src/squidpy/gr/_utils.py @@ -6,11 +6,12 @@ from contextlib import contextmanager from typing import TYPE_CHECKING, Any +import anndata import numpy as np import pandas as pd from anndata import AnnData -from anndata._core.views import ArrayView, SparseCSCMatrixView, SparseCSRMatrixView from anndata.utils import make_index_unique +from packaging.version import Version from pandas import CategoricalDtype from pandas.api.types import infer_dtype from scanpy import logging as logg @@ -19,6 +20,14 @@ from squidpy._docs import d from squidpy._utils import NDArrayA, _unique_order_preserving +CAN_USE_SPARSE_ARRAY = Version(anndata.__version__) >= Version("0.11.0") +if not CAN_USE_SPARSE_ARRAY: + from anndata._core.views import ArrayView + from anndata._core.views import SparseCSCMatrixView as SparseCSCView + from anndata._core.views import SparseCSRMatrixView as SparseCSRView +else: + from anndata._core.views import ArrayView, SparseCSCView, SparseCSRView + def _check_tuple_needles( needles: Sequence[tuple[Any, Any]], @@ -233,7 +242,7 @@ def _extract_expression( # handle views if isinstance(res, ArrayView): return np.asarray(res), genes - if isinstance(res, (SparseCSRMatrixView, SparseCSCMatrixView)): + if isinstance(res, (SparseCSRView, SparseCSCView)): mro = type(res).mro() if csr_matrix in mro: return csr_matrix(res), genes From 24940cc21fe468771edc67a23a5e233beb5e32d0 Mon Sep 17 00:00:00 2001 From: Shahul Alam Date: Thu, 10 Oct 2024 12:08:18 -0400 Subject: [PATCH 3/4] Fix logic for `anndata` import. Remove high `anndata` pin. --- pyproject.toml | 2 +- src/squidpy/gr/_utils.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 494a0a0c..8cc85ffd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -47,7 +47,7 @@ maintainers = [ dependencies = [ "aiohttp>=3.8.1", - "anndata>=0.11.0rc1", + "anndata>=0.9", "cycler>=0.11.0", "dask-image>=0.5.0", "dask[array]>=2021.02.0", diff --git a/src/squidpy/gr/_utils.py b/src/squidpy/gr/_utils.py index ac334f42..5040d192 100644 --- a/src/squidpy/gr/_utils.py +++ b/src/squidpy/gr/_utils.py @@ -21,7 +21,7 @@ from squidpy._utils import NDArrayA, _unique_order_preserving CAN_USE_SPARSE_ARRAY = Version(anndata.__version__) >= Version("0.11.0") -if not CAN_USE_SPARSE_ARRAY: +if CAN_USE_SPARSE_ARRAY: from anndata._core.views import ArrayView from anndata._core.views import SparseCSCMatrixView as SparseCSCView from anndata._core.views import SparseCSRMatrixView as SparseCSRView From 0e72ea507544295dff73aa48e1e2b3e1739cf132 Mon Sep 17 00:00:00 2001 From: Shahul Alam Date: Fri, 11 Oct 2024 02:40:42 -0400 Subject: [PATCH 4/4] Make comparison version correct. --- src/squidpy/gr/_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/squidpy/gr/_utils.py b/src/squidpy/gr/_utils.py index 5040d192..51cf005f 100644 --- a/src/squidpy/gr/_utils.py +++ b/src/squidpy/gr/_utils.py @@ -20,7 +20,7 @@ from squidpy._docs import d from squidpy._utils import NDArrayA, _unique_order_preserving -CAN_USE_SPARSE_ARRAY = Version(anndata.__version__) >= Version("0.11.0") +CAN_USE_SPARSE_ARRAY = Version(anndata.__version__) >= Version("0.11.0rc1") if CAN_USE_SPARSE_ARRAY: from anndata._core.views import ArrayView from anndata._core.views import SparseCSCMatrixView as SparseCSCView