Skip to content

Commit 5323dc1

Browse files
committed
Fix : Future year Timeouts in WorldBank IDS
1 parent ee1e0b2 commit 5323dc1

1 file changed

Lines changed: 30 additions & 8 deletions

File tree

statvar_imports/world_bank/worldbank_ids/download.py

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import os
1616
import sys
1717
import numpy as np
18+
import pandas as pd
1819
from absl import logging, flags, app
1920
# Import the required function after installing the package
2021
from bblocks import WorldBankData, DebtIDS
@@ -92,16 +93,37 @@
9293

9394
def main(_):
9495
# Itterating each list to download the respective data.
95-
for idx, indicator in enumerate(indicator_list):
96+
for idx, indicator_list_to_process in enumerate(indicator_list):
9697
# Creating an IDS object
9798
debt_id = DebtIDS()
98-
# Load the indicators.
99-
logging.info("Loaded data for%s", indicator)
100-
debt_id.load_data(indicators=indicator,
101-
start_year=FLAGS.start_year,
102-
end_year=FLAGS.end_year)
103-
# Get the data as a DataFrame
104-
df = debt_id.get_data()
99+
100+
all_data_frames = []
101+
102+
# Process indicators one by one to avoid crashing the whole batch
103+
for ind in indicator_list_to_process:
104+
try:
105+
logging.info("Loading data for %s", ind)
106+
debt_id.load_data(indicators=[ind],
107+
start_year=FLAGS.start_year,
108+
end_year=FLAGS.end_year)
109+
# Get the data for this specific indicator
110+
df_temp = debt_id.get_data()
111+
if df_temp is not None and not df_temp.empty:
112+
all_data_frames.append(df_temp)
113+
114+
# Reset debt_id for next indicator if needed or use a new one
115+
debt_id = DebtIDS()
116+
except Exception as e:
117+
logging.error("Failed to load data for %s: %s", ind, e)
118+
continue
119+
120+
if not all_data_frames:
121+
logging.warning("No data loaded for category: %s", indicator_listname[idx])
122+
continue
123+
124+
# Combine all successful indicators for this category
125+
df = pd.concat(all_data_frames, ignore_index=True)
126+
105127
try:
106128
# Extracting only the year part for data.
107129
df["YEARMOD"]=df["year"].dt.year

0 commit comments

Comments
 (0)