From 280bd3131f522e797bab8c8a49fcfb742ac55730 Mon Sep 17 00:00:00 2001 From: Edward Small Date: Tue, 12 May 2020 12:17:49 +0100 Subject: [PATCH 1/2] Check we get a good error message if no historical data found --- ow_calibration/get_region/get_region_hist_locations.py | 6 +++--- .../get_region/get_region_hist_locations_test.py | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/ow_calibration/get_region/get_region_hist_locations.py b/ow_calibration/get_region/get_region_hist_locations.py index c4893275..57d54d87 100644 --- a/ow_calibration/get_region/get_region_hist_locations.py +++ b/ow_calibration/get_region/get_region_hist_locations.py @@ -25,6 +25,7 @@ from ow_calibration.get_region.data_functions.get_data import get_data from ow_calibration.get_region.data_functions.wrap_longitude import wrap_longitude + # pylint: disable=bare-except def get_region_hist_locations(pa_wmo_numbers, pa_float_name, config): """ @@ -66,9 +67,8 @@ def get_region_hist_locations(pa_wmo_numbers, pa_float_name, config): if grid_lat.__len__() == 0: - grid_lat = 999 - grid_long = 999 - grid_dates = 'NaN' + raise ValueError("get_region_hist_locations found no data for your specification. " + "Are your wmo_boxes files set up correctly?") else: diff --git a/ow_calibration/get_region/get_region_hist_locations_test.py b/ow_calibration/get_region/get_region_hist_locations_test.py index 1264a664..a7396fcf 100644 --- a/ow_calibration/get_region/get_region_hist_locations_test.py +++ b/ow_calibration/get_region/get_region_hist_locations_test.py @@ -84,12 +84,12 @@ def test_no_data(self): print("Testing that get_region_hist_locations returns expected values for no data") wmo_boxes_no_data = np.array([[3505, 0, 0, 0]]) - lat_no_data, long_no_data, age_no_data = get_region_hist_locations(wmo_boxes_no_data, - 'none', - self.config) - self.assertEqual(lat_no_data, long_no_data, "latitude and longitude should be equal (999)") - self.assertEqual(age_no_data, 'NaN', "age should be NaN") + with self.assertRaises(ValueError) as no_data: + get_region_hist_locations(wmo_boxes_no_data, 'none', self.config) + + self.assertTrue('get_region_hist_locations found no data for your specification. ' + 'Are your wmo_boxes files set up correctly?' in str(no_data.exception)) def test_can_choose_data(self): """ From 96e1f26b8a484cdf1a97627327363e7f5d08ae28 Mon Sep 17 00:00:00 2001 From: Edward Small Date: Tue, 12 May 2020 12:25:18 +0100 Subject: [PATCH 2/2] Remove unneccessary else statement --- ow_calibration/get_region/get_region_hist_locations.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ow_calibration/get_region/get_region_hist_locations.py b/ow_calibration/get_region/get_region_hist_locations.py index 57d54d87..6aa4a12f 100644 --- a/ow_calibration/get_region/get_region_hist_locations.py +++ b/ow_calibration/get_region/get_region_hist_locations.py @@ -70,10 +70,10 @@ def get_region_hist_locations(pa_wmo_numbers, pa_float_name, config): raise ValueError("get_region_hist_locations found no data for your specification. " "Are your wmo_boxes files set up correctly?") - else: - grid_long = wrap_longitude(grid_long) - # decimalise dates - grid_dates = change_dates(grid_dates) + + grid_long = wrap_longitude(grid_long) + # decimalise dates + grid_dates = change_dates(grid_dates) return grid_lat, grid_long, grid_dates