diff --git a/tests/test_backed_hdf5.py b/tests/test_backed_hdf5.py index 19b4ca44d..509c91fc1 100644 --- a/tests/test_backed_hdf5.py +++ b/tests/test_backed_hdf5.py @@ -10,7 +10,7 @@ from scipy import sparse import anndata as ad -from anndata.compat import SpArray +from anndata.compat import SpArray, SpMatrix from anndata.tests.helpers import ( GEN_ADATA_DASK_ARGS, as_dense_dask_array, @@ -200,8 +200,8 @@ def test_backed_raw_subset(tmp_path, array_type, subset_func, subset_func2): var_idx = subset_func2(mem_adata.var_names) if ( array_type is asarray - and isinstance(obs_idx, list | np.ndarray | sparse.spmatrix | SpArray) - and isinstance(var_idx, list | np.ndarray | sparse.spmatrix | SpArray) + and isinstance(obs_idx, list | np.ndarray | SpMatrix | SpArray) + and isinstance(var_idx, list | np.ndarray | SpMatrix | SpArray) ): pytest.xfail( "Fancy indexing does not work with multiple arrays on a h5py.Dataset" diff --git a/tests/test_backed_sparse.py b/tests/test_backed_sparse.py index 2778c76bb..f2f023010 100644 --- a/tests/test_backed_sparse.py +++ b/tests/test_backed_sparse.py @@ -13,7 +13,7 @@ import anndata as ad from anndata._core.anndata import AnnData from anndata._core.sparse_dataset import sparse_dataset -from anndata.compat import CAN_USE_SPARSE_ARRAY, SpArray +from anndata.compat import CAN_USE_SPARSE_ARRAY, SpArray, SpMatrix from anndata.experimental import read_dispatched from anndata.tests.helpers import AccessTrackingStore, assert_equal, subset_func @@ -259,8 +259,8 @@ def test_consecutive_bool( ) def test_dataset_append_memory( tmp_path: Path, - sparse_format: Callable[[ArrayLike], sparse.spmatrix], - append_method: Callable[[list[sparse.spmatrix]], sparse.spmatrix], + sparse_format: Callable[[ArrayLike], SpMatrix], + append_method: Callable[[list[SpMatrix]], SpMatrix], diskfmt: Literal["h5ad", "zarr"], ): path = tmp_path / f"test.{diskfmt.replace('ad', '')}" @@ -296,7 +296,7 @@ def test_dataset_append_memory( ) def test_read_array( tmp_path: Path, - sparse_format: Callable[[ArrayLike], sparse.spmatrix], + sparse_format: Callable[[ArrayLike], SpMatrix], diskfmt: Literal["h5ad", "zarr"], subset_func, subset_func2, @@ -316,7 +316,7 @@ def test_read_array( ad.settings.use_sparse_array_on_read = True assert issubclass(type(diskmtx[obs_idx, var_idx]), SpArray) ad.settings.use_sparse_array_on_read = False - assert issubclass(type(diskmtx[obs_idx, var_idx]), sparse.spmatrix) + assert issubclass(type(diskmtx[obs_idx, var_idx]), SpMatrix) @pytest.mark.parametrize( @@ -328,8 +328,8 @@ def test_read_array( ) def test_dataset_append_disk( tmp_path: Path, - sparse_format: Callable[[ArrayLike], sparse.spmatrix], - append_method: Callable[[list[sparse.spmatrix]], sparse.spmatrix], + sparse_format: Callable[[ArrayLike], SpMatrix], + append_method: Callable[[list[SpMatrix]], SpMatrix], diskfmt: Literal["h5ad", "zarr"], ): path = tmp_path / f"test.{diskfmt.replace('ad', '')}" @@ -356,7 +356,7 @@ def test_dataset_append_disk( @pytest.mark.parametrize("sparse_format", [sparse.csr_matrix, sparse.csc_matrix]) def test_indptr_cache( tmp_path: Path, - sparse_format: Callable[[ArrayLike], sparse.spmatrix], + sparse_format: Callable[[ArrayLike], SpMatrix], ): path = tmp_path / "test.zarr" a = sparse_format(sparse.random(10, 10)) @@ -438,7 +438,7 @@ def width_idx_kinds( ) def test_data_access( tmp_path: Path, - sparse_format: Callable[[ArrayLike], sparse.spmatrix], + sparse_format: Callable[[ArrayLike], SpMatrix], idx_maj: Idx, idx_min: Idx, exp: Sequence[str], diff --git a/tests/test_concatenate.py b/tests/test_concatenate.py index d9f399dd6..72b6a89f3 100644 --- a/tests/test_concatenate.py +++ b/tests/test_concatenate.py @@ -20,7 +20,7 @@ from anndata import AnnData, Raw, concat from anndata._core import merge from anndata._core.index import _subset -from anndata.compat import AwkArray, CupySparseMatrix, DaskArray, SpArray +from anndata.compat import AwkArray, CupySparseMatrix, DaskArray, SpArray, SpMatrix from anndata.tests import helpers from anndata.tests.helpers import ( BASE_MATRIX_PARAMS, @@ -61,7 +61,7 @@ def _filled_array(a, fill_value=None): return as_dense_dask_array(_filled_array_np(a, fill_value)) -@filled_like.register(sparse.spmatrix) +@filled_like.register(SpMatrix) def _filled_sparse(a, fill_value=None): if fill_value is None: return sparse.csr_matrix(a.shape) @@ -200,7 +200,7 @@ def test_concatenate_roundtrip(join_type, array_type, concat_func, backwards_com if isinstance(orig.X, SpArray): base_type = SpArray else: - base_type = sparse.spmatrix + base_type = SpMatrix if isinstance(orig.X, CupySparseMatrix): base_type = CupySparseMatrix assert isinstance(result.X, base_type) @@ -404,7 +404,7 @@ def test_concatenate_obsm_outer(obsm_adatas, fill_val): ), ) - assert isinstance(outer.obsm["sparse"], sparse.spmatrix) + assert isinstance(outer.obsm["sparse"], SpMatrix) np.testing.assert_equal( outer.obsm["sparse"].toarray(), np.array( @@ -1496,7 +1496,7 @@ def test_concat_X_dtype(cpu_array_type, sparse_indexer_type): if sparse.issparse(result.X): # See https://github.com/scipy/scipy/issues/20389 for why this doesn't work with csc if sparse_indexer_type == np.int64 and ( - issubclass(cpu_array_type, sparse.spmatrix) or adata.X.format == "csc" + issubclass(cpu_array_type, SpMatrix) or adata.X.format == "csc" ): pytest.xfail( "Data type int64 is not maintained for sparse matrices or csc array" diff --git a/tests/test_concatenate_disk.py b/tests/test_concatenate_disk.py index a05d9a308..9bb8be289 100644 --- a/tests/test_concatenate_disk.py +++ b/tests/test_concatenate_disk.py @@ -30,7 +30,7 @@ pd.DataFrame, ), varm_types=(sparse.csr_matrix, np.ndarray, pd.DataFrame), - layers_types=(sparse.spmatrix, np.ndarray, pd.DataFrame), + layers_types=(sparse.csr_matrix, np.ndarray, pd.DataFrame), ) diff --git a/tests/test_io_conversion.py b/tests/test_io_conversion.py index 217a9cc16..0d0f0196c 100644 --- a/tests/test_io_conversion.py +++ b/tests/test_io_conversion.py @@ -10,6 +10,7 @@ from scipy import sparse import anndata as ad +from anndata.compat import SpMatrix from anndata.tests.helpers import assert_equal, gen_adata @@ -99,8 +100,8 @@ def test_dense_to_sparse_memory(tmp_path, spmtx_format, to_convert): orig = gen_adata((50, 50), np.array) orig.raw = orig.copy() orig.write_h5ad(dense_path) - assert not isinstance(orig.X, sparse.spmatrix) - assert not isinstance(orig.raw.X, sparse.spmatrix) + assert not isinstance(orig.X, SpMatrix) + assert not isinstance(orig.raw.X, SpMatrix) curr = ad.read_h5ad(dense_path, as_sparse=to_convert, as_sparse_fmt=spmtx_format) diff --git a/tests/test_io_dispatched.py b/tests/test_io_dispatched.py index 0bbbf285a..8b142ce79 100644 --- a/tests/test_io_dispatched.py +++ b/tests/test_io_dispatched.py @@ -4,10 +4,9 @@ import h5py import zarr -from scipy import sparse import anndata as ad -from anndata.compat import SpArray +from anndata.compat import SpArray, SpMatrix from anndata.experimental import read_dispatched, write_dispatched from anndata.tests.helpers import assert_equal, gen_adata @@ -96,7 +95,7 @@ def set_copy(d, **kwargs): # TODO: Should the passed path be absolute? path = "/" + store.path + "/" + k if hasattr(elem, "shape") and not isinstance( - elem, sparse.spmatrix | SpArray | ad.AnnData + elem, SpMatrix | SpArray | ad.AnnData ): if re.match(r"^/((X)|(layers)).*", path): chunks = (M, N) diff --git a/tests/test_io_elementwise.py b/tests/test_io_elementwise.py index 3ca5324b8..a33e34850 100644 --- a/tests/test_io_elementwise.py +++ b/tests/test_io_elementwise.py @@ -22,7 +22,13 @@ get_spec, ) from anndata._io.specs.registry import IORegistryError -from anndata.compat import CAN_USE_SPARSE_ARRAY, SpArray, ZarrGroup, _read_attr +from anndata.compat import ( + CAN_USE_SPARSE_ARRAY, + SpArray, + SpMatrix, + ZarrGroup, + _read_attr, +) from anndata.experimental import read_elem_as_dask from anndata.io import read_elem, write_elem from anndata.tests.helpers import ( @@ -220,7 +226,7 @@ def test_io_spec(store, value, encoding_type): @pytest.mark.parametrize("as_dask", [False, True]) def test_io_spec_cupy(store, value, encoding_type, as_dask): if as_dask: - if isinstance(value, sparse.spmatrix): + if isinstance(value, SpMatrix): value = as_cupy_sparse_dask_array(value, format=encoding_type[:3]) else: value = as_dense_cupy_dask_array(value) diff --git a/tests/test_readwrite.py b/tests/test_readwrite.py index 518559995..8a8861a4f 100644 --- a/tests/test_readwrite.py +++ b/tests/test_readwrite.py @@ -15,12 +15,11 @@ import pytest import zarr from numba.core.errors import NumbaDeprecationWarning -from scipy import sparse from scipy.sparse import csc_array, csc_matrix, csr_array, csr_matrix import anndata as ad from anndata._io.specs.registry import IORegistryError -from anndata.compat import DaskArray, SpArray, _read_attr +from anndata.compat import DaskArray, SpArray, SpMatrix, _read_attr from anndata.tests.helpers import as_dense_dask_array, assert_equal, gen_adata from testing.anndata._helpers import xfail_if_numpy2_loompy @@ -161,7 +160,7 @@ def test_readwrite_kitchensink(tmp_path, storage, typ, backing_h5ad, dataset_kwa # since we tested if assigned types and loaded types are DaskArray # this would also work if they work if isinstance(adata_src.raw.X, SpArray): - assert isinstance(adata.raw.X, sparse.spmatrix) + assert isinstance(adata.raw.X, SpMatrix) else: assert isinstance(adata_src.raw.X, type(adata.raw.X) | DaskArray) assert isinstance(