Skip to content

Commit 422cae9

Browse files
committed
fix some warnings
1 parent c7dad8f commit 422cae9

4 files changed

Lines changed: 31 additions & 20 deletions

File tree

src/scanpy/tools/_tsne.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,10 @@ def tsne( # noqa: PLR0913
135135
# Backwards compat handling: Remove in scanpy 1.9.0
136136
if n_jobs != 1 and not use_fast_tsne:
137137
warnings.warn(
138-
"In previous versions of scanpy, calling tsne with n_jobs > 1 would use "
139-
"MulticoreTSNE. Now this uses the scikit-learn version of TSNE by default. "
140-
"If you'd like the old behaviour (which is deprecated), pass "
141-
"'use_fast_tsne=True'. Note, MulticoreTSNE is not actually faster anymore.",
138+
"In previous versions of scanpy, calling tsne with `n_jobs` > 1 would use MulticoreTSNE. "
139+
"Now this uses the scikit-learn version of TSNE by default. "
140+
"If youd like the old behaviour (which is deprecated), pass `use_fast_tsne=True`. "
141+
"Note, MulticoreTSNE is not actually faster anymore.",
142142
UserWarning,
143143
stacklevel=2,
144144
)
@@ -154,18 +154,18 @@ def tsne( # noqa: PLR0913
154154
if use_fast_tsne:
155155
try:
156156
from MulticoreTSNE import MulticoreTSNE as TSNE
157-
158-
tsne = TSNE(**params_sklearn)
159-
logg.info(" using the 'MulticoreTSNE' package by Ulyanov (2017)")
160-
# need to transform to float64 for MulticoreTSNE...
161-
X_tsne = tsne.fit_transform(X.astype("float64"))
162157
except ImportError:
163158
use_fast_tsne = False
164159
warnings.warn(
165160
"Could not import 'MulticoreTSNE'. Falling back to scikit-learn.",
166-
UserWarning,
161+
ImportWarning,
167162
stacklevel=2,
168163
)
164+
else:
165+
tsne = TSNE(**params_sklearn)
166+
logg.info(" using the 'MulticoreTSNE' package by Ulyanov (2017)")
167+
# need to transform to float64 for MulticoreTSNE...
168+
X_tsne = tsne.fit_transform(X.astype("float64"))
169169
if use_fast_tsne is False: # In case MultiCore failed to import
170170
from sklearn.manifold import TSNE
171171

tests/test_clustering.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,14 @@ def test_clustering_subset(adata_neighbors, clustering, key):
189189
@pytest.mark.parametrize(
190190
("clustering", "default_key", "default_res", "custom_resolutions"),
191191
[
192-
pytest.param(sc.tl.leiden, "leiden", 0.8, [0.9, 1.1], marks=needs.leidenalg),
192+
pytest.param(
193+
partial(sc.tl.leiden, flavor="leidenalg"),
194+
"leiden",
195+
0.8,
196+
[0.9, 1.1],
197+
marks=needs.leidenalg,
198+
id="leiden",
199+
),
193200
],
194201
)
195202
def test_clustering_custom_key(

tests/test_deprecations.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@
66
from testing.scanpy._helpers.data import pbmc68k_reduced
77

88

9-
def test_deprecate_multicore_tsne():
9+
def test_deprecate_multicore_tsne() -> None:
1010
pbmc = pbmc68k_reduced()
1111

1212
with pytest.warns(
13-
UserWarning, match="calling tsne with n_jobs > 1 would use MulticoreTSNE"
13+
UserWarning, match=r"calling tsne with `n_jobs` > 1 would use MulticoreTSNE"
1414
):
1515
sc.tl.tsne(pbmc, n_jobs=2)
1616

17-
with pytest.warns(FutureWarning, match="Argument `use_fast_tsne` is deprecated"):
18-
sc.tl.tsne(pbmc, use_fast_tsne=True)
19-
20-
with pytest.warns(UserWarning, match="Falling back to scikit-learn"):
17+
with (
18+
pytest.warns(FutureWarning, match=r"Argument `use_fast_tsne` is deprecated"),
19+
pytest.warns(ImportWarning, match=r"MulticoreTSNE"),
20+
):
2121
sc.tl.tsne(pbmc, use_fast_tsne=True)
2222

2323

tests/test_preprocessing.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,9 +280,10 @@ def test_scale_zero_center_warns_dask_sparse(array_type):
280280
adata.X = adata.raw.X
281281
adata_casted = adata.copy()
282282
adata_casted.X = array_type(adata_casted.raw.X)
283-
with pytest.warns(UserWarning, match="zero-center.*sparse"):
283+
with pytest.warns(UserWarning, match=r"zero-center.*sparse"):
284284
sc.pp.scale(adata_casted)
285-
sc.pp.scale(adata)
285+
with pytest.warns(UserWarning, match=r"zero-center.*sparse"):
286+
sc.pp.scale(adata)
286287
assert_allclose(adata_casted.X, adata.X, rtol=1e-5, atol=1e-5)
287288

288289

@@ -292,7 +293,10 @@ def test_scale():
292293
v = adata[:, 0 : adata.shape[1] // 2]
293294
# Should turn view to copy https://github.com/scverse/anndata/issues/171#issuecomment-508689965
294295
assert v.is_view
295-
with pytest.warns(Warning, match="view"):
296+
with (
297+
pytest.warns(UserWarning, match=r"zero-center.*sparse"),
298+
pytest.warns(UserWarning, match=r"Received a view"),
299+
):
296300
sc.pp.scale(v)
297301
assert not v.is_view
298302
assert_allclose(v.X.var(axis=0), np.ones(v.shape[1]), atol=0.01)

0 commit comments

Comments
 (0)