Skip to content

Commit

Permalink
Fix type for return_year in extreme.return_year_value (MHKiT-Software…
Browse files Browse the repository at this point in the history
…#225)

In an oversight in merging MHKiT-Software#193 the docstring was updated for the
type of return_year in return_year_value but the corresponding
assertion was not.

Tests for the types of the two input parameters have been added to
try to avoid a simular situation occuring the future.
  • Loading branch information
mbruggs authored and jmcvey3 committed Apr 14, 2023
1 parent 16aed26 commit b77e945
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion mhkit/loads/extreme.py
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,7 @@ def return_year_value(ppf, return_year, short_term_period_hr):
The value corresponding to the return period from the distribution.
"""
assert callable(ppf)
assert isinstance(return_year, int)
assert isinstance(return_year, (float, int))
assert isinstance(short_term_period_hr, (float, int))

p = 1 / (return_year * 365.25 * 24 / short_term_period_hr)
Expand Down
14 changes: 9 additions & 5 deletions mhkit/tests/loads/test_loads.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,17 @@ def test_mler_export_time_series(self):
assert_frame_equal(self.mler_ts, mler_ts, atol=0.0001)

def test_return_year_value(self):
return_years = [50, 50.0]
short_term_periods = [1, 1.0]
dist = stats.norm
return_year = 50
short_term_period = 1

val = loads.extreme.return_year_value(dist.ppf, return_year, short_term_period)
want = 4.5839339
self.assertAlmostEqual(want, val, 5)
for y in return_years:
for stp in short_term_periods:
with self.subTest(year=y, short_term=stp):
val = loads.extreme.return_year_value(
dist.ppf, y, stp)
want = 4.5839339
self.assertAlmostEqual(want, val, 5)

def test_longterm_extreme(self):
ste_1 = stats.norm
Expand Down

0 comments on commit b77e945

Please sign in to comment.