diff --git a/kats/detectors/cusum_detection.py b/kats/detectors/cusum_detection.py index 579a81ca..c7841ab0 100644 --- a/kats/detectors/cusum_detection.py +++ b/kats/detectors/cusum_detection.py @@ -525,7 +525,8 @@ def detector(self, **kwargs: Any) -> Sequence[CUSUMChangePoint]: None means the middle of the time series. change_directions: Optional; list; a list contain either or both 'increase' and 'decrease' to specify what type of change - want to detect. + want to detect, to point both directions can be also setted up + as empty list ([]), None or ["both"] interest_window: Optional; list, a list containing the start and end of interest windows where we will look for change points. Note that llr will still be calculated using all data @@ -572,8 +573,15 @@ def detector(self, **kwargs: Any) -> Sequence[CUSUMChangePoint]: ts = self.data.value.to_numpy() ts = ts.astype("float64") changes_meta = {} - - if change_directions is None: + if type(change_directions) is str: + change_directions = [change_directions] + + if ( + change_directions is None + or change_directions == [""] + or change_directions == ["both"] + or change_directions == [] + ): change_directions = ["increase", "decrease"] for change_direction in change_directions: @@ -1024,7 +1032,16 @@ def detector(self, **kwargs: Any) -> List[List[CUSUMChangePoint]]: ts_multi = ts_multi[:, np.newaxis] changes_meta_multi = {} - if change_directions is None: + + if type(change_directions) is str: + change_directions = [change_directions] + + if ( + change_directions is None + or change_directions == [""] + or change_directions == ["both"] + or change_directions == [] + ): change_directions = ["increase", "decrease"] for change_direction in change_directions: diff --git a/kats/tests/detectors/test_cusum_detection.py b/kats/tests/detectors/test_cusum_detection.py index e4dceca0..e9afbd89 100644 --- a/kats/tests/detectors/test_cusum_detection.py +++ b/kats/tests/detectors/test_cusum_detection.py @@ -95,7 +95,7 @@ def setUp(self) -> None: self.periodicity * self.total_cycles - 1, ], magnitude_quantile=1, - change_directions=["increase", "decrease"], + change_directions="both", delta_std_ratio=0, ) self.season_metadata = self.season_inc_trend_change_points[0] @@ -542,7 +542,7 @@ def setUp(self) -> None: ).detector() self.dec_change_points_int_window = CUSUMDetector( TimeSeriesData(df[["decrease", "time"]]) - ).detector(change_directions=["decrease"], interest_window=(35, 55)) + ).detector(change_directions="decrease", interest_window=(35, 55)) timeseries = TimeSeriesData(df) change_points_vectorized_ = VectorizedCUSUMDetector(timeseries).detector_()