Skip to content
Snippets Groups Projects
Commit 6481fb26 authored by Raphael Sturgis's avatar Raphael Sturgis
Browse files

Merge branch '22-normalisation-should-raise-exception-when-bad-arguments-given' into 'develop'

Resolve "normalisation should raise exception when bad arguments given"

See merge request !15
parents 184ebc0e e837df89
No related branches found
No related tags found
2 merge requests!15Resolve "normalisation should raise exception when bad arguments given",!13Draft: Develop
......@@ -44,6 +44,9 @@ class AISPoints:
def normalize(self, min_max_features=(), standardization_features=(), third_quartile_features=(),
divide_by_value=(), divide_by_max=(), normalization_dict=None):
if normalization_dict is None:
if len(min_max_features) == len(standardization_features) == len(third_quartile_features) == len(
divide_by_value) == len(divide_by_max) == 0:
raise ValueError("All arguments are empty")
normalization_dict = {}
for f in min_max_features:
if f in self.df.columns:
......@@ -94,7 +97,7 @@ class AISPoints:
normalization_dict[f] = {'type': 'divide by max',
'maximum': maximum}
self.df[f] = self.df[f] / maximum
else:
elif type(normalization_dict) == dict:
for f in normalization_dict:
if f in self.df.columns:
if normalization_dict[f]['type'] == 'min-max':
......@@ -125,6 +128,8 @@ class AISPoints:
raise ValueError(
f"{normalization_dict[f]['type']} not a valid normalization method. Must be on of [min-max,"
f" standardization, 3rd quartile, divide by value]")
else:
raise ValueError("normalization_dict not a dictionary")
return normalization_dict
# New features
......
......@@ -216,6 +216,40 @@ class TestAISPositions(unittest.TestCase):
pd.testing.assert_frame_equal(expected.reset_index(drop=True), result.reset_index(drop=True),
check_exact=False, rtol=0.05)
def test_normalize_wrong_arguments_1(self):
ais_points = AISPoints(pd.DataFrame(
{
"cog": [i for i in range(0, 359, 10)],
"heading": [180 for _ in range(0, 359, 10)]
}
)
)
with self.assertRaises(ValueError):
ais_points.normalize(normalization_dict=None)
def test_normalize_wrong_arguments_2(self):
ais_points = AISPoints(pd.DataFrame(
{
"cog": [i for i in range(0, 359, 10)],
"heading": [180 for _ in range(0, 359, 10)]
}
)
)
with self.assertRaises(ValueError):
ais_points.normalize(normalization_dict=10)
def test_normalize_wrong_arguments_3(self):
ais_points = AISPoints(pd.DataFrame(
{
"cog": [i for i in range(0, 359, 10)],
"heading": [180 for _ in range(0, 359, 10)]
}
)
)
with self.assertRaises(ValueError):
ais_points.normalize(normalization_dict=[0, 1, 2, 3, 4])
def test_compute_drift(self):
ais_points = AISPoints(pd.DataFrame(
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment