Skip to content

Commit 912a832

Browse files
Backport PR #3393 on branch 1.3.x ([pre-commit.ci] pre-commit autoupdate) (#3398)
Backport PR #3393: [pre-commit.ci] pre-commit autoupdate Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 9eea1cc commit 912a832

21 files changed

+121
-97
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ repos:
4141
)$
4242
4343
- repo: https://github.com/astral-sh/ruff-pre-commit
44-
rev: v0.11.13
44+
rev: v0.12.0
4545
hooks:
4646
- id: ruff
4747
args: [--fix, --exit-non-zero-on-fix]

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,13 @@ to [Semantic Versioning]. Full commit history is available in the
2424

2525
#### Changed
2626

27+
- Update Read the docs tutorials with one main preprocessing tutorial {pr}`3363`.
28+
2729
#### Removed
2830

31+
- Removed default arguments from test function parameters due to ruff pre-commit v0.12.0 with
32+
PT028 rule {pr}`3393`.
33+
2934
### 1.3.1 (2025-05-15)
3035

3136
#### Added

src/scvi/nn/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
MultiEncoder,
1111
)
1212
from ._embedding import Embedding
13-
from ._utils import one_hot
1413

1514
__all__ = [
1615
"FCLayers",
@@ -22,6 +21,5 @@
2221
"LinearDecoderSCVI",
2322
"MultiEncoder",
2423
"MultiDecoder",
25-
"one_hot",
2624
"Embedding",
2725
]

src/scvi/nn/_utils.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,6 @@
1-
import warnings
2-
31
import torch
42
from torch import nn
53

6-
from scvi import settings
7-
8-
9-
def one_hot(index: torch.Tensor, n_cat: int) -> torch.Tensor:
10-
"""One hot a tensor of categories."""
11-
# TODO: remove in 1.3.0
12-
warnings.warn(
13-
"The `one_hot` function is deprecated in v1.2 and will be removed in v1.3. "
14-
"Please use the `one_hot` function in PyTorch instead.",
15-
DeprecationWarning,
16-
stacklevel=settings.warnings_stacklevel,
17-
)
18-
onehot = torch.zeros(index.size(0), n_cat, device=index.device)
19-
onehot.scatter_(1, index.type(torch.long), 1)
20-
return onehot.type(torch.float32)
21-
224

235
class ExpActivation(nn.Module):
246
def __init__(self):

tests/autotune/test_tune.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ def test_run_autotune_scvi_basic(save_path: str):
4343

4444

4545
@pytest.mark.autotune
46-
def test_run_autotune_scvi_no_anndata(save_path: str, n_batches: int = 3):
46+
@pytest.mark.parametrize("n_batches", [3])
47+
def test_run_autotune_scvi_no_anndata(save_path: str, n_batches: int):
4748
from ray import tune
4849
from ray.tune import ResultGrid
4950

@@ -150,7 +151,8 @@ def test_run_autotune_scvi_with_scib(model_cls, metric: str, save_path: str):
150151

151152

152153
@pytest.mark.autotune
153-
def test_run_autotune_scvi_with_scib_ext_indices(save_path: str, metric: str = "iLISI"):
154+
@pytest.mark.parametrize("metric", ["iLISI"])
155+
def test_run_autotune_scvi_with_scib_ext_indices(save_path: str, metric: str):
154156
from ray import tune
155157
from ray.tune import ResultGrid
156158

tests/criticism/test_criticism.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import numpy as np
66
import pandas as pd
7+
import pytest
78
from sparse import GCXS
89
from xarray import Dataset
910

@@ -101,7 +102,8 @@ def test_ppc_zero_fraction():
101102
assert ppc.metrics["zero_fraction"].columns.tolist() == ["model1", "model2", "Raw"]
102103

103104

104-
def test_ppc_de(n_genes: int = 200):
105+
@pytest.mark.parametrize("n_genes", [200])
106+
def test_ppc_de(n_genes: int):
105107
adata = synthetic_iid(n_genes=n_genes)
106108
ppc, _ = get_ppc_with_samples(adata, n_samples=4)
107109

tests/data/test_anntorchdataset.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ def test_getitem_tensors():
7373
manager.create_torch_dataset(data_and_attributes=1)
7474

7575

76-
def test_getitem(n_genes: int = 50):
76+
@pytest.mark.parametrize("n_genes", [50])
77+
def test_getitem(n_genes: int):
7778
adata = scvi.data.synthetic_iid(n_genes=n_genes)
7879
manager = generic_setup_adata_manager(adata, batch_key="batch")
7980

@@ -105,7 +106,8 @@ def test_getitem(n_genes: int = 50):
105106

106107

107108
@pytest.mark.parametrize("sparse_format", ["csr_matrix", "csc_matrix"])
108-
def test_load_sparse_tensor(sparse_format: str | None, n_genes: int = 50):
109+
@pytest.mark.parametrize("n_genes", [50])
110+
def test_load_sparse_tensor(sparse_format: str | None, n_genes: int):
109111
adata = scvi.data.synthetic_iid(sparse_format=sparse_format, n_genes=n_genes)
110112
manager = generic_setup_adata_manager(adata, batch_key="batch")
111113

@@ -136,7 +138,8 @@ def test_load_sparse_tensor(sparse_format: str | None, n_genes: int = 50):
136138
assert data[REGISTRY_KEYS.BATCH_KEY].shape == (1, 1)
137139

138140

