diff --git a/anndata/base.py b/anndata/base.py index 8b9cd9ca6..fabdb8c2d 100644 --- a/anndata/base.py +++ b/anndata/base.py @@ -604,7 +604,7 @@ class AnnData(IndexMixin, metaclass=utils.DeprecationMixinMeta): def __init__( self, - X: Optional[Union[np.ndarray, sparse.spmatrix]] = None, + X: Optional[Union[np.ndarray, sparse.spmatrix, ArrayView]] = None, obs: Optional[Union[pd.DataFrame, Mapping[Any, Iterable[Any]], np.ndarray]] = None, var: Optional[Union[pd.DataFrame, Mapping[Any, Iterable[Any]], np.ndarray]] = None, uns: Optional[Mapping[Any, Any]] = None, @@ -868,8 +868,8 @@ def shape(self): return self.n_obs, self.n_vars @property - def X(self) -> Union[np.ndarray, sparse.spmatrix, None]: - """Data matrix of shape `n_obs` × `n_vars` (`np.ndarray`, `sp.sparse.spmatrix`) or `None`.""" + def X(self) -> Optional[Union[np.ndarray, sparse.spmatrix, ArrayView]]: + """Data matrix of shape `n_obs` × `n_vars`.""" if self.isbacked: if not self.file.isopen: self.file.open() X = self.file['X'] diff --git a/anndata/readwrite/write.py b/anndata/readwrite/write.py index 768b27a2b..2768c0e8b 100644 --- a/anndata/readwrite/write.py +++ b/anndata/readwrite/write.py @@ -146,7 +146,7 @@ def preprocess_writing(value): and f[key].shape == value.shape \ and f[key].dtype == value.dtype \ and not isinstance(f[key], h5py.SparseDataset) - if not is_valid_group and not isinstance(value, sparse.spmatrix): + if not is_valid_group and not issparse(value): f[key][()] = value return else: