Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/anndata/_core/sparse_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,10 @@ class _CSCDataset(BaseCompressedSparseDataset, abc.CSCDataset):
"""Internal concrete version of :class:`anndata.abc.CSRDataset`."""


abc.CSRDataset.register(_CSRDataset)
abc.CSCDataset.register(_CSCDataset)
Comment on lines +642 to +643
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a deep cut for me - don't these both already inherit from the ABC? I'd like to understand this one. Does it have to do with the multiple inheritance?

from anndata._core.sparse_dataset import _CSRDataset
from anndata.abc import CSRDataset
assert issubclass(_CSRDataset, CSRDataset)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

huh, you’re right.

I must have run into something else then, no idea why I thought that check wasn’t already right.



def sparse_dataset(group: GroupStorageType) -> abc.CSRDataset | abc.CSCDataset:
"""Generates a backed mode-compatible sparse dataset class.

Expand Down
2 changes: 1 addition & 1 deletion src/anndata/compat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import h5py
import numpy as np
import pandas as pd
import scipy
import scipy.sparse
from packaging.version import Version

if TYPE_CHECKING:
Expand Down
5 changes: 3 additions & 2 deletions tests/test_backed_sparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from anndata._core.anndata import AnnData
from anndata._core.sparse_dataset import sparse_dataset
from anndata._io.specs.registry import read_elem_as_dask
from anndata.abc import CSCDataset, CSRDataset
from anndata.compat import CSArray, CSMatrix, DaskArray
from anndata.experimental import read_dispatched
from anndata.tests.helpers import AccessTrackingStore, assert_equal, subset_func
Expand All @@ -27,7 +28,6 @@
from numpy.typing import ArrayLike, NDArray
from pytest_mock import MockerFixture

from anndata.abc import CSCDataset, CSRDataset
from anndata.compat import ZarrGroup

Idx = slice | int | NDArray[np.integer] | NDArray[np.bool_]
Expand Down Expand Up @@ -319,7 +319,7 @@ def test_append_array_cache_bust(tmp_path: Path, diskfmt: Literal["h5ad", "zarr"
)
def test_read_array(
tmp_path: Path,
sparse_format: Callable[[ArrayLike], CSMatrix],
sparse_format: type[CSMatrix],
diskfmt: Literal["h5ad", "zarr"],
subset_func,
subset_func2,
Expand All @@ -334,6 +334,7 @@ def test_read_array(
f = h5py.File(path, "a")
ad.io.write_elem(f, "mtx", a)
diskmtx = sparse_dataset(f["mtx"])
assert isinstance(diskmtx, CSCDataset if a.format == "csc" else CSRDataset)
ad.settings.use_sparse_array_on_read = True
assert issubclass(type(diskmtx[obs_idx, var_idx]), CSArray)
ad.settings.use_sparse_array_on_read = False
Expand Down