44
55from ml3_drift .analysis .analyzer .base import DataDriftAnalyzer
66from ml3_drift .analysis .report import Report
7- from ml3_drift .monitoring .base import MonitoringAlgorithm
7+ from ml3_drift .monitoring .base . base import MonitoringAlgorithm
88
99from ml3_drift .models .monitoring import (
1010 MonitoringOutput ,
@@ -74,7 +74,7 @@ def _single_scan_data(
7474 y_categorical : bool ,
7575 first_batch_indexes : tuple [int , int ],
7676 second_batch_indexes : tuple [int , int ],
77- ) -> tuple [MonitoringOutput , MonitoringOutput ]:
77+ ) -> tuple [MonitoringOutput | None , MonitoringOutput | None ]:
7878 """
7979 Inner helper method that performs a single scan of two batches
8080 """
@@ -95,16 +95,20 @@ def _single_scan_data(
9595 y_categorical ,
9696 second_batch_indexes ,
9797 )
98-
99- cont_algorithm = deepcopy (self .continuous_monitoring_algorithm ).fit (
100- first_batch_cont
101- )
102- cat_algorithm = deepcopy (self .categorical_monitoring_algorithm ).fit (
103- first_batch_cat
104- )
105-
106- cont_output = cont_algorithm .detect (second_batch_cont )[0 ]
107- cat_output = cat_algorithm .detect (second_batch_cat )[0 ]
98+ if len (continuous_columns_ids ) > 0 :
99+ cont_algorithm = deepcopy (self .continuous_monitoring_algorithm ).fit (
100+ first_batch_cont
101+ )
102+ cont_output = cont_algorithm .detect (second_batch_cont )[0 ]
103+ else :
104+ cont_output = None
105+ if len (categorical_columns_ids ) > 0 :
106+ cat_algorithm = deepcopy (self .categorical_monitoring_algorithm ).fit (
107+ first_batch_cat
108+ )
109+ cat_output = cat_algorithm .detect (second_batch_cat )[0 ]
110+ else :
111+ cat_output = None
108112
109113 return cont_output , cat_output
110114
@@ -149,7 +153,9 @@ def _scan_data(
149153 next_batch_indexes ,
150154 )
151155
152- if cont_output .drift_detected | cat_output .drift_detected :
156+ if (cont_output is not None and cont_output .drift_detected ) | (
157+ cat_output is not None and cat_output .drift_detected
158+ ):
153159 # if a drift is detected then, we close the current batch and open a new one
154160 merged_batches .append (
155161 (current_batch_start , current_batch_indexes [1 ] - 1 )
@@ -181,7 +187,10 @@ def _scan_data(
181187
182188 # if no drift is detected the two batches are considered to belong to the same distribution
183189 # and are added to the same distribution list
184- if not (cont_output .drift_detected | cat_output .drift_detected ):
190+ if not (
191+ (cont_output is not None and cont_output .drift_detected )
192+ | (cat_output is not None and cat_output .drift_detected )
193+ ):
185194 same_distributions [pair [0 ]].append (pair [1 ])
186195
187196 return Report (concepts = merged_batches , same_distributions = same_distributions )
0 commit comments