From aa0a80a69b7ae3c3e4995e79ca14c3e23f5397fa Mon Sep 17 00:00:00 2001 From: Aayush Seth Date: Fri, 6 Sep 2024 14:59:15 -0700 Subject: [PATCH 1/2] Throw exception if negative length requested --- src/seer/anomaly_detection/detectors/mp_utils.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/seer/anomaly_detection/detectors/mp_utils.py b/src/seer/anomaly_detection/detectors/mp_utils.py index bf84f34d9..fd6baf87c 100644 --- a/src/seer/anomaly_detection/detectors/mp_utils.py +++ b/src/seer/anomaly_detection/detectors/mp_utils.py @@ -42,6 +42,8 @@ def get_mp_dist_from_mp( mp_dist = normalizer.normalize(mp_dist) if pad_to_len is not None: + if pad_to_len - len(mp_dist) < 0: + raise Exception("Requested length should be greater than current mp_dist") nan_value_count = np.empty(pad_to_len - len(mp_dist)) nan_value_count.fill(np.nan) mp_dist_updated = np.concatenate((nan_value_count, mp_dist)) From f51a5f518845002bb218f4be47af78bf2dcb5b79 Mon Sep 17 00:00:00 2001 From: Aayush Seth Date: Fri, 6 Sep 2024 15:25:07 -0700 Subject: [PATCH 2/2] Fix message --- src/seer/anomaly_detection/detectors/mp_utils.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/seer/anomaly_detection/detectors/mp_utils.py b/src/seer/anomaly_detection/detectors/mp_utils.py index fd6baf87c..5dfe2571d 100644 --- a/src/seer/anomaly_detection/detectors/mp_utils.py +++ b/src/seer/anomaly_detection/detectors/mp_utils.py @@ -42,8 +42,10 @@ def get_mp_dist_from_mp( mp_dist = normalizer.normalize(mp_dist) if pad_to_len is not None: - if pad_to_len - len(mp_dist) < 0: - raise Exception("Requested length should be greater than current mp_dist") + if pad_to_len < len(mp_dist): + raise Exception( + "Requested length should be greater than or equal to current mp_dist" + ) nan_value_count = np.empty(pad_to_len - len(mp_dist)) nan_value_count.fill(np.nan) mp_dist_updated = np.concatenate((nan_value_count, mp_dist))