diff --git a/nannyml/drift/univariate/calculator.py b/nannyml/drift/univariate/calculator.py index 58e350f2..d996c047 100644 --- a/nannyml/drift/univariate/calculator.py +++ b/nannyml/drift/univariate/calculator.py @@ -343,13 +343,27 @@ def _calculate(self, data: pd.DataFrame, *args, **kwargs) -> Result: for column_name in self.continuous_column_names: for method in self._column_to_models_mapping[column_name]: - for k, v in _calculate_for_column(chunk.data, column_name, method).items(): - row[f'{column_name}_{method.column_name}_{k}'] = v + try: + for k, v in _calculate_for_column(chunk.data, column_name, method).items(): + row[f'{column_name}_{method.column_name}_{k}'] = v + except Exception as exc: + self._logger.error( + f"an unexpected exception occurred during calculation of method '{method.display_name}': " + f"{exc}" + ) + continue for column_name in self.categorical_column_names: for method in self._column_to_models_mapping[column_name]: - for k, v in _calculate_for_column(chunk.data, column_name, method).items(): - row[f'{column_name}_{method.column_name}_{k}'] = v + try: + for k, v in _calculate_for_column(chunk.data, column_name, method).items(): + row[f'{column_name}_{method.column_name}_{k}'] = v + except Exception as exc: + self._logger.error( + f"an unexpected exception occurred during calculation of method '{method.display_name}': " + f"{exc}" + ) + continue rows.append(row) diff --git a/nannyml/performance_calculation/calculator.py b/nannyml/performance_calculation/calculator.py index 60cc0c7d..294e6d8b 100644 --- a/nannyml/performance_calculation/calculator.py +++ b/nannyml/performance_calculation/calculator.py @@ -273,8 +273,13 @@ def _fit(self, reference_data: pd.DataFrame, *args, **kwargs) -> PerformanceCalc # data validation is performed during the _fit for each metric for metric in self.metrics: - metric.fit(reference_data=reference_data, chunker=self.chunker) - + try: + metric.fit(reference_data=reference_data, chunker=self.chunker) + except Exception as exc: + self._logger.error( + f"an unexpected error occurred when calculating metric '{metric.display_name}': {exc}" + ) + continue self.previous_reference_data = reference_data self.result = self._calculate(reference_data) @@ -349,9 +354,14 @@ def _calculate(self, data: pd.DataFrame, *args, **kwargs) -> Result: def _calculate_metrics_for_chunk(self, chunk: Chunk) -> Dict: chunk_records: Dict[str, Any] = {} for metric in self.metrics: - chunk_record = metric.get_chunk_record(chunk.data) - chunk_records.update(chunk_record) - + try: + chunk_record = metric.get_chunk_record(chunk.data) + chunk_records.update(chunk_record) + except Exception as exc: + self._logger.error( + f"an unexpected error occurred while calculating metric {metric.display_name}: {exc}" + ) + continue return chunk_records diff --git a/nannyml/performance_estimation/confidence_based/cbpe.py b/nannyml/performance_estimation/confidence_based/cbpe.py index c9167307..2bfa7287 100644 --- a/nannyml/performance_estimation/confidence_based/cbpe.py +++ b/nannyml/performance_estimation/confidence_based/cbpe.py @@ -412,9 +412,15 @@ def _estimate(self, data: pd.DataFrame, *args, **kwargs) -> Result: def _estimate_chunk(self, chunk: Chunk) -> Dict: chunk_records: Dict[str, Any] = {} for metric in self.metrics: - chunk_record = metric.get_chunk_record(chunk.data) - # add the chunk record to the chunk_records dict - chunk_records.update(chunk_record) + try: + chunk_record = metric.get_chunk_record(chunk.data) + # add the chunk record to the chunk_records dict + chunk_records.update(chunk_record) + except Exception as exc: + self._logger.error( + f"an unexpected error occurred while calculating metric {metric.display_name}: {exc}" + ) + continue return chunk_records def _fit_binary(self, reference_data: pd.DataFrame) -> CBPE: diff --git a/nannyml/performance_estimation/direct_loss_estimation/dle.py b/nannyml/performance_estimation/direct_loss_estimation/dle.py index e1ccac4a..fa88c1a3 100644 --- a/nannyml/performance_estimation/direct_loss_estimation/dle.py +++ b/nannyml/performance_estimation/direct_loss_estimation/dle.py @@ -299,7 +299,13 @@ def _fit(self, reference_data: pd.DataFrame, *args, **kwargs) -> Self: for metric in self.metrics: metric.categorical_column_names = categorical_feature_columns - metric.fit(reference_data) + try: + metric.fit(reference_data) + except Exception as exc: + self._logger.error( + f"an unexpected error occurred while calculating metric {metric.display_name}: {exc}" + ) + continue self.result = self._estimate(reference_data) self.result.data[('chunk', 'period')] = 'reference' @@ -374,8 +380,14 @@ def _estimate(self, data: pd.DataFrame, *args, **kwargs) -> Result: def _estimate_chunk(self, chunk: Chunk) -> Dict: estimates: Dict[str, Any] = {} for metric in self.metrics: - estimated_metric = metric.estimate(chunk.data) - sampling_error = metric.sampling_error(chunk.data) + try: + estimated_metric = metric.estimate(chunk.data) + sampling_error = metric.sampling_error(chunk.data) + except Exception as exc: + self._logger.error( + f"an unexpected error occurred while calculating metric {metric.display_name}: {exc}" + ) + continue upper_confidence_boundary = estimated_metric + 3 * sampling_error if metric.upper_threshold_value_limit is not None: