Skip to content

Commit a2e5ac4

Browse files
econdbKevin Sheppard
authored andcommitted
BUG: Fix tests and colon separation
1 parent 6bea25c commit a2e5ac4

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

pandas_datareader/compat/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
PANDAS_0220 = PANDAS_VERSION >= LooseVersion("0.22.0")
1515
PANDAS_0230 = PANDAS_VERSION >= LooseVersion("0.23.0")
1616

17-
1817
__all__ = [
1918
"HTTPError",
2019
"StringIO",

pandas_datareader/econdb.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,28 @@ def read(self):
2727
if self._show == "labels":
2828

2929
def show_func(x):
30-
return x.split(":")[1]
30+
return x[x.find(':')+1:]
3131

3232
elif self._show == "codes":
3333

3434
def show_func(x):
35-
return x.split(":")[0]
35+
return x[:x.find(':')]
3636

3737
for entry in results:
3838
series = pd.DataFrame(entry["data"])[["dates", "values"]].set_index("dates")
39-
4039
head = entry["additional_metadata"]
40+
4141
if head != "": # this additional metadata is not blank
4242
series.columns = pd.MultiIndex.from_tuples(
4343
[[show_func(x) for x in head.values()]],
4444
names=[show_func(x) for x in head.keys()],
4545
)
46+
else:
47+
series.rename(
48+
columns={"values": entry['ticker']}, inplace=True)
4649

4750
if not df.empty:
48-
df = df.join(series, how="outer")
51+
df = df.merge(series, how="outer", left_index=True, right_index=True)
4952
else:
5053
df = series
5154
if df.shape[0] > 0:

pandas_datareader/tests/test_econdb.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,22 @@ def test_get_tourism(self):
4848
us = np.array(
4949
[175702304, 160507424, 164079728, 167600272, 171320416], dtype=float
5050
)
51+
index = pd.date_range("2008-01-01", "2012-01-01", freq="AS", name="TIME_PERIOD")
52+
5153

5254
# check the values coming back are equal
5355
np.testing.assert_array_equal(df.values[:, 0], jp)
5456
np.testing.assert_array_equal(df.values[:, 1], us)
5557

58+
# sometimes the country and variable columns are swapped
59+
df = df.swaplevel(2, 1, axis=1)
60+
for label, values in [("Japan", jp), ("United States", us)]:
61+
expected = pd.Series(
62+
values, index=index, name="Total international arrivals"
63+
)
64+
tm.assert_series_equal(
65+
df[label]['Tourism demand surveys']["Total international arrivals"], expected)
66+
5667
def test_bls(self):
5768
# BLS
5869
# CPI
@@ -64,3 +75,14 @@ def test_bls(self):
6475
)
6576

6677
assert df.loc["2010-05-01"][0] == 217.3
78+
79+
80+
def test_australia_gdp(self):
81+
82+
df = web.DataReader(
83+
'dataset=ABS_GDP&to=2019-09-01&from=1959-09-01&h=TIME&v=Indicator',
84+
'econdb')
85+
assert df.loc[
86+
'2017-10-01',
87+
('GDP per capita: Current prices - National Accounts',
88+
'Seasonally Adjusted', 'AUD')] == 18329

0 commit comments

Comments
 (0)