Skip to content

Commit

Permalink
Fix sparse matrix interactions in sq.gr.utils. (#891)
Browse files Browse the repository at this point in the history
* Fix sparse matrix interactions in `sq.gr.utils`.

Made to be compatible with new `anndata` release.

* Make import depend on `anndata` version.

* Fix logic for `anndata` import.

Remove high `anndata` pin.

* Make comparison version correct.
  • Loading branch information
alam-shahul authored Oct 14, 2024
1 parent 8cfd4ba commit 80621fc
Showing 1 changed file with 10 additions and 1 deletion.
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
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

0 comments on commit 80621fc

Please sign in to comment.