diff --git a/benchmarks/benchmarks/preprocessing_counts.py b/benchmarks/benchmarks/preprocessing_counts.py index 5c5114d902..99a7ef0b53 100644 --- a/benchmarks/benchmarks/preprocessing_counts.py +++ b/benchmarks/benchmarks/preprocessing_counts.py @@ -25,7 +25,6 @@ def cache_adata(dataset: Dataset, layer: KeyCount) -> None: - """Without this caching, asv was running several processes which meant the data was repeatedly downloaded.""" adata, batch_key = get_count_dataset(dataset, layer=layer) assert "lop1p" not in adata.uns adata.uns["batch_key"] = batch_key @@ -40,6 +39,7 @@ class PreprocessingCountsSuite: # noqa: D101 param_names = ("dataset", "layer") def setup_cache(self) -> None: + """Without this caching, asv was running several processes which meant the data was repeatedly downloaded.""" for dataset, layer in product(*self.params): cache_adata(dataset, layer) diff --git a/benchmarks/benchmarks/tools.py b/benchmarks/benchmarks/tools.py index 1d7e66e18b..41563293bb 100644 --- a/benchmarks/benchmarks/tools.py +++ b/benchmarks/benchmarks/tools.py @@ -5,6 +5,8 @@ from __future__ import annotations +from pathlib import Path + import anndata as ad import scanpy as sc @@ -13,42 +15,44 @@ class ToolsSuite: # noqa: D101 - def setup_cache(self) -> None: + def setup_cache(self) -> Path: adata = pbmc68k_reduced() assert "X_pca" in adata.obsm - adata.write_h5ad("adata.h5ad") + adata.write_h5ad(path := Path("adata.h5ad")) + # we need to have a parameter, else asv doesn’t run `setup_cache` before `setup` + return path - def setup(self) -> None: - self.adata = ad.read_h5ad("adata.h5ad") + def setup(self, path: Path) -> None: + self.adata = ad.read_h5ad(path) - def time_umap(self) -> None: + def time_umap(self, *_) -> None: sc.tl.umap(self.adata, rng=None) - def peakmem_umap(self) -> None: + def peakmem_umap(self, *_) -> None: sc.tl.umap(self.adata, rng=None) - def time_diffmap(self) -> None: + def time_diffmap(self, *_) -> None: sc.tl.diffmap(self.adata) - def peakmem_diffmap(self) -> None: + def peakmem_diffmap(self, *_) -> None: sc.tl.diffmap(self.adata) - def time_leiden(self) -> None: + def time_leiden(self, *_) -> None: sc.tl.leiden(self.adata, flavor="igraph") - def peakmem_leiden(self) -> None: + def peakmem_leiden(self, *_) -> None: sc.tl.leiden(self.adata, flavor="igraph") - def time_rank_genes_groups(self) -> None: + def time_rank_genes_groups(self, *_) -> None: sc.tl.rank_genes_groups(self.adata, "bulk_labels", method="wilcoxon") - def peakmem_rank_genes_groups(self) -> None: + def peakmem_rank_genes_groups(self, *_) -> None: sc.tl.rank_genes_groups(self.adata, "bulk_labels", method="wilcoxon") - def time_combat(self) -> None: + def time_combat(self, *_) -> None: sc.pp.combat(self.adata, key="bulk_labels") - def peakmem_combat(self) -> None: + def peakmem_combat(self, *_) -> None: sc.pp.combat(self.adata, key="bulk_labels")