From d2091b1646e7c41fb75fd5750233ecdafb548b16 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 26 Sep 2023 10:18:06 +0200 Subject: [PATCH] [pre-commit.ci] pre-commit autoupdate (#383) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [pre-commit.ci] pre-commit autoupdate updates: - [github.com/astral-sh/ruff-pre-commit: v0.0.290 → v0.0.291](https://github.com/astral-sh/ruff-pre-commit/compare/v0.0.290...v0.0.291) * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 2 +- pertpy/tools/_distances/_distances.py | 9 +++++---- tests/tools/_distances/test_distances.py | 6 ++++-- 3 files changed, 10 insertions(+), 7 deletions(-) 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