Skip to content

Commit d8b8e9a

Browse files
Raise ValueError in download_world_bank_indicator (#1050)
* Fix worldbank fallback by raising a ValueError instead of a RuntimeError
1 parent 4d2d690 commit d8b8e9a

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

climada/test/test_litpop_integr.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ def test_netherlands150_pass(self):
5353
self.assertEqual(ent.gdf.shape[0], 2829)
5454

5555
def test_BLM150_pass(self):
56-
"""Test from_countries for BLM at 150 arcsec, 2 data points"""
56+
"""Test from_countries for BLM at 150 arcsec, 2 data points
57+
The world bank doesn't provide data for Saint Barthélemy, fall back to natearth
58+
"""
5759
ent = lp.LitPop.from_countries("BLM", res_arcsec=150, reference_year=2016)
5860
self.assertEqual(ent.gdf.shape[0], 2)
5961

climada/util/finance.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ def download_world_bank_indicator(
216216
# Check if we received an error message
217217
try:
218218
if json_data[0]["message"][0]["id"] == "120":
219-
raise RuntimeError(
219+
raise ValueError(
220220
"Error requesting data from the World Bank API. Did you use the "
221221
"correct country code and indicator ID?"
222222
)

climada/util/test/test_finance.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,12 @@ def test_download_wb_data(self):
151151

152152
# Check errors raised
153153
with self.assertRaisesRegex(
154-
RuntimeError,
154+
ValueError,
155155
"Did you use the correct country code",
156156
):
157157
download_world_bank_indicator("Spain", "NY.GDP.MKTP.CD")
158158
with self.assertRaisesRegex(
159-
RuntimeError,
159+
ValueError,
160160
"Did you use the correct country code",
161161
):
162162
download_world_bank_indicator("ESP", "BogusIndicator")

0 commit comments

Comments
 (0)