Skip to content

Commit 97bd543

Browse files
authored
Merge pull request scipy#22174 from dschult/catch_warnings_optimize
Maint: optimize: switch suppress_warnings to catch_warnings
2 parents 95ae5fc + c1d7407 commit 97bd543

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

scipy/optimize/_linprog_ip.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
from sksparse.cholmod import cholesky as cholmod # noqa: F401
3333
from sksparse.cholmod import analyze as cholmod_analyze
3434
from sksparse.cholmod import CholmodTypeConversionWarning
35+
from warnings import catch_warnings
3536
except ImportError:
3637
has_cholmod = False
3738
try:
@@ -98,8 +99,9 @@ def solve(r, sym_pos=False):
9899
# except Exception:
99100
# _get_solver.cholmod_factor = cholmod_analyze(M)
100101
# _get_solver.cholmod_factor.cholesky_inplace(M)
101-
with np.testing.suppress_warnings() as sup:
102-
sup.filter(CholmodTypeConversionWarning)
102+
with catch_warnings(
103+
action='ignore', category=CholmodTypeConversionWarning
104+
):
103105
try:
104106
# Will raise an exception in the first call,
105107
# or when the matrix changes due to a new problem

scipy/optimize/_trustregion_constr/projections.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import warnings
1212
sksparse_available = False
1313
import numpy as np
14-
from warnings import warn
14+
from warnings import warn, catch_warnings
1515

1616
__all__ = [
1717
'orthogonality',
@@ -61,8 +61,7 @@ def normal_equation_projections(A, m, n, orth_tol, max_refin, tol):
6161
# TODO: revert this once the warning bug fix in sksparse is merged/released
6262
# Add suppression of spurious warning bug from sksparse with csc_array gh-22089
6363
# factor = cholesky_AAt(A)
64-
with np.testing.suppress_warnings() as sup:
65-
sup.filter(CholmodTypeConversionWarning, "converting matrix of class")
64+
with catch_warnings(action='ignore', category=CholmodTypeConversionWarning):
6665
factor = cholesky_AAt(A)
6766

6867
# z = x - A.T inv(A A.T) A x

0 commit comments

Comments
 (0)