Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sparse matrix interactions in sq.gr.utils. #891

Merged
merged 7 commits into from
Oct 14, 2024
11 changes: 10 additions & 1 deletion src/squidpy/gr/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, SparseCSCView, SparseCSRView
alam-shahul marked this conversation as resolved.
Show resolved Hide resolved
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
Expand All @@ -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.0rc1")
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
else:
from anndata._core.views import ArrayView, SparseCSCView, SparseCSRView


def _check_tuple_needles(
needles: Sequence[tuple[Any, Any]],
Expand Down
Loading