Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hotfix/fix-edebt: Patches economy/edebt and updates tests #4981

Merged
merged 1 commit into from
May 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions openbb_terminal/economy/commodity_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,26 @@ def get_debt() -> pd.DataFrame:
"""
url = "https://en.wikipedia.org/wiki/List_of_countries_by_external_debt"
response = request(url, headers={"User-Agent": get_user_agent()})
df = pd.read_html(response.text)[1]
df = pd.read_html(response.content)[0]
df = df.rename(
columns={
"Country/Region": "Country",
"External debtUS dollars": "Debt",
"External debt US dollars": "USD Debt",
"Per capitaUS dollars": "Per Capita",
"External debt US dollars": "Debt",
"Per capita US dollars": "Per Capita",
"Per capita US dollars": "USD Per Capita",
"Date": "As Of",
}
)
df = df.drop(["Date", "% of GDP"], axis=1)
df["Debt"] = df["Debt"].apply(lambda x: format_number(x))
df["Rank"] = df["Debt"].rank(ascending=False).astype(int)
indexes = ["Rank", "Country", "Per Capita", "Debt"]
df["USD Debt"] = df["USD Debt"].apply(lambda x: format_number(x)).astype(int)
df["USD Per Capita"] = df["USD Per Capita"].astype(int)
df["Rank"] = df["USD Debt"].rank(ascending=False).astype(int)
date = df["As Of"].astype(str)
dates = []
for i in date.index:
dates.append(date[i].split("[")[0])
df["As Of"] = dates
df["As Of"] = df["As Of"].str.replace("31 September", "30 September")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is odd 👀

indexes = ["Rank", "As Of", "Country", "USD Per Capita", "USD Debt", "% of GDP"]
df = df[indexes]

return df

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
,Rank,As Of,Country,USD Per Capita,USD Debt,% of GDP
0,1,January 2023,United States,94188,31000000000000,121.08
1,2,June 2022,United Kingdom,129203,8730000000000,273.06
2,3,June 2022,France,107245,7040000000000,253.35
3,4,June 2022,Germany,77607,6460000000000,160.35
4,5,June 2022,Japan,34841,4360000000000,101.41
5,7,June 2022,China,1866,2640000000000,14.39
6,8,31 December 2017,Italy,42300,2510000000000,141.0
7,9,31 December 2017,Spain,48700,2260000000000,170.0
8,6,31 December 2017,Canada,52300,3200000000000,143.0
9,10,30 September 2020,Australia,71906,1830000000000,130.0
10,11,31 December 2017,Switzerland,213100,1820000000000,285.0
11,12,30 June 2021,Singapore,231000,1670000000000,471.0
12,13,30 June 2017,Belgium,112000,1280000000000,269.0
13,14,January 2023,Mexico,3300,769000000000,51.7
14,15,31 December 2020,Austria,84061,757000000000,165.0
15,16,June 2022,Norway,132676,721000000000,133.4
16,17,September 2022,South Korea,7500,719000000000,48.1
17,18,31 March 2022,Finland,24578,613900000000,218.0
18,19,September 2022,India,437,610500000000,19.2
19,20,30 September 2017,Brazil,3200,556000000000,38.0
20,21,December 2021,Netherlands,26540,555000000000,52.0
21,22,January 2023,Indonesia,1431,518000000000,39.5
22,23,30 June 2017,Denmark,85700,492000000000,158.0
23,24,1 September 2021,Russia,3700,489000000000,32.0
24,25,31 March 2022 ,Turkey,5155,444000000000,55.0
25,26,30 September 2022,Argentina,6037,382000000000,79.3
26,27,September 2022,Greece,42800,350000000000,175.7
27,28,December 2022,Poland,9500,344000000000,49.3
28,29,December 2022,Portugal,39478,292000000000,113.9
29,30,January 2023,Thailand,2170,285000000000,53.6
30,31,January 2023,Philippines,3623,251000000000,60.9
31,32,December 2022,Malaysia,6800,245000000000,60.4
32,33,31 December 2017,Ireland,49000,228000000000,701.0
33,34,30 June 2021,Ukraine,2200,225000000000,81.0
34,35,31 December 2016 est.,United Arab Emirates,23500,220000000000,59.0
35,36,31 December 2016 est.,Saudi Arabia,6100,201000000000,31.0
36,37,30 June 2018,Mauritius,148000,200000000000,2.01
37,38,30 June 2018,Taiwan,7400,199000000000,28.0
38,39,31 March 2020,New Zealand,38400,192000000000,90.0
39,40,31 March 2019,Chile,9771,187000000000,82.0
40,41,31 January 2015 est.,Puerto Rico (United States),47800,167000000000,164.0
41,41,31 March 2017,Kazakhstan,9100,167000000000,91.0
42,43,31 December 2016 est.,Qatar,68100,159000000000,83.0
43,44,March 2022 est.,Egypt,700,158000000000,34.0
44,45,30 June 2017,Hungary,15000,148000000000,160.0
45,46,31 December 2016,South Africa,2600,143000000000,57.0
46,47,December 2021,Vietnam,500,142000000000,39.1
47,48,31 December 2016,Czech Republic,13000,138000000000,76.0
48,49,30 September 2021,Pakistan,554,122000000000,43.0
49,50,31 January 2017,Colombia,2500,121000000000,57.0
50,51,30 June 2017,Cyprus,97200,120000000000,849.0
51,52,30 September 2015,Venezuela,3500,111000000000,23.0
52,53,31 July 2017,Romania,5100,109000000000,58.0
53,54,30 June 2017,Malta,223000,96300000000,691.0
54,55,30 september 2022,Sweden,94330,94900000000,23.0
55,56,30 June 2017,Israel,10700,89400000000,33.0
56,57,30 June 2017,Slovakia,15900,86600000000,112.0
57,58,16 October 2021,Bangladesh,460,78400000000,22.0
58,59,31 December 2016,Peru,2300,74700000000,44.0
59,60,31 December 2016 est.,Iraq,1800,68000000000,44.0
60,61,1 March 2022,Morocco,1400,63700000000,46.0
61,62,30 April 2020,Slovenia,25000,52000000000,104.0
62,63,31 December 2016 est.,Kuwait,11700,47900000000,51.0
63,64,31 December 2016,Sri Lanka,2200,46600000000,68.0
64,65,30 June 2017,Croatia,10700,46100000000,74.0
65,66,31 December 2015,Sudan,1100,45000000000,121.0
66,67,30 June 2017,Latvia,21200,41100000000,126.0
67,68,31 January 2018,Bulgaria,5700,40400000000,63.0
68,69,30 April 2022,Lebanon,6000,39600000000,220.0
69,70,30 June 2017,Belarus,4000,39000000000,66.0
70,71,31 December 2016 est.,Angola,1400,37700000000,41.0
71,72,31 August 2017,Ecuador,2100,36700000000,57.0
72,73,30 June 2017,Lithuania,12700,36400000000,74.0
73,74,30 June 2017,Serbia,3200,28000000000,62.0
74,75,30 June 2017,Jordan,3400,27800000000,83.0
75,76,31 December 2016 est.,Cuba,2300,26300000000,34.0
76,77,31 December 2016,Uruguay,7600,26100000000,50.0
77,77,31 December 2016 est.,Dominican Republic,2400,26100000000,36.0
78,79,30 June 2017,Mongolia,7800,25200000000,245.0
79,80,31 December 2012,Tunisia,2200,25100000000,97.0
80,81,31 December 2016 est.,Costa Rica,5100,24900000000,43.0
81,82,30 June 2017,Iceland,72700,24400000000,81.0
82,83,31 December 2016 est.,Ethiopia,220,22500000000,32.0
83,84,30 June 2017,Kenya,370,22200000000,26.0
84,85,31 December 2016 est.,Papua New Guinea,2800,22000000000,111.0
85,86,31 December 2016,Trinidad & Tobago,15700,21500000000,76.0
86,87,31 December 2016 est.,Ghana,700,21200000000,30.0
87,87,31 December 2016 est.,Bahrain,14900,21200000000,66.0
88,89,31 December 2016 est.,Oman,4400,20900000000,35.0
89,90,31 December 2016,Estonia,15700,20500000000,89.0
90,91,31 December 2016 est.,Guatemala,1100,19100000000,28.0
91,92,31 December 2014 est.,Palau,846000,18400000000,6.21
92,93,28 February 2018,Panama,4400,18300000000,157.0
93,94,31 December 2013 est.,Bahamas,44200,17600000000,194.0
94,95,31 December 2016 est.,Jamaica,6000,16800000000,122.0
95,96,30 June 2010 est.,Monaco,434000,16500000000,240.0
96,97,30 June 2017,Georgia,3900,16400000000,128.0
97,98,31 December 2016,Paraguay,2400,16100000000,54.0
98,99,31 December 2016 est.,Tanzania,280,15900000000,34.0
99,100,31 December 2016 est.,Uzbekistan,500,15800000000,24.0
100,101,30 June 2017,Nigeria,60,15000000000,2.0
101,102,31 December 2016 est.,El Salvador,2400,14900000000,56.0
102,103,31 December 2016 est.,Laos,1700,12000000000,53.0
103,104,31 December 2016 est.,Nicaragua,1800,11100000000,83.0
104,105,31 December 2016 est.,Zimbabwe,670,10900000000,77.0
105,106,31 March 2020 ,Luxembourg,114704,10600000000,22.1
106,107,31 December 2020,Albania,3634,10500000000,66.0
107,108,31 December 2015,Ivory Coast,420,10000000000,24.0
108,109,31 December 2016,Cambodia,600,9820000000,57.0
109,110,31 December 2016 est.,Mozambique,320,9550000000,72.0
110,111,31 December 2016 est.,Zambia,540,9270000000,45.0
111,112,31 December 2016 est.,Honduras,1000,8040000000,38.0
112,113,31 December 2016,Kyrgyzstan,1300,7870000000,112.0
113,114,31 December 2016,North Macedonia,3700,7650000000,73.0
114,115,31 December 2016 est.,Cameroon,300,7380000000,24.0
115,116,31 January 2015,Yemen,260,7190000000,21.0
116,117,31 December 2016 est.,Iran,90,7120000000,2.0
117,118,31 December 2016,Azerbaijan,1300,6910000000,22.0
118,119,31 December 2016,Moldova,1600,6590000000,70.0
119,120,31 December 2016 est.,Namibia,2500,6520000000,64.0
120,122,31 December 2015,Bolivia,600,6340000000,33.0
121,123,31 December 2016 est.,Uganda,150,6240000000,24.0
122,124,31 December 2016 est.,Senegal,390,6190000000,42.0
123,125,31 December 2020,Armenia,2043,6050000000,102.0
124,121,31 December 2015,Myanmar,120,6400000000,17.0
125,126,31 December 2016 est.,Syria,300,5920000000,24.0
126,127,31 December 2016 est.,Democratic Republic of the Congo,70,5330000000,13.0
127,128,31 December 2016 est.,Gabon,2900,5160000000,35.0
128,129,2013 est.,North Korea,200,5000000000,18.0
129,130,31 December 2016 est.,Republic of the Congo,1000,4820000000,55.0
130,131,30 June 2017,Bosnia and Herzegovina,1300,4720000000,23.0
131,132,2010 est.,Barbados,15700,4490000000,100.0
132,133,26 March 2021,Montenegro,6742,4410000000,151.0
133,134,31 December 2016 est.,Madagascar,160,4010000000,41.0
134,135,31 December 2019,Algeria,89,3840000000,2.0
135,136,31 December 2016 est.,Mali,200,3630000000,26.0
136,137,31 December 2016 est.,Mauritania,840,3590000000,76.0
137,138,31 December 2016 est.,Libya,550,3530000000,9.0
138,139,31 July 2015,Nepal,120,3450000000,16.0
139,140,31 December 2016 est.,Burkina Faso,160,3090000000,26.0
140,141,31 December 2013 est.,Somalia,270,3050000000,52.0
141,142,31 December 2016 est.,Niger,130,2730000000,36.0
142,143,31 December 2016 est.,Seychelles,26200,2550000000,180.0
143,144,31 December 2016 est.,Rwanda,200,2440000000,29.0
144,144,2015 est.,Bermuda (UK),39700,2440000000,47.0
145,146,30 June 2017,Kosovo,1200,2390000000,37.0
146,147,31 December 2016 est.,Benin,200,2340000000,26.0
147,148,31 December 2016,Tajikistan,260,2270000000,38.0
148,149,31 December 2016 est.,Bhutan,2900,2260000000,108.0
149,150,31 December 2016 est.,Haiti,180,2020000000,24.0
150,151,31 December 2016 est.,Malawi,100,1920000000,39.0
151,151,2017,South Sudan,167,1920000000,62.7
152,153,31 December 2016 est.,Chad,130,1880000000,18.0
153,154,31 March 2017,Botswana,720,1690000000,8.0
154,155,31 March 2016 est.,Palestine,340,1660000000,35.0
155,155,31 December 2016 est.,Cape Verde,3100,1660000000,99.0
156,157,31 December 2016 est.,Sierra Leone,230,1560000000,36.0
157,158,31 December 2016 est.,Equatorial Guinea,1500,1360000000,12.0
158,159,31 December 2016 est.,Djibouti,1500,1340000000,71.0
159,160,31 December 2016 est.,Guinea,100,1330000000,20.0
160,160,31 December 2016 est.,Belize,3500,1330000000,75.0
161,162,FY-2010/11,Afghanistan,40,1280000000,7.0
162,163,31 December 2016 est.,Suriname,2200,1240000000,30.0
163,164,31 December 2016 est.,Togo,150,1170000000,26.0
164,165,31 December 2015,Guyana,1500,1140000000,36.0
165,166,2014 est.,Andorra,14345,1110000000,41.0
166,166,31 December 2016 est.,Liberia,230,1110000000,51.0
167,168,31 December 2010 est.,Guinea-Bissau,570,1100000000,94.0
168,169,31 December 2016 est.,Lesotho,430,949000000,53.0
169,170,2010,Faroe Islands (Denmark),18400,889000000,38.0
170,171,31 December 2016 est.,Fiji,900,833000000,18.0
171,172,31 December 2016 est.,Eritrea,150,820000000,15.0
172,173,2014 est.,Maldives,2000,742000000,23.0
173,174,31 December 2016 est.,Burundi,60,705000000,26.0
174,175,31 December 2014 est.,Aruba,6600,693000000,28.0
175,176,31 December 2016 est.,Central African Republic,130,687000000,39.0
176,177,2013 est.,Grenada,6300,679000000,66.0
177,178,31 December 2016 est.,Gambia,260,542000000,61.0
178,179,31 December 2016 est.,Saint Lucia,2700,513000000,36.0
179,180,31 December 2016 est.,Turkmenistan,90,503000000,1.0
180,181,31 December 2013 est.,Solomon Islands,800,492000000,40.0
181,182,31 December 2016 est.,Eswatini,360,471000000,14.0
182,183,31 December 2013 est.,Samoa,2300,447000000,51.0
183,184,31 December 2012,Antigua and Barbuda,4700,441000000,34.0
184,185,2016,San Marino,10604,352000000,23.0
185,186,2017,Brunei,27200,340000000,2.8
186,187,31 December 2016 est.,Saint Vincent and the Grenadines,2900,321000000,42.0
187,188,31 December 2014 est.,Timor-Leste,250,312000000,12.0
188,189,31 December 2016 est.,Dominica,3900,289000000,55.0
189,190,31 December 2011,Cook Islands,13400,281000000,23.0
190,191,31 December 2016 est.,Sao Tome and Principe,1200,237000000,67.0
191,192,31 December 2016 est.,Tonga,2200,233000000,54.0
192,193,31 December 2016 est.,Vanuatu,750,208000000,27.0
193,194,31 December 2016 est.,Saint Kitts and Nevis,3300,188000000,20.0
194,195,31 December 2016 est.,Comoros,160,133000000,21.0
195,196,31 December 2013 est.,New Caledonia (France),420,112000000,1.0
196,197,2013 est.,Marshall Islands,1800,98000000,52.0
197,198,2013 est.,Micronesia,900,93600000,29.0
198,199,1998 est.,Cayman Islands (UK),2100,79000000,7.0
199,200,2010,Greenland (Denmark),650,36400000,2.0
200,201,2004 est.,Nauru,3200,33300000,22.0
201,202,31 December 2016,British Virgin Islands (UK),570,17700000,2.0
202,203,2017 est.,Tuvalu,1224,14800000,37.0
203,204,2013 est.,Kiribati,120,13600000,8.0
204,205,1998,Anguilla (UK),590,8800000,5.0
205,206,2004,Wallis and Futuna (France),280,3670000,6.0
206,207,31 December 2011,Montserrat (UK),200,1040000,2.0
207,208,2001,Liechtenstein,0,0,0.0
208,208,27 October 2016,Niue (New Zealand),0,0,0.0
7 changes: 3 additions & 4 deletions tests/openbb_terminal/economy/test_commodity_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ def test_format_number():
assert isinstance(fmt_number, float)


@pytest.mark.record_http
def test_get_debt():
@pytest.mark.vcr
def test_get_debt(recorder):
df = commodity_model.get_debt()
assert df is not None
assert not df.empty
recorder.capture(df)
3 changes: 2 additions & 1 deletion tests/openbb_terminal/economy/test_commodity_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def test_format_large_numbers():
commodity_view.format_large_numbers(1_000_000_000_000)


@pytest.mark.record_http
@pytest.mark.vcr(record_mode="none")
@pytest.mark.record_stdout
def test_display_debt():
commodity_view.display_debt()
Loading