@@ -375,8 +375,9 @@ def _get_income_group(cntry_info, ref_year, shp_file):
375375 attribute for every country.
376376 """
377377 # check if file with income groups exists in SYSTEM_DIR, download if not
378+ fn_ig = os .path .join (os .path .abspath (SYSTEM_DIR ), 'OGHIST.xls' )
379+ dfr_wb = pd .DataFrame ()
378380 try :
379- fn_ig = os .path .join (os .path .abspath (SYSTEM_DIR ), 'OGHIST.xls' )
380381 if not glob .glob (fn_ig ):
381382 file_down = download_file (WORLD_BANK_INC_GRP )
382383 shutil .move (file_down , fn_ig )
@@ -387,8 +388,8 @@ def _get_income_group(cntry_info, ref_year, shp_file):
387388 except (IOError , requests .exceptions .ConnectionError ):
388389 LOGGER .warning ('Internet connection failed while downloading ' +
389390 'historical income groups.' )
390- dfr_wb = pd .DataFrame ()
391391
392+ list_records = list (shp_file .records ())
392393 for cntry_iso , cntry_val in cntry_info .items ():
393394 try :
394395 cntry_dfr = dfr_wb .loc [cntry_iso ]
@@ -401,13 +402,12 @@ def _get_income_group(cntry_info, ref_year, shp_file):
401402
402403 except (KeyError , IndexError ):
403404 # take value from natural earth repository
404- list_records = list (shp_file .records ())
405405 for info in list_records :
406406 if info .attributes ['ADM0_A3' ] == cntry_iso :
407407 close_inc = info .attributes ['INCOME_GRP' ]
408- try :
409- close_inc_val = INCOME_GRP_NE_TABLE [ int (close_inc [0 ])]
410- except ( KeyError , IndexError ) :
408+ break
409+ close_inc_val = INCOME_GRP_NE_TABLE . get ( int (close_inc [0 ]))
410+ if close_inc_val is None :
411411 LOGGER .error ("No income group for country %s found." ,
412412 cntry_iso )
413413 raise ValueError
0 commit comments