Skip to content

Commit 4062317

Browse files
Merge pull request #47 from stared/patch-1
BUG: Parsing latitude and longitude in wb.get_countries
2 parents a37ecd6 + 564d30f commit 4062317

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

pandas_datareader/tests/test_wb.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ def test_wdi_get_countries(self):
104104
result = get_countries()
105105
self.assertTrue('Zimbabwe' in list(result['name']))
106106
self.assertTrue(len(result) > 100)
107+
self.assertTrue(pandas.notnull(result.latitude.mean()))
108+
self.assertTrue(pandas.notnull(result.longitude.mean()))
107109

108110
if __name__ == '__main__':
109111
nose.runmodule(argv=[__file__, '-vvs', '-x', '--pdb', '--pdb-failure'],

pandas_datareader/wb.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,9 @@ def _get_data(indicator="NY.GNS.ICTR.GN.ZS", country='US',
213213

214214
def get_countries():
215215
'''Query information about countries
216+
217+
Provides information such as:
218+
country code, region, income level, capital city, latitude and longitude
216219
'''
217220
url = 'http://api.worldbank.org/countries/?per_page=1000&format=json'
218221
with urlopen(url) as response:
@@ -223,6 +226,8 @@ def get_countries():
223226
data.incomeLevel = [x['value'] for x in data.incomeLevel]
224227
data.lendingType = [x['value'] for x in data.lendingType]
225228
data.region = [x['value'] for x in data.region]
229+
data.latitude = [float(x) if x != "" else np.nan for x in data.latitude]
230+
data.longitude = [float(x) if x != "" else np.nan for x in data.longitude]
226231
data = data.rename(columns={'id': 'iso3c', 'iso2Code': 'iso2c'})
227232
return data
228233

0 commit comments

Comments
 (0)