Skip to content

Commit

Permalink
Use invalid_argument exception for invalid extrapolation policy
Browse files Browse the repository at this point in the history
Instead of runtime_error
  • Loading branch information
tnipen committed Mar 11, 2024
1 parent 5d89bb3 commit fc15fcd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/api/curve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ float gridpp::apply_curve(float input, const vec& curve_ref, const vec& curve_fc
slope = dObs / dFcst;
}
else {
throw std::runtime_error("Unknown extrapolation policy");
throw std::invalid_argument("Unknown extrapolation policy");
}
output = nearestObs + slope * (input - nearestFcst);
}
Expand Down
14 changes: 11 additions & 3 deletions tests/test_apply_curve.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,18 @@ def test_3d(self):

def test_all_extrapolation_policies(self):
"""Check that all policies work"""
curve_fcst = np.random.rand(3, 2, 4)
curve_ref = np.random.rand(3, 2, 4)
field = np.random.rand(3, 2)
for policy in [gridpp.OneToOne, gridpp.Zero, gridpp.NearestSlope, gridpp.MeanSlope, gridpp.Unchanged]:
curve_fcst = np.random.rand(3, 2, 4)
curve_ref = np.random.rand(3, 2, 4)
field = np.random.rand(3, 2)
gridpp.apply_curve(field, curve_ref, curve_fcst, policy, policy)

def test_invalid_extrapolation_policy(self):
policy = -1
curve_fcst = np.random.rand(3, 2, 4)
curve_ref = np.random.rand(3, 2, 4)
field = np.random.rand(3, 2)
with self.assertRaises(ValueError) as e:
gridpp.apply_curve(field, curve_ref, curve_fcst, policy, policy)


Expand Down

0 comments on commit fc15fcd

Please sign in to comment.