|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
3 | 3 | import itertools |
| 4 | +from contextlib import nullcontext |
4 | 5 | from pathlib import Path |
5 | 6 | from string import ascii_letters |
6 | 7 | from typing import TYPE_CHECKING |
@@ -391,11 +392,12 @@ def test_compare_to_upstream( |
391 | 392 | sc.pp.log1p(pbmc) |
392 | 393 | sc.pp.highly_variable_genes(pbmc, flavor=flavor, **params, inplace=True) |
393 | 394 | elif func == "fgd": |
394 | | - sc.pp.filter_genes_dispersion( |
395 | | - pbmc, flavor=flavor, **params, log=True, subset=False |
396 | | - ) |
| 395 | + with pytest.warns(FutureWarning, match=r"sc\.pp\.highly_variable_genes"): |
| 396 | + sc.pp.filter_genes_dispersion( |
| 397 | + pbmc, flavor=flavor, **params, log=True, subset=False |
| 398 | + ) |
397 | 399 | else: |
398 | | - raise AssertionError() |
| 400 | + pytest.fail(f"Unknown func {func}") |
399 | 401 |
|
400 | 402 | np.testing.assert_array_equal( |
401 | 403 | hvg_info["highly_variable"], pbmc.var["highly_variable"] |
@@ -505,7 +507,7 @@ def test_seurat_v3_warning(): |
505 | 507 |
|
506 | 508 | def test_batches(): |
507 | 509 | adata = pbmc68k_reduced() |
508 | | - adata[:100, :100].X = np.zeros((100, 100)) |
| 510 | + adata.X[:100, :100] = np.zeros((100, 100)) |
509 | 511 |
|
510 | 512 | adata.obs["batch"] = ["0" if i < 100 else "1" for i in range(adata.n_obs)] |
511 | 513 | adata_1 = adata[adata.obs["batch"] == "0"].copy() |
@@ -558,6 +560,7 @@ def test_batches(): |
558 | 560 | assert np.all(np.isin(colnames, hvg1.columns)) |
559 | 561 |
|
560 | 562 |
|
| 563 | +@pytest.mark.filterwarnings("ignore:invalid value encountered:RuntimeWarning") |
561 | 564 | def test_degenerate_batches(): |
562 | 565 | adata = AnnData( |
563 | 566 | X=np.random.randn(10, 100), |
@@ -692,10 +695,17 @@ def test_dask_consistency(adata: AnnData, flavor, batch_key, to_dask): |
692 | 695 | adata_dask = adata.copy() |
693 | 696 | adata_dask.X = to_dask(adata_dask.X) |
694 | 697 |
|
695 | | - output_mem, output_dask = ( |
696 | | - sc.pp.highly_variable_genes(ad, flavor=flavor, n_top_genes=15, inplace=False) |
697 | | - for ad in [adata, adata_dask] |
698 | | - ) |
| 698 | + with ( |
| 699 | + pytest.warns(UserWarning, match="n_top_genes.*normalized dispersions") |
| 700 | + if flavor == "cell_ranger" |
| 701 | + else nullcontext() |
| 702 | + ): |
| 703 | + output_mem, output_dask = ( |
| 704 | + sc.pp.highly_variable_genes( |
| 705 | + ad, flavor=flavor, n_top_genes=15, inplace=False |
| 706 | + ) |
| 707 | + for ad in [adata, adata_dask] |
| 708 | + ) |
699 | 709 |
|
700 | 710 | assert isinstance(output_mem, pd.DataFrame) |
701 | 711 | assert isinstance(output_dask, pd.DataFrame) |
|
0 commit comments