|
| 1 | +import numpy as np |
| 2 | +import pandas as pd |
| 3 | +import pandas.util.testing as tm |
| 4 | +import pandas_datareader.data as web |
| 5 | + |
| 6 | + |
| 7 | +class TestEcondb(object): |
| 8 | + |
| 9 | + def test_get_cdh_e_fos(self): |
| 10 | + # EUROSTAT |
| 11 | + # Employed doctorate holders in non managerial and non professional |
| 12 | + # occupations by fields of science (%) |
| 13 | + df = web.DataReader( |
| 14 | + 'dataset=CDH_E_FOS&GEO=NO,PL,PT,RU&FOS07=FOS1&Y_GRAD=TOTAL', |
| 15 | + 'econdb', |
| 16 | + start=pd.Timestamp('2005-01-01'), |
| 17 | + end=pd.Timestamp('2010-01-01')) |
| 18 | + assert isinstance(df, pd.DataFrame) |
| 19 | + assert df.shape == (2, 4) |
| 20 | + |
| 21 | + df = df['Natural sciences']['Annual'][ |
| 22 | + ['Norway', 'Poland', 'Portugal', 'Russia']] |
| 23 | + |
| 24 | + exp_col = pd.MultiIndex.from_product( |
| 25 | + [['Norway', 'Poland', 'Portugal', 'Russia'], |
| 26 | + ['Percentage'], ['Total']], |
| 27 | + names=['Geopolitical entity (reporting)', 'Unit of measure', |
| 28 | + 'Year of graduation']) |
| 29 | + exp_idx = pd.DatetimeIndex(['2006-01-01', '2009-01-01'], |
| 30 | + name='TIME_PERIOD') |
| 31 | + |
| 32 | + values = np.array([[25.49, np.nan, 39.05, np.nan], |
| 33 | + [20.38, 25.1, 27.77, 38.1]]) |
| 34 | + expected = pd.DataFrame(values, index=exp_idx, columns=exp_col) |
| 35 | + tm.assert_frame_equal(df, expected) |
| 36 | + |
| 37 | + def test_get_tourism(self): |
| 38 | + # OECD |
| 39 | + # TOURISM_INBOUND |
| 40 | + |
| 41 | + df = web.DataReader( |
| 42 | + 'dataset=OE_TOURISM_INBOUND&COUNTRY=JPN,USA&' |
| 43 | + 'VARIABLE=INB_ARRIVALS_TOTAL', 'econdb', |
| 44 | + start=pd.Timestamp('2008-01-01'), end=pd.Timestamp('2012-01-01')) |
| 45 | + df = df.astype(np.float) |
| 46 | + jp = np.array([8351000, 6790000, 8611000, 6219000, |
| 47 | + 8368000], dtype=float) |
| 48 | + us = np.array([175702309, 160507417, 164079732, 167600277, |
| 49 | + 171320408], dtype=float) |
| 50 | + index = pd.date_range('2008-01-01', '2012-01-01', freq='AS', |
| 51 | + name='TIME_PERIOD') |
| 52 | + for label, values in [('Japan', jp), ('United States', us)]: |
| 53 | + expected = pd.Series(values, index=index, |
| 54 | + name='Total international arrivals') |
| 55 | + tm.assert_series_equal(df[label]['Total international arrivals'], |
| 56 | + expected) |
| 57 | + |
| 58 | + def test_bls(self): |
| 59 | + # BLS |
| 60 | + # CPI |
| 61 | + df = web.DataReader( |
| 62 | + 'ticker=BLS_CU.CUSR0000SA0.M.US', 'econdb', |
| 63 | + start=pd.Timestamp('2010-01-01'), end=pd.Timestamp('2013-01-27')) |
| 64 | + |
| 65 | + assert df.loc['2010-05-01'][0] == 217.3 |
0 commit comments