|
7 | 7 | import pandas.util.testing as tm
|
8 | 8 | import pytest
|
9 | 9 |
|
10 |
| -from pandas_datareader.io import read_jsdmx |
11 | 10 | from pandas_datareader.compat import PANDAS_0210
|
| 11 | +from pandas_datareader.io import read_jsdmx |
| 12 | + |
12 | 13 |
|
| 14 | +@pytest.fixture |
| 15 | +def dirpath(datapath): |
| 16 | + return datapath("io", "data") |
13 | 17 |
|
14 |
| -class TestJSDMX(object): |
15 | 18 |
|
16 |
| - def setup_method(self, method): |
17 |
| - self.dirpath = tm.get_data_path() |
| 19 | +@pytest.mark.skipif(not PANDAS_0210, reason='Broken on old pandas') |
| 20 | +def test_tourism(dirpath): |
| 21 | + # OECD -> Industry and Services -> Inbound Tourism |
| 22 | + result = read_jsdmx(os.path.join(dirpath, 'jsdmx', |
| 23 | + 'tourism.json')) |
| 24 | + assert isinstance(result, pd.DataFrame) |
| 25 | + jp = result['Japan'] |
| 26 | + visitors = ['China', 'Hong Kong, China', |
| 27 | + 'Total international arrivals', |
| 28 | + 'Korea', 'Chinese Taipei', 'United States'] |
18 | 29 |
|
19 |
| - @pytest.mark.skipif(not PANDAS_0210, reason='Broken on old pandas') |
20 |
| - def test_tourism(self): |
21 |
| - # OECD -> Industry and Services -> Inbound Tourism |
22 |
| - result = read_jsdmx(os.path.join(self.dirpath, 'jsdmx', |
23 |
| - 'tourism.json')) |
24 |
| - assert isinstance(result, pd.DataFrame) |
25 |
| - jp = result['Japan'] |
26 |
| - visitors = ['China', 'Hong Kong, China', |
27 |
| - 'Total international arrivals', |
28 |
| - 'Korea', 'Chinese Taipei', 'United States'] |
| 30 | + exp_col = pd.Index( |
| 31 | + ['China', 'Hong Kong, China', 'Total international arrivals', |
| 32 | + 'Korea', 'Chinese Taipei', 'United States'], |
| 33 | + name='Variable') |
| 34 | + exp_idx = pd.DatetimeIndex(['2008-01-01', '2009-01-01', '2010-01-01', |
| 35 | + '2011-01-01', '2012-01-01', '2013-01-01', |
| 36 | + '2014-01-01', '2015-01-01', '2016-01-01'], |
| 37 | + name='Year') |
| 38 | + values = [ |
| 39 | + [1000000.0, 550000.0, 8351000.0, 2382000.0, 1390000.0, 768000.0], |
| 40 | + [1006000.0, 450000.0, 6790000.0, 1587000.0, 1024000.0, 700000.0], |
| 41 | + [1413000.0, 509000.0, 8611000.0, 2440000.0, 1268000.0, 727000.0], |
| 42 | + [1043000.0, 365000.0, 6219000.0, 1658000.0, 994000.0, 566000.0], |
| 43 | + [1430000.0, 482000.0, 8368000.0, 2044000.0, 1467000.0, 717000.0], |
| 44 | + [1314000.0, 746000.0, 10364000.0, 2456000.0, 2211000.0, 799000.0], |
| 45 | + [2409000.0, 926000.0, 13413000.0, 2755000.0, 2830000.0, 892000.0], |
| 46 | + [4993689.0, 1524292.0, 19737409.0, 4002095.0, 3677075.0, |
| 47 | + 1033258.0], |
| 48 | + [6373564.0, 1839193.0, 24039700.0, 5090302.0, 4167512.0, 1242719.0] |
| 49 | + ] |
| 50 | + values = np.array(values, dtype='object') |
| 51 | + expected = pd.DataFrame(values, index=exp_idx, columns=exp_col) |
| 52 | + tm.assert_frame_equal(jp[visitors], expected) |
29 | 53 |
|
30 |
| - exp_col = pd.Index( |
31 |
| - ['China', 'Hong Kong, China', 'Total international arrivals', |
32 |
| - 'Korea', 'Chinese Taipei', 'United States'], |
33 |
| - name='Variable') |
34 |
| - exp_idx = pd.DatetimeIndex(['2008-01-01', '2009-01-01', '2010-01-01', |
35 |
| - '2011-01-01', '2012-01-01', '2013-01-01', |
36 |
| - '2014-01-01', '2015-01-01', '2016-01-01'], |
37 |
| - name='Year') |
38 |
| - values = [ |
39 |
| - [1000000.0, 550000.0, 8351000.0, 2382000.0, 1390000.0, 768000.0], |
40 |
| - [1006000.0, 450000.0, 6790000.0, 1587000.0, 1024000.0, 700000.0], |
41 |
| - [1413000.0, 509000.0, 8611000.0, 2440000.0, 1268000.0, 727000.0], |
42 |
| - [1043000.0, 365000.0, 6219000.0, 1658000.0, 994000.0, 566000.0], |
43 |
| - [1430000.0, 482000.0, 8368000.0, 2044000.0, 1467000.0, 717000.0], |
44 |
| - [1314000.0, 746000.0, 10364000.0, 2456000.0, 2211000.0, 799000.0], |
45 |
| - [2409000.0, 926000.0, 13413000.0, 2755000.0, 2830000.0, 892000.0], |
46 |
| - [4993689.0, 1524292.0, 19737409.0, 4002095.0, 3677075.0, |
47 |
| - 1033258.0], |
48 |
| - [6373564.0, 1839193.0, 24039700.0, 5090302.0, 4167512.0, 1242719.0] |
49 |
| - ] |
50 |
| - values = np.array(values, dtype='object') |
51 |
| - expected = pd.DataFrame(values, index=exp_idx, columns=exp_col) |
52 |
| - tm.assert_frame_equal(jp[visitors], expected) |
53 | 54 |
|
54 |
| - @pytest.mark.skipif(not PANDAS_0210, reason='Broken on old pandas') |
55 |
| - def test_land_use(self): |
56 |
| - # OECD -> Environment -> Resources Land Use |
57 |
| - result = read_jsdmx(os.path.join(self.dirpath, 'jsdmx', |
58 |
| - 'land_use.json')) |
59 |
| - assert isinstance(result, pd.DataFrame) |
60 |
| - result = result.loc['2010':'2011'] |
| 55 | +@pytest.mark.skipif(not PANDAS_0210, reason='Broken on old pandas') |
| 56 | +def test_land_use(dirpath): |
| 57 | + # OECD -> Environment -> Resources Land Use |
| 58 | + result = read_jsdmx(os.path.join(dirpath, 'jsdmx', |
| 59 | + 'land_use.json')) |
| 60 | + assert isinstance(result, pd.DataFrame) |
| 61 | + result = result.loc['2010':'2011'] |
61 | 62 |
|
62 |
| - cols = ['Arable land and permanent crops', |
63 |
| - 'Arable and cropland % land area', |
64 |
| - 'Total area', 'Forest', 'Forest % land area', |
65 |
| - 'Land area', 'Permanent meadows and pastures', |
66 |
| - 'Meadows and pastures % land area', 'Other areas', |
67 |
| - 'Other % land area'] |
68 |
| - exp_col = pd.MultiIndex.from_product([ |
69 |
| - ['Japan', 'United States'], |
70 |
| - cols], names=['Country', 'Variable']) |
71 |
| - exp_idx = pd.DatetimeIndex(['2010', '2011'], name='Year') |
72 |
| - values = [ |
73 |
| - [53790.0, 14.753154141525, 377800.0, np.nan, np.nan, 364600.0, |
74 |
| - 5000.0, 1.3713658804169, np.nan, np.nan, |
75 |
| - 1897990.0, 20.722767650476, 9629090.0, np.nan, np.nan, 9158960.0, |
76 |
| - 2416000.0, 26.378540795025, np.nan, |
77 |
| - np.nan], |
78 |
| - [53580.0, 14.691527282698, 377800.0, np.nan, np.nan, 364700.0, |
79 |
| - 5000.0, 1.3709898546751, np.nan, np.nan, |
80 |
| - 1897990.0, 20.722767650476, 9629090.0, np.nan, np.nan, 9158960.0, |
81 |
| - 2416000.0, 26.378540795025, np.nan, |
82 |
| - np.nan]] |
83 |
| - values = np.array(values) |
84 |
| - expected = pd.DataFrame(values, index=exp_idx, columns=exp_col) |
85 |
| - tm.assert_frame_equal(result[exp_col], expected) |
| 63 | + cols = ['Arable land and permanent crops', |
| 64 | + 'Arable and cropland % land area', |
| 65 | + 'Total area', 'Forest', 'Forest % land area', |
| 66 | + 'Land area', 'Permanent meadows and pastures', |
| 67 | + 'Meadows and pastures % land area', 'Other areas', |
| 68 | + 'Other % land area'] |
| 69 | + exp_col = pd.MultiIndex.from_product([ |
| 70 | + ['Japan', 'United States'], |
| 71 | + cols], names=['Country', 'Variable']) |
| 72 | + exp_idx = pd.DatetimeIndex(['2010', '2011'], name='Year') |
| 73 | + values = [ |
| 74 | + [53790.0, 14.753154141525, 377800.0, np.nan, np.nan, 364600.0, |
| 75 | + 5000.0, 1.3713658804169, np.nan, np.nan, |
| 76 | + 1897990.0, 20.722767650476, 9629090.0, np.nan, np.nan, 9158960.0, |
| 77 | + 2416000.0, 26.378540795025, np.nan, |
| 78 | + np.nan], |
| 79 | + [53580.0, 14.691527282698, 377800.0, np.nan, np.nan, 364700.0, |
| 80 | + 5000.0, 1.3709898546751, np.nan, np.nan, |
| 81 | + 1897990.0, 20.722767650476, 9629090.0, np.nan, np.nan, 9158960.0, |
| 82 | + 2416000.0, 26.378540795025, np.nan, |
| 83 | + np.nan]] |
| 84 | + values = np.array(values) |
| 85 | + expected = pd.DataFrame(values, index=exp_idx, columns=exp_col) |
| 86 | + tm.assert_frame_equal(result[exp_col], expected) |
0 commit comments