From 8369414427e5c9829ad5fb463d7c2f36e3bf2c4f Mon Sep 17 00:00:00 2001 From: Philipp A Date: Fri, 10 Nov 2023 10:35:58 +0100 Subject: [PATCH] XFail lobpcg with small test data (#2745) --- pyproject.toml | 2 +- scanpy/tests/test_pca.py | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 46d3ee558..a782f9e62 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -107,7 +107,7 @@ test-full = [ ] doc = [ "sphinx>=5", - "sphinx-book-theme", + "sphinx-book-theme>=1.0.1", "scanpydoc>=0.9.5", "sphinx-autodoc-typehints", "myst-parser", diff --git a/scanpy/tests/test_pca.py b/scanpy/tests/test_pca.py index 50f7427bf..b95a5366c 100644 --- a/scanpy/tests/test_pca.py +++ b/scanpy/tests/test_pca.py @@ -1,3 +1,4 @@ +from typing import Literal import numpy as np import pytest import warnings @@ -71,7 +72,9 @@ def zero_center(request: pytest.FixtureRequest): @pytest.fixture -def pca_params(array_type, svd_solver_type, zero_center): +def pca_params( + array_type, svd_solver_type: Literal[None, "valid", "invalid"], zero_center +): all_svd_solvers = {"auto", "full", "arpack", "randomized", "tsqr", "lobpcg"} expected_warning = None @@ -120,7 +123,9 @@ def test_pca_warnings(array_type, zero_center, pca_params): if expected_warning is not None: with pytest.warns(UserWarning, match=expected_warning): sc.pp.pca(adata, svd_solver=svd_solver, zero_center=zero_center) - else: + return + + try: with warnings.catch_warnings(): warnings.simplefilter("error") warnings.filterwarnings( @@ -129,6 +134,12 @@ def test_pca_warnings(array_type, zero_center, pca_params): DeprecationWarning, ) sc.pp.pca(adata, svd_solver=svd_solver, zero_center=zero_center) + except UserWarning: + # TODO: Fix this case, maybe by increasing test data size. + # https://github.com/scverse/scanpy/issues/2744 + if svd_solver == "lobpcg": + pytest.xfail(reason="lobpcg doesn’t work with this small test data") + raise # This warning test is out of the fixture because it is a special case in the logic of the function