diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e15ffad9..b49bc12c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -25,7 +25,7 @@ repos: # https://github.com/jupyterlab/jupyterlab/issues/12675 language_version: "17.9.1" - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.0.290 + rev: v0.0.291 hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] diff --git a/pertpy/tools/_distances/_distances.py b/pertpy/tools/_distances/_distances.py index 6733de86..74b30cd6 100644 --- a/pertpy/tools/_distances/_distances.py +++ b/pertpy/tools/_distances/_distances.py @@ -1,7 +1,6 @@ from __future__ import annotations from abc import ABC, abstractmethod -from collections.abc import Iterable from typing import TYPE_CHECKING import numpy as np @@ -14,6 +13,8 @@ from sklearn.metrics import pairwise_distances if TYPE_CHECKING: + from collections.abc import Iterable + from anndata import AnnData @@ -144,7 +145,7 @@ def pairwise( # Some metrics are able to handle precomputed distances. This means that # the pairwise distances between all cells are computed once and then # passed to the metric function. This is much faster than computing the - # pairwise distances for each group separately. Other metrics are not + # pairwise distances for each group separately. Other metrics are not # able to handle precomputed distances such as the PsuedobulkDistance. if self.metric_fct.accepts_precomputed: # Precompute the pairwise distances if needed @@ -180,7 +181,7 @@ def pairwise( df.columns.name = groupby df.name = f"pairwise {self.metric}" return df - + def onesided_distances( self, adata: AnnData, @@ -218,7 +219,7 @@ def onesided_distances( # Some metrics are able to handle precomputed distances. This means that # the pairwise distances between all cells are computed once and then # passed to the metric function. This is much faster than computing the - # pairwise distances for each group separately. Other metrics are not + # pairwise distances for each group separately. Other metrics are not # able to handle precomputed distances such as the PsuedobulkDistance. if self.metric_fct.accepts_precomputed: # Precompute the pairwise distances if needed diff --git a/tests/tools/_distances/test_distances.py b/tests/tools/_distances/test_distances.py index 4d927f51..bd71b671 100644 --- a/tests/tools/_distances/test_distances.py +++ b/tests/tools/_distances/test_distances.py @@ -36,11 +36,13 @@ def test_distance_pairwise(self, adata, distance): assert isinstance(df, DataFrame) assert df.columns.equals(df.index) assert np.sum(df.values - df.values.T) == 0 # symmetry - + @mark.parametrize("distance", actual_distances + pseudo_distances) def test_distance_onesided(self, adata, distance): Distance = pt.tl.Distance(distance, "X_pca") selected_group = adata.obs.perturbation.unique()[0] - df = Distance.onesided_distances(adata, groupby="perturbation", selected_group=selected_group, show_progressbar=True) + df = Distance.onesided_distances( + adata, groupby="perturbation", selected_group=selected_group, show_progressbar=True + ) assert isinstance(df, Series) assert df.loc[selected_group] == 0 # distance to self is 0