From 2ebe88e095a0b76ee37894517ab8c919b699aad9 Mon Sep 17 00:00:00 2001 From: bikegeek Date: Thu, 17 Oct 2024 13:41:31 -0600 Subject: [PATCH] Enclose call to the METcalcpy sum_stat module's calculate_statistic to capture error and log appropriately for success and failure --- .../equivalence_testing_bounds_series.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/metplotpy/plots/equivalence_testing_bounds/equivalence_testing_bounds_series.py b/metplotpy/plots/equivalence_testing_bounds/equivalence_testing_bounds_series.py index b944f569..1548dc9c 100644 --- a/metplotpy/plots/equivalence_testing_bounds/equivalence_testing_bounds_series.py +++ b/metplotpy/plots/equivalence_testing_bounds/equivalence_testing_bounds_series.py @@ -160,14 +160,22 @@ def _calculate_tost_paired(self, series_data_1: DataFrame, series_data_2: DataFr # calculate stat values for index, row in series_data_1.iterrows(): row_array = np.expand_dims(row.to_numpy(), axis=0) - stat_value = calculate_statistic(row_array, series_data_1.columns, + stat_value = calculate_statistic( row_array, series_data_1.columns, series_data_1["stat_name"][0].lower()) # save the value to the 'stat_value' column series_data_1.at[index, 'stat_value'] = stat_value + for index, row in series_data_2.iterrows(): row_array = np.expand_dims(row.to_numpy(), axis=0) - stat_value = calculate_statistic(row_array, series_data_2.columns, - series_data_2["stat_name"][0].lower()) + statistic_name = series_data_2["stat_name"][0].lower() + try: + logger.info(f"Calculating the '{statistic_name}' statistic using METcalcpy's sum_stat.py module, " + f"for data row: {index}.") + stat_value = calculate_statistic(row_array, series_data_2.columns, + statistic_name) + except RuntimeError: + logger.error(f"An error occurred while calculating the statistic '{statistic_name}'") + # save the value to the 'stat_value' column series_data_2.at[index, 'stat_value'] = stat_value