From adf7b078e320fe6069daf284f65413b3fed31a06 Mon Sep 17 00:00:00 2001 From: bikegeek Date: Thu, 21 Dec 2023 16:30:30 -0700 Subject: [PATCH 1/3] Issue #329 return 0 if negative BCMSE value is calculated --- metcalcpy/util/sl1l2_statistics.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/metcalcpy/util/sl1l2_statistics.py b/metcalcpy/util/sl1l2_statistics.py index 9324a0dd..12508b45 100644 --- a/metcalcpy/util/sl1l2_statistics.py +++ b/metcalcpy/util/sl1l2_statistics.py @@ -524,10 +524,13 @@ def calculate_bcmse(input_data, columns_names, aggregation=False): """ warnings.filterwarnings('error') try: + mse = calculate_mse(input_data, columns_names, aggregation) me = calculate_me(input_data, columns_names, aggregation) result = mse - me ** 2 result = round_half_up(result, PRECISION) + if result < 0: + return 0. except (TypeError, Warning): result = None warnings.filterwarnings('ignore') From b44ed449ca511dbf231881abaa8a80e9a9282b8e Mon Sep 17 00:00:00 2001 From: bikegeek Date: Thu, 21 Dec 2023 16:31:33 -0700 Subject: [PATCH 2/3] Issue #329 add test for calculate_bcmse() in the sl1l2_statistics module --- test/test_sl1l2.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 test/test_sl1l2.py diff --git a/test/test_sl1l2.py b/test/test_sl1l2.py new file mode 100644 index 00000000..2cbce584 --- /dev/null +++ b/test/test_sl1l2.py @@ -0,0 +1,22 @@ +import numpy as np +import pytest + +from metcalcpy.util import sl1l2_statistics as sl1l2 + +def test_calculate_bcmse(): + # Test that negative BCMSE values are no longer returned. + input_data_list = [] + + # These data produce negative BCMSE values. Test that the modified code no longer returns negative values + # for the BCMSE. + input_data_list.append(np.array([[4.37978400e+01, 4.70115800e+01, 1.91825108e+03, 2.21008843e+03, 2.05900571e+03, 1.00000000e+00]])) + input_data_list.append(np.array([[8.66233900e+01, 4.83037900e+01, 7.50361146e+03, 2.33325660e+03, 4.18423840e+03, 1.00000000e+00]])) + input_data_list.append(np.array([[3.68089000e+01, 1.64253370e+02, 1.35489535e+03, 2.69791703e+04, 6.04598647e+03, 1.00000000e+00]])) + columns_names = np.array(['fbar', 'obar', 'ffbar', 'oobar', 'fobar', 'total'], dtype='= 0. + + + From a176c2b1d8d02a61f04fb09e20a67ff3961d432c Mon Sep 17 00:00:00 2001 From: bikegeek Date: Thu, 21 Dec 2023 16:35:38 -0700 Subject: [PATCH 3/3] Issue #392 added test_sl1l2.py to the list of pytests to run --- .github/workflows/unit_tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/unit_tests.yml b/.github/workflows/unit_tests.yml index 8a83305a..2a41ae92 100644 --- a/.github/workflows/unit_tests.yml +++ b/.github/workflows/unit_tests.yml @@ -64,6 +64,7 @@ jobs: pytest test_utils.py pytest test_validate_mv_python.py pytest test_future_warnings.py + pytest test_sl1l2.py coverage run -m pytest test_agg_eclv.py test_agg_stats_and_boot.py test_agg_stats_with_groups.py test_calc_difficulty_index.py test_convert_lon_indices.py test_event_equalize.py test_event_equalize_against_values.py test_lon_360_to_180.py test_statistics.py test_tost_paired.py test_utils.py test_future_warnings.py coverage html