[Fix] Handle platform-dependent rank-deficient warning in ODR tests

This commit is contained in:
Fabian Joswig 2026-03-29 20:10:54 +02:00
commit 92d5b59430

View file

@ -1,3 +1,4 @@
import warnings
import numpy as np
import autograd.numpy as anp
import matplotlib.pyplot as plt
@ -476,7 +477,9 @@ def test_total_least_squares_vanishing_chisquare():
x = [pe.pseudo_Obs(1.0, 0.1, 'x0'), pe.pseudo_Obs(2.0, 0.1, 'x1')]
y = [pe.pseudo_Obs(1.0, 0.1, 'y0'), pe.pseudo_Obs(2.0, 0.1, 'y1')]
with pytest.warns(RuntimeWarning, match="rank deficient"):
# Rank-deficient warning may or may not fire depending on platform/solver numerics.
with warnings.catch_warnings():
warnings.filterwarnings("ignore", message="ODR fit is rank deficient", category=RuntimeWarning)
out = pe.total_least_squares(x, y, func, silent=True)
assert len(out.fit_parameters) == 2
@ -525,7 +528,10 @@ def test_r_value_persistence():
assert np.isclose(fitp[1].value, fitp[1].r_values['a'])
assert np.isclose(fitp[1].value, fitp[1].r_values['b'])
fitp = pe.fits.total_least_squares(y, y, f)
# Rank-deficient warning may or may not fire depending on platform/solver numerics.
with warnings.catch_warnings():
warnings.filterwarnings("ignore", message="ODR fit is rank deficient", category=RuntimeWarning)
fitp = pe.fits.total_least_squares(y, y, f)
assert np.isclose(fitp[0].value, fitp[0].r_values['a'])
assert np.isclose(fitp[0].value, fitp[0].r_values['b'])