Skip to content

Commit

Permalink
[pre-commit.ci] pre-commit autoupdate (#383)
Browse files Browse the repository at this point in the history
* [pre-commit.ci] pre-commit autoupdate

updates:
- [github.com/astral-sh/ruff-pre-commit: v0.0.290 → v0.0.291](astral-sh/ruff-pre-commit@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>
  • Loading branch information
pre-commit-ci[bot] authored Sep 26, 2023
1 parent 2038248 commit d2091b1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
9 changes: 5 additions & 4 deletions pertpy/tools/_distances/_distances.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -14,6 +13,8 @@
from sklearn.metrics import pairwise_distances

if TYPE_CHECKING:
from collections.abc import Iterable

from anndata import AnnData


Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -180,7 +181,7 @@ def pairwise(
df.columns.name = groupby
df.name = f"pairwise {self.metric}"
return df

def onesided_distances(
self,
adata: AnnData,
Expand Down Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions tests/tools/_distances/test_distances.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit d2091b1

Please sign in to comment.