139-
def test_load_sparse_tensor_backed(save_path: str, n_genes: int = 50):
141+
@pytest.mark.parametrize("n_genes", [50])
142+
def test_load_sparse_tensor_backed(save_path: str, n_genes: int):
140143
adata = scvi.data.synthetic_iid(sparse_format="csr_matrix", n_genes=n_genes)
141144
adata_path = os.path.join(save_path, "adata.h5ad")
142145
adata.write(adata_path)

tests/dataloaders/test_dataloaders.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,14 @@ def training_step(self, batch, batch_idx):
5151
return super().training_step(batch, batch_idx)
5252

5353

54-
def test_semisuperviseddataloader_subsampling(
55-
batch_size: int = 128,
56-
n_batches: int = 2,
57-
n_labels: int = 3,
58-
n_samples_per_label: int = 10,
59-
):
60-
adata = scvi.data.synthetic_iid(batch_size=batch_size, n_batches=n_batches, n_labels=n_labels)
54+
def test_semisuperviseddataloader_subsampling():
55+
adata = scvi.data.synthetic_iid(batch_size=128, n_batches=2, n_labels=3)
6156
adata.obs["indices"] = np.arange(adata.n_obs)
6257

6358
original_training_plan_cls = scvi.model.SCANVI._training_plan_cls
6459
scvi.model.SCANVI._training_plan_cls = TestSemiSupervisedTrainingPlan
6560
plan_kwargs = {
66-
"n_samples_per_label": n_samples_per_label,
61+
"n_samples_per_label": 10,
6762
}
6863
scvi.model.SCANVI.setup_anndata(
6964
adata,
@@ -74,8 +69,8 @@ def test_semisuperviseddataloader_subsampling(
7469
model = scvi.model.SCANVI(adata)
7570
model.train(
7671
max_epochs=10,
77-
batch_size=batch_size // 2,
78-
n_samples_per_label=n_samples_per_label,
72+
batch_size=128 // 2,
73+
n_samples_per_label=10,
7974
plan_kwargs=plan_kwargs,
8075
)
8176

tests/dataloaders/test_samplers.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
from scvi.dataloaders import BatchDistributedSampler
99

1010

11+
@pytest.mark.parametrize("batch_size", [128])
12+
@pytest.mark.parametrize("n_batches", [2])
1113
def test_batchdistributedsampler_init(
12-
batch_size: int = 128,
13-
n_batches: int = 2,
14+
batch_size: int,
15+
n_batches: int,
1416
):
1517
adata = scvi.data.synthetic_iid(batch_size=batch_size, n_batches=n_batches)
1618
manager = generic_setup_adata_manager(adata)
@@ -35,12 +37,15 @@ def test_batchdistributedsampler_init(
3537

3638
@pytest.mark.parametrize("drop_last", [True, False])
3739
@pytest.mark.parametrize("drop_dataset_tail", [True, False])
40+
@pytest.mark.parametrize("batch_size", [128])
41+
@pytest.mark.parametrize("n_batches", [3])
42+
@pytest.mark.parametrize("num_replicas", [2])
3843
def test_batchdistributedsampler_drop_last(
3944
drop_last: bool,
4045
drop_dataset_tail: bool,
41-
batch_size: int = 128,
42-
n_batches: int = 3,
43-
num_replicas: int = 2,
46+
batch_size: int,
47+
n_batches: int,
48+
num_replicas: int,
4449
):
4550
"""Expected behavior:
4651
@@ -116,10 +121,13 @@ def check_samplers(samplers: list, sampler_batch_size: int):
116121
check_samplers(samplers, sampler_batch_size)
117122

118123

124+
@pytest.mark.parametrize("batch_size", [128])
125+
@pytest.mark.parametrize("n_batches", [3])
126+
@pytest.mark.parametrize("num_replicas", [2])
119127
def test_batchdistributedsampler_indices(
120-
batch_size: int = 128,
121-
n_batches: int = 3,
122-
num_replicas: int = 2,
128+
batch_size: int,
129+
n_batches: int,
130+
num_replicas: int,
123131
):
124132
adata = scvi.data.synthetic_iid(batch_size=batch_size, n_batches=n_batches)
125133
manager = generic_setup_adata_manager(adata)

tests/distributions/test_negative_binomial.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ def test_zinb_distribution():
4949
ZeroInflatedNegativeBinomial(
5050
mu=-mu, theta=theta, zi_logits=pi, scale=scales, validate_args=True
5151
)
52-
with pytest.warns(UserWarning):
52+
with pytest.warns(UserWarning, match="The value argument must be within the support"):
5353
dist1.log_prob(-x) # ensures neg values raise warning
54-
with pytest.warns(UserWarning):
54+
with pytest.warns(UserWarning, match="The value argument must be within the support"):
5555
dist2.log_prob(0.5 * x) # ensures float values raise warning
5656

5757
# test with no scale
@@ -62,7 +62,7 @@ def test_zinb_distribution():
6262
assert dist1.log_prob(x).shape == size
6363
assert dist2.log_prob(x).shape == size
6464

65-
with pytest.warns(UserWarning):
65+
with pytest.warns(UserWarning, match="The value argument must be within the support"):
6666
dist1.log_prob(-x)
67-
with pytest.warns(UserWarning):
67+
with pytest.warns(UserWarning, match="The value argument must be within the support"):
6868
dist2.log_prob(0.5 * x)

0 commit comments

Comments
 (0)