|
8 | 8 | import pytest |
9 | 9 |
|
10 | 10 | from pandas_datareader.io import read_jsdmx |
| 11 | +from pandas_datareader.compat import PANDAS_0210 |
11 | 12 |
|
12 | 13 |
|
13 | 14 | class TestJSDMX(object): |
14 | 15 |
|
15 | 16 | def setup_method(self, method): |
16 | 17 | self.dirpath = tm.get_data_path() |
17 | 18 |
|
18 | | - @pytest.mark.xfail(reason='Parsing error') |
| 19 | + @pytest.mark.skipif(not PANDAS_0210, reason='Broken on old pandas') |
19 | 20 | def test_tourism(self): |
20 | 21 | # OECD -> Industry and Services -> Inbound Tourism |
21 | 22 | result = read_jsdmx(os.path.join(self.dirpath, 'jsdmx', |
22 | 23 | 'tourism.json')) |
23 | 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'] |
24 | 29 |
|
25 | | - exp_col = pd.MultiIndex.from_product( |
26 | | - [['Japan'], ['China', 'Hong Kong, China', |
27 | | - 'Total international arrivals', |
28 | | - 'Total international receipts', |
29 | | - 'International passenger transport receipts', |
30 | | - 'International travel receipts', |
31 | | - 'Korea', 'Chinese Taipei', 'United States']], |
32 | | - names=['Country', 'Variable']) |
33 | | - exp_idx = pd.DatetimeIndex(['2004', '2005', '2006', '2007', |
34 | | - '2008', '2009', '2010', '2011', |
35 | | - '2012'], name='Year') |
36 | | - |
37 | | - values = np.array([ |
38 | | - [616, 300, 6138, 1550, 330, 1220, 1588, 1081, 760], |
39 | | - [653, 299, 6728, 1710, 340, 1370, 1747, 1275, 822], |
40 | | - [812, 352, 7334, 1330, 350, 980, 2117, 1309, 817], |
41 | | - [942, 432, 8347, 1460, 360, 1100, 2601, 1385, 816], |
42 | | - [1000, 550, 8351, 1430, 310, 1120, 2382, 1390, 768], |
43 | | - [1006, 450, 6790, 1170, 210, 960, 1587, 1024, 700], |
44 | | - [1413, 509, 8611, 1350, 190, 1160, 2440, 1268, 727], |
45 | | - [1043, 365, 6219, 1000, 100, 900, 1658, 994, 566], |
46 | | - [1430, 482, 8368, 1300, 100, 1200, 2044, 1467, 717]]) |
| 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') |
47 | 51 | expected = pd.DataFrame(values, index=exp_idx, columns=exp_col) |
48 | | - tm.assert_frame_equal(result, expected) |
| 52 | + tm.assert_frame_equal(jp[visitors], expected) |
49 | 53 |
|
50 | | - @pytest.mark.xfail(reason='Parsing error') |
| 54 | + @pytest.mark.skipif(not PANDAS_0210, reason='Broken on old pandas') |
51 | 55 | def test_land_use(self): |
52 | 56 | # OECD -> Environment -> Resources Land Use |
53 | 57 | result = read_jsdmx(os.path.join(self.dirpath, 'jsdmx', |
54 | 58 | 'land_use.json')) |
55 | 59 | assert isinstance(result, pd.DataFrame) |
56 | 60 | result = result.loc['2010':'2011'] |
57 | 61 |
|
| 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'] |
58 | 68 | exp_col = pd.MultiIndex.from_product([ |
59 | 69 | ['Japan', 'United States'], |
60 | | - ['Arable land and permanent crops', |
61 | | - 'Arable and cropland % land area', |
62 | | - 'Total area', 'Forest', 'Forest % land area', |
63 | | - 'Land area', 'Permanent meadows and pastures', |
64 | | - 'Meadows and pastures % land area', 'Other areas', |
65 | | - 'Other % land area']], names=['Country', 'Variable']) |
| 70 | + cols], names=['Country', 'Variable']) |
66 | 71 | exp_idx = pd.DatetimeIndex(['2010', '2011'], name='Year') |
67 | | - values = np.array([[45930, 12.601, 377950, 249790, 68.529, 364500, |
68 | | - np.nan, np.nan, 68780, 18.87, 1624330, 17.757, |
69 | | - 9831510, 3040220, 33.236, 9147420, 2485000, |
70 | | - 27.166, 1997870, 21.841], |
71 | | - [45610, 12.513, 377955, 249878, 68.554, 364500, |
72 | | - np.nan, np.nan, 69012, 18.933, 1627625, 17.793, |
73 | | - 9831510, 3044048, 33.278, 9147420, 2485000, |
74 | | - 27.166, 1990747, 21.763]]) |
| 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) |
75 | 84 | expected = pd.DataFrame(values, index=exp_idx, columns=exp_col) |
76 | | - tm.assert_frame_equal(result, expected) |
| 85 | + tm.assert_frame_equal(result[exp_col], expected) |
0 commit comments