Skip to content

Commit fe02bfa

Browse files
committed
Address review comments
1 parent 3372d28 commit fe02bfa

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

ratapi/inputs.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ def make_problem(project: ratapi.Project, validate_range: bool = False) -> Probl
151151
----------
152152
project : RAT.Project
153153
The project model, which defines the physical system under study.
154+
validate_range : bool, default True
155+
Whether parameter range should be validated.
154156
155157
Returns
156158
-------
@@ -366,7 +368,7 @@ def make_problem(project: ratapi.Project, validate_range: bool = False) -> Probl
366368
prior_values.append([prior_id[param.prior_type], param.mu, param.sigma])
367369
check_list.append(int(param.fit))
368370
if param.fit:
369-
min_range = abs(param.value) * 1e-6 if param.value == 0 else 1e-6
371+
min_range = 1e-6 if param.value == 0 else abs(param.value) * 1e-6
370372
if validate_range and (param.max - param.min) < min_range:
371373
warnings.warn(
372374
f'{class_list.replace("_", " ").title()} "{param.name}" was removed from the '

tests/test_inputs.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -483,15 +483,19 @@ def test_make_problem(test_project, test_problem, request) -> None:
483483
check_problem_equal(problem, test_problem)
484484

485485

486-
def test_make_problem_validate_range(request) -> None:
486+
@pytest.mark.parametrize("value,min_range", [(0, 1e-6), (10, 1e-5)])
487+
def test_make_problem_validate_range(value, min_range, request) -> None:
487488
"""The problem should not contain fitted parameters with small range."""
488489
test_project = request.getfixturevalue("standard_layers_project")
489490

490-
test_project.scalefactors.set_fields(0, min=10, value=10, max=10, fit=True)
491+
test_project.scalefactors.set_fields(0, min=value, value=value, max=value, fit=True)
491492
problem = make_problem(test_project)
492493
assert problem.checks.scalefactors[0] == 1
493494

494-
with pytest.warns(UserWarning, match="was removed from the fit because its range is too small \(< 1e-06\)"):
495+
with pytest.warns(
496+
UserWarning,
497+
match="was removed from the fit because its range is too small {0}(< {1:g}{0})".format("\\", min_range),
498+
):
495499
problem = make_problem(test_project, True)
496500
assert problem.checks.scalefactors[0] == 0
497501

0 commit comments

Comments
 (0)