-
Notifications
You must be signed in to change notification settings - Fork 603
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(feat): raising errors where
backed
is not supported (#3048)
* (feat): first step raising errors where `backed` is not supported * (fix): fix `chunked` with `log1p` * (fix): complications in `log1p` with `chunked` * remove duplicated import * (feat): pca check * (feat): `ingest` check added * (feat): add `dendrogram` test * (feat): add `tsne` check * (feat): `rank_genes_groups` * (feat): `score_genes` check * (chore): add plotting backed tests * (chore): check type instead of `isbacked` * (chore): release note * (fix): string formatting error * (fix): `worker_id` default * (fix): try `SparseDataset` * (fix): correct fixture creation * Apply suggestions from code review Co-authored-by: Philipp A. <[email protected]> * (chore): consolidate tests * (chore): remove erroneous plotting tests * (chore): remove other `tempfile` import * (fix): try moving scanpy install * (fix): `np.Inf` -> `np.inf` * (fix): fail if pynn is newest * (fix): name * (fix): `score_genes` name * revert 88d51ab * session-scoped backed_adata * (fix): move umap import back to top * (fix): try block shape * (fix): revert chunks fix --------- Co-authored-by: Philipp A <[email protected]>
- Loading branch information
1 parent
23c20bc
commit 3ba3f46
Showing
14 changed files
with
229 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
from __future__ import annotations | ||
|
||
from functools import partial | ||
|
||
import pytest | ||
from anndata import read_h5ad | ||
|
||
import scanpy as sc | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("name", "func", "msg"), | ||
[ | ||
pytest.param("PCA", sc.pp.pca, " with chunked as False", id="pca"), | ||
pytest.param( | ||
"PCA", partial(sc.pp.pca, layer="X_copy"), " from layers", id="pca_layer" | ||
), | ||
pytest.param( | ||
"regress_out", | ||
partial(sc.pp.regress_out, keys=["n_counts", "percent_mito"]), | ||
"", | ||
id="regress_out", | ||
), | ||
pytest.param( | ||
"dendrogram", partial(sc.tl.dendrogram, groupby="cat"), "", id="dendrogram" | ||
), | ||
pytest.param("tsne", sc.tl.tsne, "", id="tsne"), | ||
pytest.param("scale", sc.pp.scale, "", id="scale"), | ||
pytest.param( | ||
"downsample_counts", | ||
partial(sc.pp.downsample_counts, counts_per_cell=1000), | ||
"", | ||
id="downsample_counts", | ||
), | ||
pytest.param( | ||
"filter_genes", | ||
partial(sc.pp.filter_genes, max_cells=1000), | ||
"", | ||
id="filter_genes", | ||
), | ||
pytest.param( | ||
"filter_cells", | ||
partial(sc.pp.filter_cells, max_genes=1000), | ||
"", | ||
id="filter_cells", | ||
), | ||
pytest.param( | ||
"rank_genes_groups", | ||
partial(sc.tl.rank_genes_groups, groupby="cat"), | ||
"", | ||
id="rank_genes_groups", | ||
), | ||
pytest.param( | ||
"score_genes", | ||
partial(sc.tl.score_genes, gene_list=map(str, range(100))), | ||
"", | ||
id="score_genes", | ||
), | ||
], | ||
) | ||
def test_backed_error(backed_adata, name, func, msg): | ||
with pytest.raises( | ||
NotImplementedError, | ||
match=f"{name} is not implemented for matrices of type {type(backed_adata.X)}{msg}", | ||
): | ||
func(backed_adata) | ||
|
||
|
||
def test_log1p_backed_errors(backed_adata): | ||
with pytest.raises( | ||
NotImplementedError, | ||
match="log1p is not implemented for backed AnnData with backed mode not r+", | ||
): | ||
sc.pp.log1p(backed_adata, chunked=True) | ||
backed_adata.file.close() | ||
backed_adata = read_h5ad(backed_adata.filename, backed="r+") | ||
with pytest.raises( | ||
NotImplementedError, | ||
match=f"log1p is not implemented for matrices of type {type(backed_adata.X)} without `chunked=True`", | ||
): | ||
sc.pp.log1p(backed_adata) | ||
backed_adata.layers["X_copy"] = backed_adata.X | ||
layer_type = type(backed_adata.layers["X_copy"]) | ||
with pytest.raises( | ||
NotImplementedError, | ||
match=f"log1p is not implemented for matrices of type {layer_type} from layers", | ||
): | ||
sc.pp.log1p(backed_adata, layer="X_copy") | ||
backed_adata.file.close() | ||
|
||
|
||
def test_scatter_backed(backed_adata): | ||
sc.pp.pca(backed_adata, chunked=True) | ||
sc.pl.scatter(backed_adata, color="0", basis="pca") | ||
|
||
|
||
def test_dotplot_backed(backed_adata): | ||
sc.pl.dotplot(backed_adata, ["0", "1", "2", "3"], groupby="cat") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.