Skip to content

Commit

Permalink
Backport PR #2271: Add support for AnnData 0.10.0 (#2278)
Browse files Browse the repository at this point in the history
  • Loading branch information
martinkim0 authored Oct 9, 2023
1 parent a210867 commit 68f8863
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 6 deletions.
6 changes: 6 additions & 0 deletions docs/release_notes/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ is available in the [commit logs](https://github.com/YosefLab/scvi-tools/commits

## Version 1.0

### 1.0.4 (2023-10-xx)

### Added

- Add support for AnnData 0.10.0 {pr}`2271`.

### 1.0.3 (2023-08-13)

### Changed
Expand Down
10 changes: 9 additions & 1 deletion scvi/data/_anntorchdataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@
import h5py
import numpy as np
import pandas as pd
from anndata._core.sparse_dataset import SparseDataset

try:
from anndata._core.sparse_dataset import SparseDataset
except ImportError:
# anndata >= 0.10.0
from anndata._core.sparse_dataset import (
BaseCompressedSparseDataset as SparseDataset,
)

from scipy.sparse import issparse
from torch.utils.data import Dataset

Expand Down
6 changes: 3 additions & 3 deletions scvi/data/_built_in_data/_synthetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,16 @@ def _generate_synthetic(
labels = np.random.randint(0, n_labels, size=(n_obs,))
labels = np.array([f"label_{i}" for i in labels])

adata = AnnData(rna, dtype=np.float32)
adata = AnnData(rna)
if return_mudata:
mod_dict = {rna_key: adata}

if n_proteins > 0:
protein_adata = AnnData(protein, dtype=np.float32)
protein_adata = AnnData(protein)
protein_adata.var_names = protein_names
mod_dict[protein_expression_key] = protein_adata
if n_regions > 0:
mod_dict[accessibility_key] = AnnData(accessibility, dtype=np.float32)
mod_dict[accessibility_key] = AnnData(accessibility)

adata = MuData(mod_dict)
else:
Expand Down
9 changes: 8 additions & 1 deletion scvi/data/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@
import pandas as pd
import scipy.sparse as sp_sparse
from anndata import AnnData
from anndata._core.sparse_dataset import SparseDataset

try:
from anndata._core.sparse_dataset import SparseDataset
except ImportError:
# anndata >= 0.10.0
from anndata._core.sparse_dataset import (
BaseCompressedSparseDataset as SparseDataset,
)

# TODO use the experimental api once we lower bound to anndata 0.8
try:
Expand Down
2 changes: 1 addition & 1 deletion scvi/model/base/_archesmixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def prepare_query_anndata(

if inplace:
if adata_out is not adata:
adata._init_as_actual(adata_out, dtype=adata._X.dtype)
adata._init_as_actual(adata_out)
else:
return adata_out

Expand Down

0 comments on commit 68f8863

Please sign in to comment.