Skip to content

Commit

Permalink
simplify further error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
rizac committed Nov 24, 2024
1 parent 4e5bfc7 commit f1d9647
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
6 changes: 4 additions & 2 deletions egsim/api/forms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,11 @@ def clean(self):
try:
validate_inputs(cleaned_data[gsim_field], cleaned_data[imt_field])
except IncompatibleModelImtError as imi_err:
err_msg = (f"incompatible model(s) and intensity measure(s) "
f"{str(imi_err)}")
# add_error removes also the field from self.cleaned_data:
self.add_error(gsim_field, str(imi_err))
self.add_error(imt_field, str(imi_err))
self.add_error(gsim_field, err_msg)
self.add_error(imt_field, err_msg)
return cleaned_data


Expand Down
2 changes: 2 additions & 0 deletions egsim/smtk/residuals.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ def get_residuals_from_expected_and_observed_motions(
:param normalise: boolean (default True) normalize the random effects residuals
(calculated using the inter-event residual formula described in
Abrahamson & Youngs (1992) Eq. 10)
:param return_mean: boolean (default False) include the predicted values
(models computed mean) in the dataframe columns
"""
residuals: pd.DataFrame = pd.DataFrame(index=expected.index)
mean_cols = expected.columns[expected.columns.get_level_values(1) == Clabel.mean]
Expand Down
1 change: 0 additions & 1 deletion egsim/smtk/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,5 @@ def __str__(self):
"""Custom error msg"""
arg = self.args[0]
return (
"incompatible model(s) and intensity measure(s) " +
", ".join(f'{m}+{i}' for m in sorted(arg.keys()) for i in sorted(arg[m]))
)
6 changes: 2 additions & 4 deletions tests/smtk/test_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ def test_invalid_imts(capsys):
harmonize_input_gsims(gsims),
harmonize_input_imts(imts)
)
assert str(err.value) == ('incompatible model(s) and intensity measure(s) '
'BindiEtAl2014Rjb+CAV')
assert str(err.value) == 'BindiEtAl2014Rjb+CAV'

gsims = ['BindiEtAl2014Rjb']
imts = ['CAV', 'MMI']
Expand All @@ -23,8 +22,7 @@ def test_invalid_imts(capsys):
harmonize_input_gsims(gsims),
harmonize_input_imts(imts)
)
assert str(err.value) == ('incompatible model(s) and intensity measure(s) '
'BindiEtAl2014Rjb+CAV, BindiEtAl2014Rjb+MMI')
assert str(err.value) == 'BindiEtAl2014Rjb+CAV, BindiEtAl2014Rjb+MMI'

# period outside the gsim SA limits:
validate_inputs(
Expand Down

0 comments on commit f1d9647

Please sign in to comment.