Skip to content

Commit 99dad48

Browse files
committed
simplify warning and error names
1 parent e895b22 commit 99dad48

6 files changed

Lines changed: 15 additions & 9 deletions

File tree

pymatsolver/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
from .direct import Solver, pardiso
6464
from .direct import SolverLU
6565

66-
from .solvers import PymatsolverAccuracyError
66+
from .solvers import SolverAccuracyError
6767
from .direct import Pardiso, Mumps
6868
from .direct.pardiso import _available as _pardiso_available
6969
from .direct.mumps import _available as _mumps_available

pymatsolver/solvers.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77
import copy
88

99

10-
class PymatsolverAccuracyError(Exception):
10+
class SolverAccuracyError(Exception):
11+
pass
12+
13+
14+
class UnusedArgumentWarning(UserWarning):
1115
pass
1216

1317

@@ -93,7 +97,7 @@ def __init__(
9397
if kwargs:
9498
warnings.warn(
9599
f"Unused keyword arguments for {self.__class__.__name__}: {kwargs.keys()}",
96-
UserWarning,
100+
UnusedArgumentWarning,
97101
stacklevel=3
98102
)
99103

@@ -275,7 +279,7 @@ def _compute_accuracy(self, rhs, x):
275279
rhs_norm = np.linalg.norm(rhs)
276280
tolerance = max(self.check_rtol * rhs_norm, self.check_atol)
277281
if resid_norm > tolerance:
278-
raise PymatsolverAccuracyError(
282+
raise SolverAccuracyError(
279283
f'Accuracy on solve is above tolerance: {resid_norm} > {tolerance}'
280284
)
281285

pymatsolver/wrappers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from inspect import signature
33
import numpy as np
44

5-
from pymatsolver.solvers import Base
5+
from pymatsolver.solvers import Base, UnusedArgumentWarning
66

77
def _valid_kwargs_for_func(func, **kwargs):
88
"""Validates keyword arguments for a function by inspecting its signature.
@@ -28,7 +28,7 @@ def _valid_kwargs_for_func(func, **kwargs):
2828
sig.bind_partial(**{key: value})
2929
valid_kwargs[key] = value
3030
except TypeError:
31-
warnings.warn(f'Unused keyword argument "{key}" for {func.__name__}.', UserWarning, stacklevel=3)
31+
warnings.warn(f'Unused keyword argument "{key}" for {func.__name__}.', UnusedArgumentWarning, stacklevel=3)
3232
# stack level of three because we want the warning issued at the call
3333
# to the wrapped solver's `__init__` method.
3434
return valid_kwargs

tests/test_Basic.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import scipy.sparse as sp
55
import pymatsolver
66
from pymatsolver import Diagonal
7+
from pymatsolver.solvers import UnusedArgumentWarning
78

89
TOL = 1e-12
910

@@ -84,7 +85,7 @@ def test_errors_and_warnings():
8485
with pytest.warns(FutureWarning, match="accuracy_tol is deprecated.*"):
8586
IdentitySolver(np.full((4, 4), 1), accuracy_tol=0.41)
8687

87-
with pytest.warns(UserWarning, match="Unused keyword arguments.*"):
88+
with pytest.warns(UnusedArgumentWarning, match="Unused keyword arguments.*"):
8889
IdentitySolver(np.full((4, 4), 1), not_an_argument=4)
8990

9091
with pytest.raises(TypeError, match="is_symmetric must be a boolean."):

tests/test_Pardiso.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def test_inacurrate_symmetry(test_mat_data):
128128
D = sp.diags(np.linspace(2, 3, A.shape[0]))
129129
A = A @ D
130130
Ainv = pymatsolver.Pardiso(A, is_symmetric=True, check_accuracy=True)
131-
with pytest.raises(pymatsolver.PymatsolverAccuracyError):
131+
with pytest.raises(pymatsolver.SolverAccuracyError):
132132
Ainv * rhs
133133

134134

tests/test_Wrappers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from pymatsolver import SolverCG, SolverLU, wrap_direct, wrap_iterative
2+
from pymatsolver.solvers import UnusedArgumentWarning
23
import pytest
34
import scipy.sparse as sp
45
import warnings
@@ -10,7 +11,7 @@
1011
def test_wrapper_unused_kwargs(solver_class):
1112
A = sp.eye(10)
1213

13-
with pytest.warns(UserWarning, match="Unused keyword argument.*"):
14+
with pytest.warns(UnusedArgumentWarning, match="Unused keyword argument.*"):
1415
solver_class(A, not_a_keyword_arg=True)
1516

1617
def test_good_arg_iterative():

0 commit comments

Comments
 (0)