From 21f2f557c91b7df2585837135b3ed3cce325a284 Mon Sep 17 00:00:00 2001 From: Nivedita Singh Date: Mon, 16 Mar 2026 17:07:38 +0000 Subject: [PATCH 1/3] added logic to skip file that doesn't exist --- scripts/world_bank/wdi/worldbank.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/scripts/world_bank/wdi/worldbank.py b/scripts/world_bank/wdi/worldbank.py index 126e4e281e..d8b3354066 100644 --- a/scripts/world_bank/wdi/worldbank.py +++ b/scripts/world_bank/wdi/worldbank.py @@ -255,9 +255,9 @@ def read_worldbank(iso3166alpha3, mode): if file.startswith("API"): file_to_open = file break - assert file_to_open is not None, \ - "Failed to find data for" + iso3166alpha3 - + if file_to_open is None: + logging.warning('Failed to find data for %s in the downloaded ZIP. Skipping.', iso3166alpha3) + return None df = None # Captures any text contained in double quotatations. line_match = re.compile(r"\"([^\"]*)\"") @@ -415,6 +415,9 @@ def download_indicator_data(worldbank_countries, indicator_codes, mode): for index, country_code in enumerate(worldbank_countries['ISO3166Alpha3']): country_df = read_worldbank(country_code, mode) + if country_df is None: + continue + # Remove unneccessary indicators. country_df = country_df[country_df['IndicatorCode'].isin( indicators_to_keep)] From 556a5897463388f1c50ab62b70dc2defc021d9c3 Mon Sep 17 00:00:00 2001 From: Nivedita Singh Date: Mon, 16 Mar 2026 17:21:15 +0000 Subject: [PATCH 2/3] added logic to skip file that doesn't exist --- scripts/world_bank/wdi/worldbank.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/world_bank/wdi/worldbank.py b/scripts/world_bank/wdi/worldbank.py index d8b3354066..d556fd04bf 100644 --- a/scripts/world_bank/wdi/worldbank.py +++ b/scripts/world_bank/wdi/worldbank.py @@ -256,7 +256,9 @@ def read_worldbank(iso3166alpha3, mode): file_to_open = file break if file_to_open is None: - logging.warning('Failed to find data for %s in the downloaded ZIP. Skipping.', iso3166alpha3) + logging.warning( + 'Failed to find data for %s in the downloaded ZIP. Skipping.', + iso3166alpha3) return None df = None # Captures any text contained in double quotatations. From 07273a1e1e23794760d3d8aab947acca09edc7c0 Mon Sep 17 00:00:00 2001 From: Nivedita Singh Date: Mon, 16 Mar 2026 18:31:32 +0000 Subject: [PATCH 3/3] modified code --- scripts/world_bank/wdi/worldbank.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/scripts/world_bank/wdi/worldbank.py b/scripts/world_bank/wdi/worldbank.py index d556fd04bf..dcb5d4757f 100644 --- a/scripts/world_bank/wdi/worldbank.py +++ b/scripts/world_bank/wdi/worldbank.py @@ -423,12 +423,15 @@ def download_indicator_data(worldbank_countries, indicator_codes, mode): # Remove unneccessary indicators. country_df = country_df[country_df['IndicatorCode'].isin( indicators_to_keep)] - # Map country codes to ISO. country_df['ISO3166Alpha3'] = country_code - # Add new row to main datframe. country_df_list.append(country_df) + # 3. Handle the empty list case OUTSIDE the loop + if not country_df_list: + logging.error("No data was downloaded for any country.") + # Return empty DF with expected columns to satisfy the rest of the pipeline + return pd.DataFrame(columns=['StatisticalVariable', 'Year', 'Value']) worldbank_dataframe = pd.concat(country_df_list) # Map indicator codes to unique Statistical Variable.