Skip to content

Commit 40cf6e8

Browse files
committed
TST: Reenable jsmdx testing
Re-enable jsmdx testing on modern pandas
1 parent 9ff8939 commit 40cf6e8

File tree

4 files changed

+52
-42
lines changed

4 files changed

+52
-42
lines changed

pandas_datareader/compat/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
PANDAS_0190 = (PANDAS_VERSION >= LooseVersion('0.19.0'))
1212
PANDAS_0200 = (PANDAS_VERSION >= LooseVersion('0.20.0'))
13+
PANDAS_0210 = (PANDAS_VERSION >= LooseVersion('0.21.0'))
1314

1415
if PANDAS_0190:
1516
from pandas.api.types import is_number

pandas_datareader/tests/io/data/jsdmx/land_use.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

pandas_datareader/tests/io/data/jsdmx/tourism.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

pandas_datareader/tests/io/test_jsdmx.py

Lines changed: 49 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -8,69 +8,78 @@
88
import pytest
99

1010
from pandas_datareader.io import read_jsdmx
11+
from pandas_datareader.compat import PANDAS_0210
1112

1213

1314
class TestJSDMX(object):
1415

1516
def setup_method(self, method):
1617
self.dirpath = tm.get_data_path()
1718

18-
@pytest.mark.xfail(reason='Parsing error')
19+
@pytest.mark.skipif(not PANDAS_0210, reason='Broken on old pandas')
1920
def test_tourism(self):
2021
# OECD -> Industry and Services -> Inbound Tourism
2122
result = read_jsdmx(os.path.join(self.dirpath, 'jsdmx',
2223
'tourism.json'))
2324
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']
2429

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')
4751
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)
4953

50-
@pytest.mark.xfail(reason='Parsing error')
54+
@pytest.mark.skipif(not PANDAS_0210, reason='Broken on old pandas')
5155
def test_land_use(self):
5256
# OECD -> Environment -> Resources Land Use
5357
result = read_jsdmx(os.path.join(self.dirpath, 'jsdmx',
5458
'land_use.json'))
5559
assert isinstance(result, pd.DataFrame)
5660
result = result.loc['2010':'2011']
5761

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']
5868
exp_col = pd.MultiIndex.from_product([
5969
['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'])
6671
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)
7584
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

Comments
 (0)