Skip to content

Commit

Permalink
Auto-metric and fix logs (scverse#3186)
Browse files Browse the repository at this point in the history
  • Loading branch information
flying-sheep authored Aug 1, 2024
1 parent 13a3706 commit 3ba0d30
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 12 deletions.
8 changes: 4 additions & 4 deletions src/scanpy/preprocessing/_pca.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,10 +338,10 @@ def pca(
logg.info(" finished", time=logg_start)
logg.debug(
"and added\n"
" 'X_pca', the PCA coordinates (adata.obs)\n"
" 'PC1', 'PC2', ..., the loadings (adata.var)\n"
" 'pca_variance', the variance / eigenvalues (adata.uns)\n"
" 'pca_variance_ratio', the variance ratio (adata.uns)"
f" {key_obsm!r}, the PCA coordinates (adata.obs)\n"
f" {key_varm!r}, the loadings (adata.varm)\n"
f" 'pca_variance', the variance / eigenvalues (adata.uns[{key_uns!r}])\n"
f" 'pca_variance_ratio', the variance ratio (adata.uns[{key_uns!r}])"
)
return adata if copy else None
else:
Expand Down
6 changes: 5 additions & 1 deletion src/scanpy/tools/_tsne.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,11 @@ def tsne(
logg.info(
" finished",
time=start,
deep="added\n 'X_tsne', tSNE coordinates (adata.obsm)",
deep=(
f"added\n"
f" {key_obsm!r}, tSNE coordinates (adata.obsm)\n"
f" {key_uns!r}, tSNE parameters (adata.uns)"
),
)

return adata if copy else None
6 changes: 5 additions & 1 deletion src/scanpy/tools/_umap.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,10 @@ def umap(
logg.info(
" finished",
time=start,
deep=("added\n" " 'X_umap', UMAP coordinates (adata.obsm)"),
deep=(
"added\n"
f" {key_obsm!r}, UMAP coordinates (adata.obsm)\n"
f" {key_uns!r}, UMAP parameters (adata.uns)"
),
)
return adata if copy else None
20 changes: 14 additions & 6 deletions tests/test_aggregated.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

from typing import get_args

import anndata as ad
import numpy as np
import pandas as pd
Expand All @@ -9,11 +11,17 @@

import scanpy as sc
from scanpy._utils import _resolve_axis
from scanpy.get._aggregated import AggType
from testing.scanpy._helpers import assert_equal
from testing.scanpy._helpers.data import pbmc3k_processed
from testing.scanpy._pytest.params import ARRAY_TYPES_MEM


@pytest.fixture(params=get_args(AggType))
def metric(request: pytest.FixtureRequest) -> AggType:
return request.param


@pytest.fixture
def df_base():
ax_base = ["A", "B"]
Expand Down Expand Up @@ -88,7 +96,6 @@ def test_mask(axis):


@pytest.mark.parametrize("array_type", ARRAY_TYPES_MEM)
@pytest.mark.parametrize("metric", ["sum", "mean", "var", "count_nonzero"])
def test_aggregate_vs_pandas(metric, array_type):
adata = pbmc3k_processed().raw.to_adata()
adata = adata[
Expand Down Expand Up @@ -135,7 +142,6 @@ def test_aggregate_vs_pandas(metric, array_type):


@pytest.mark.parametrize("array_type", ARRAY_TYPES_MEM)
@pytest.mark.parametrize("metric", ["sum", "mean", "var", "count_nonzero"])
def test_aggregate_axis(array_type, metric):
adata = pbmc3k_processed().raw.to_adata()
adata = adata[
Expand Down Expand Up @@ -222,7 +228,8 @@ def test_aggregate_axis_specification(axis_name):
{
"a": ["a", "a", "b", "b"],
"b": ["c", "d", "d", "d"],
}
},
index=["a_c", "a_d", "b_d1", "b_d2"],
),
["a", "b"],
["count_nonzero"], # , "sum", "mean"],
Expand Down Expand Up @@ -253,7 +260,8 @@ def test_aggregate_axis_specification(axis_name):
{
"a": ["a", "a", "b", "b"],
"b": ["c", "d", "d", "d"],
}
},
index=["a_c", "a_d", "b_d1", "b_d2"],
),
["a", "b"],
["sum", "mean", "count_nonzero"],
Expand Down Expand Up @@ -284,7 +292,8 @@ def test_aggregate_axis_specification(axis_name):
{
"a": ["a", "a", "b", "b"],
"b": ["c", "d", "d", "d"],
}
},
index=["a_c", "a_d", "b_d1", "b_d2"],
),
["a", "b"],
["mean"],
Expand Down Expand Up @@ -381,7 +390,6 @@ def test_combine_categories(label_cols, cols, expected):


@pytest.mark.parametrize("array_type", ARRAY_TYPES_MEM)
@pytest.mark.parametrize("metric", ["sum", "mean", "var", "count_nonzero"])
def test_aggregate_arraytype(array_type, metric):
adata = pbmc3k_processed().raw.to_adata()
adata = adata[
Expand Down

0 comments on commit 3ba0d30

Please sign in to comment.