From 929d93b68d2843f1adc72a14f8fe6199477f6079 Mon Sep 17 00:00:00 2001 From: Avik Basu Date: Wed, 26 Jul 2023 14:45:57 -0400 Subject: [PATCH] chore: add data shape validation Signed-off-by: Avik Basu --- numalogic/models/threshold/_mahalanobis.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/numalogic/models/threshold/_mahalanobis.py b/numalogic/models/threshold/_mahalanobis.py index 6b996bcc..efbdaeb2 100644 --- a/numalogic/models/threshold/_mahalanobis.py +++ b/numalogic/models/threshold/_mahalanobis.py @@ -21,6 +21,7 @@ _INLIER: Final[int] = 0 _OUTLIER: Final[int] = 1 +_INPUT_DIMS = Final[int] = 2 class MahalanobisThreshold(BaseThresholdModel): @@ -87,7 +88,7 @@ def _chebyshev_k(p: float) -> float: @staticmethod def _validate_input(x: npt.NDArray[float]) -> None: """Validate the input matrix shape.""" - if x.ndim != 2: + if x.ndim != _INPUT_DIMS: raise InvalidDataShapeError(f"Input matrix should have 2 dims, given shape: {x.shape}.") def fit(self, x: npt.NDArray[float]) -> Self: