8
8
9
9
from pandas_datareader .wb import (search , download , get_countries ,
10
10
get_indicators , WorldBankReader )
11
- from pandas_datareader .compat import PANDAS_0170 , PANDAS_0160
12
11
13
12
14
13
class TestWB (tm .TestCase ):
@@ -56,17 +55,12 @@ def test_wdi_download(self):
56
55
expected = pd .DataFrame (expected )
57
56
# Round, to ignore revisions to data.
58
57
expected = np .round (expected , decimals = - 3 )
59
- if PANDAS_0170 :
60
- expected = expected .sort_index ()
61
- else :
62
- expected = expected .sort ()
58
+ expected = expected .sort_index ()
63
59
64
60
result = download (country = cntry_codes , indicator = inds ,
65
61
start = 2003 , end = 2004 , errors = 'ignore' )
66
- if PANDAS_0170 :
67
- result = result .sort_index ()
68
- else :
69
- result = result .sort ()
62
+ result = result .sort_index ()
63
+
70
64
# Round, to ignore revisions to data.
71
65
result = np .round (result , decimals = - 3 )
72
66
@@ -76,10 +70,8 @@ def test_wdi_download(self):
76
70
# pass start and end as string
77
71
result = download (country = cntry_codes , indicator = inds ,
78
72
start = '2003' , end = '2004' , errors = 'ignore' )
79
- if PANDAS_0170 :
80
- result = result .sort_index ()
81
- else :
82
- result = result .sort ()
73
+ result = result .sort_index ()
74
+
83
75
# Round, to ignore revisions to data.
84
76
result = np .round (result , decimals = - 3 )
85
77
tm .assert_frame_equal (result , expected )
@@ -94,30 +86,21 @@ def test_wdi_download_str(self):
94
86
expected = pd .DataFrame (expected )
95
87
# Round, to ignore revisions to data.
96
88
expected = np .round (expected , decimals = - 3 )
97
- if PANDAS_0170 :
98
- expected = expected .sort_index ()
99
- else :
100
- expected = expected .sort ()
89
+ expected = expected .sort_index ()
101
90
102
91
cntry_codes = 'JP'
103
92
inds = 'NY.GDP.PCAP.CD'
104
93
result = download (country = cntry_codes , indicator = inds ,
105
94
start = 2000 , end = 2004 , errors = 'ignore' )
106
- if PANDAS_0170 :
107
- result = result .sort_index ()
108
- else :
109
- result = result .sort ()
95
+ result = result .sort_index ()
110
96
result = np .round (result , decimals = - 3 )
111
97
112
98
expected .index .names = ['country' , 'year' ]
113
99
tm .assert_frame_equal (result , expected )
114
100
115
101
result = WorldBankReader (inds , countries = cntry_codes ,
116
102
start = 2000 , end = 2004 , errors = 'ignore' ).read ()
117
- if PANDAS_0170 :
118
- result = result .sort_index ()
119
- else :
120
- result = result .sort ()
103
+ result = result .sort_index ()
121
104
result = np .round (result , decimals = - 3 )
122
105
tm .assert_frame_equal (result , expected )
123
106
@@ -126,30 +109,28 @@ def test_wdi_download_error_handling(self):
126
109
inds = 'NY.GDP.PCAP.CD'
127
110
128
111
with tm .assertRaisesRegexp (ValueError , "Invalid Country Code\\ (s\\ ): XX" ):
129
- result = download (country = cntry_codes , indicator = inds ,
130
- start = 2003 , end = 2004 , errors = 'raise' )
112
+ download (country = cntry_codes , indicator = inds ,
113
+ start = 2003 , end = 2004 , errors = 'raise' )
131
114
132
- if PANDAS_0160 :
133
- # assert_produces_warning doesn't exists in prior versions
134
- with self .assert_produces_warning ():
135
- result = download (country = cntry_codes , indicator = inds ,
136
- start = 2003 , end = 2004 , errors = 'warn' )
137
- self .assertTrue (isinstance (result , pd .DataFrame ))
138
- self .assertEqual (len (result ), 2 )
115
+ # assert_produces_warning doesn't exists in prior versions
116
+ with self .assert_produces_warning ():
117
+ result = download (country = cntry_codes , indicator = inds ,
118
+ start = 2003 , end = 2004 , errors = 'warn' )
119
+ self .assertTrue (isinstance (result , pd .DataFrame ))
120
+ self .assertEqual (len (result ), 2 )
139
121
140
122
cntry_codes = ['USA' ]
141
123
inds = ['NY.GDP.PCAP.CD' , 'BAD_INDICATOR' ]
142
124
143
125
with tm .assertRaisesRegexp (ValueError , "The provided parameter value is not valid\\ . Indicator: BAD_INDICATOR" ):
126
+ download (country = cntry_codes , indicator = inds ,
127
+ start = 2003 , end = 2004 , errors = 'raise' )
128
+
129
+ with self .assert_produces_warning ():
144
130
result = download (country = cntry_codes , indicator = inds ,
145
- start = 2003 , end = 2004 , errors = 'raise' )
146
-
147
- if PANDAS_0160 :
148
- with self .assert_produces_warning ():
149
- result = download (country = cntry_codes , indicator = inds ,
150
- start = 2003 , end = 2004 , errors = 'warn' )
151
- self .assertTrue (isinstance (result , pd .DataFrame ))
152
- self .assertEqual (len (result ), 2 )
131
+ start = 2003 , end = 2004 , errors = 'warn' )
132
+ self .assertTrue (isinstance (result , pd .DataFrame ))
133
+ self .assertEqual (len (result ), 2 )
153
134
154
135
def test_wdi_download_w_retired_indicator (self ):
155
136
0 commit comments