#NEWLINE# def download( country = None , indicator = None , start = 2003 , end = 2005 , errors = 'warn' ) : #NEWLINE# #INDENT# "\n    Download data series from the World Bank's World Development Indicators\n\n    Parameters\n    ----------\n\n    indicator: string or list of strings\n        taken from the ``id`` field in ``WDIsearch()``\n\n    country: string or list of strings.\n        ``all`` downloads data for all countries\n        2 or 3 character ISO country codes select individual\n        countries (e.g.``US``,``CA``) or (e.g.``USA``,``CAN``).  The codes\n        can be mixed.\n\n        The two ISO lists of countries, provided by wikipedia, are hardcoded\n        into pandas as of 11/10/2014.\n\n    start: int\n        First year of the data series\n\n    end: int\n        Last year of the data series (inclusive)\n\n    errors: str {'ignore', 'warn', 'raise'}, default 'warn'\n        Country codes are validated against a hardcoded list.  This controls\n        the outcome of that validation, and attempts to also apply\n        to the results from world bank.\n\n        errors='raise', will raise a ValueError on a bad country code.\n\n    Returns\n    -------\n\n    ``pandas`` DataFrame with columns: country, iso_code, year,\n    indicator value.\n\n    " #NEWLINE# if ( country is None ) : #NEWLINE# #INDENT# country = [ 'MX' , 'CA' , 'US' ] #NEWLINE# #UNINDENT# if ( indicator is None ) : #NEWLINE# #INDENT# indicator = [ 'NY.GDP.MKTP.CD' , 'NY.GNS.ICTR.ZS' ] #NEWLINE# #UNINDENT# if ( type ( country ) == str ) : #NEWLINE# #INDENT# country = [ country ] #NEWLINE# #UNINDENT# bad_countries = np . setdiff1d ( country , country_codes ) #NEWLINE# if ( len ( bad_countries ) > 0 ) : #NEWLINE# #INDENT# tmp = ', ' . join ( bad_countries ) #NEWLINE# if ( errors == 'raise' ) : #NEWLINE# #INDENT# raise ValueError ( ( 'Invalid Country Code(s): %s' % tmp ) ) #NEWLINE# #UNINDENT# if ( errors == 'warn' ) : #NEWLINE# #INDENT# warnings . warn ( ( 'Non-standard ISO country codes: %s' % tmp ) ) #NEWLINE# #UNINDENT# #UNINDENT# if ( type ( indicator ) == str ) : #NEWLINE# #INDENT# indicator = [ indicator ] #NEWLINE# #UNINDENT# data = [ ] #NEWLINE# bad_indicators = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for ind in indicator : #NEWLINE# #INDENT# ( one_indicator_data , msg ) = _get_data ( ind , country , start , end ) #NEWLINE# if ( msg == 'Success' ) : #NEWLINE# #INDENT# data . append ( one_indicator_data ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# bad_indicators [ ind ] = msg #NEWLINE# #UNINDENT# #UNINDENT# if ( len ( bad_indicators . keys ( ) ) > 0 ) : #NEWLINE# #INDENT# bad_ind_msgs = [ ( ( errors + ' : ' ) + m ) for ( i , m ) in bad_indicators . items ( ) ] #NEWLINE# bad_ind_msgs = '\n\n' . join ( bad_ind_msgs ) #NEWLINE# bad_ind_msgs = ( '\n\nInvalid Indicators:\n\n%s' % bad_ind_msgs ) #NEWLINE# if ( errors == 'raise' ) : #NEWLINE# #INDENT# raise ValueError ( bad_ind_msgs ) #NEWLINE# #UNINDENT# if ( errors == 'warn' ) : #NEWLINE# #INDENT# warnings . warn ( bad_ind_msgs ) #NEWLINE# #UNINDENT# #UNINDENT# if ( len ( data ) > 0 ) : #NEWLINE# #INDENT# out = reduce ( ( lambda x , y : x . merge ( y , how = 'outer' ) ) , data ) #NEWLINE# out = out . drop ( 'iso_code' , axis = 1 ) #NEWLINE# out = out . set_index ( [ 'country' , 'year' ] ) #NEWLINE# out = out . _convert ( datetime = True , numeric = True ) #NEWLINE# return out #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# msg = 'No indicators returned data.' #NEWLINE# if ( errors == 'ignore' ) : #NEWLINE# #INDENT# msg += "  Set errors='warn' for more information." #NEWLINE# #UNINDENT# raise ValueError ( msg )