Skip to content

Commit

Permalink
TST: Update modeling test logic
Browse files Browse the repository at this point in the history
that now fails in devdeps with scipy dev.
Since this is backport branch and the warning may or may not appear,
let's just blanket ignore the unsuccessful fit because test case
is not well defined to begin with.
  • Loading branch information
pllim committed Aug 28, 2023
1 parent 2417387 commit 9580b23
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions astropy/modeling/tests/test_constraints.py
Expand Up @@ -14,13 +14,9 @@
from astropy.modeling import fitting, models
from astropy.modeling.core import Fittable1DModel
from astropy.modeling.parameters import Parameter
from astropy.utils import minversion
from astropy.utils.compat.numpycompat import NUMPY_LT_2_0
from astropy.utils.compat.optional_deps import HAS_SCIPY
from astropy.utils.exceptions import AstropyUserWarning

SCIPY_LT_1_11_2 = not minversion("scipy", "1.11.2") if HAS_SCIPY else True

fitters = [
fitting.LevMarLSQFitter,
fitting.TRFLSQFitter,
Expand Down Expand Up @@ -184,6 +180,7 @@ def test_bounds_slsqp(self):
assert intercept + 10**-5 >= bounds["intercept"][0]
assert intercept - 10**-5 <= bounds["intercept"][1]

@pytest.mark.filterwarnings("ignore:The fit may be unsuccessful")
@pytest.mark.parametrize("fitter", fitters)
def test_bounds_gauss2d_lsq(self, fitter):
fitter = fitter()
Expand All @@ -205,19 +202,13 @@ def test_bounds_gauss2d_lsq(self, fitter):
bounds=bounds,
)
if isinstance(fitter, (fitting.LevMarLSQFitter, fitting.DogBoxLSQFitter)):
with pytest.warns(AstropyUserWarning, match="The fit may be unsuccessful"):
model = fitter(gauss, X, Y, self.data)
model = fitter(gauss, X, Y, self.data)
else:
ctx2 = nullcontext()
if isinstance(fitter, fitting.TRFLSQFitter):
ctx = np.errstate(invalid="ignore", divide="ignore")
if not NUMPY_LT_2_0 or not SCIPY_LT_1_11_2:
ctx2 = pytest.warns(
AstropyUserWarning, match="The fit may be unsuccessful"
)
else:
ctx = nullcontext()
with ctx, ctx2:
with ctx:
model = fitter(gauss, X, Y, self.data)
x_mean = model.x_mean.value
y_mean = model.y_mean.value
Expand Down

0 comments on commit 9580b23

Please sign in to comment.