Skip to content

Commit

Permalink
removed type error from metrics and metrics always return tuple even …
Browse files Browse the repository at this point in the history
…if None. Ensures the same format for all metrics. Tests updated.
  • Loading branch information
EvanKomp committed Mar 15, 2021
1 parent 5d3a304 commit 72a26f3
Showing 1 changed file with 3 additions and 29 deletions.
32 changes: 3 additions & 29 deletions gandy/tests/test_metrics/test_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,6 @@ def test_calculate(self):
subject = metrics.MSE(predictions=np.array([0, 1, 2]),
real="0, 1, 2").calculate()

# failure case: Uncertainties given when none expected
with self.assertRaises(TypeError):
subject = metrics.MSE(predictions=np.array([0, 1, 2]),
real=np.array([0, 1, 2]),
uncertainties=np.array([0, 0.5, 1])).\
calculate()

# check to make sure necessary attributes are inputted
subject = metrics.MSE(predictions=np.array([0, 1, 2]),
real=np.array([0, 1, 2]))
Expand Down Expand Up @@ -75,13 +68,6 @@ def test_calculate(self):
subject = metrics.RMSE(predictions=np.array([0, 1, 2]),
real="0, 1, 2").calculate()

# failure case: Uncertainties given when none expected
with self.assertRaises(TypeError):
subject = metrics.RMSE(predictions=np.array([0, 1, 2]),
real=np.array([0, 1, 2]),
uncertainties=np.array([0, 0.5, 1])).\
calculate()

# check to make sure necessary attributes are inputted
subject = metrics.RMSE(predictions=np.array([0, 1, 2]),
real=np.array([0, 1, 2]))
Expand Down Expand Up @@ -109,12 +95,6 @@ def test_calculate(self):
subject = metrics.F1(predictions=np.array([0, 1, 2]),
real="0, 1, 2").calculate()

# failure case: Uncertainties given when none expected
with self.assertRaises(TypeError):
subject = metrics.F1(predictions=np.array([0, 1, 2]),
real=np.array([0, 1, 2]),
uncertainties=np.array([0, 0.5, 1])).\
calculate()

# check to make sure necessary attributes are inputted
subject = metrics.F1(predictions=np.array([0, 1, 2]),
Expand All @@ -125,7 +105,7 @@ def test_calculate(self):
self.assertTrue(subject.uncertainties is None)

# check to make sure output is correct type
self.assertTrue(isinstance(subject.calculate(), (float, int)))
self.assertTrue(isinstance(subject.calculate(), tuple))


class TestAccuracy(unittest.TestCase):
Expand All @@ -143,12 +123,6 @@ def test_calculate(self):
subject = metrics.Accuracy(predictions=np.array([0, 1, 2]),
real="0, 1, 2").calculate()

# failure case: Uncertainties given when none expected
with self.assertRaises(TypeError):
subject = metrics.Accuracy(predictions=np.array([0, 1, 2]),
real=np.array([0, 1, 2]),
uncertainties=np.array([0, 0.5, 1])).\
calculate()

# check to make sure necessary attributes are inputted
subject = metrics.Accuracy(predictions=np.array([0, 1, 2]),
Expand All @@ -159,7 +133,7 @@ def test_calculate(self):
self.assertTrue(subject.uncertainties is None)

# check to make sure output is correct type
self.assertTrue(isinstance(subject.calculate(), (float, int)))
self.assertTrue(isinstance(subject.calculate(), tuple))


class TestUCP(unittest.TestCase):
Expand Down Expand Up @@ -203,4 +177,4 @@ def test_calculate(self):
self.assertTrue(subject.uncertainties is not None)

# check to make sure output is correct type
self.assertTrue(isinstance(subject.calculate(), (float, int)))
self.assertTrue(isinstance(subject.calculate(), tuple))

0 comments on commit 72a26f3

Please sign in to comment.