Skip to content

Commit dcd7a33

Browse files
authored
TST: Remove tm.get_data_path use (#566)
Remove get_data_path from tests since it was dropped upstream
1 parent 5512020 commit dcd7a33

File tree

6 files changed

+136
-96
lines changed

6 files changed

+136
-96
lines changed

docs/source/whatsnew.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ What's New
1818

1919
These are new features and improvements of note in each release.
2020

21+
.. include:: whatsnew/v0.7.0.txt
2122
.. include:: whatsnew/v0.6.0.txt
2223
.. include:: whatsnew/v0.5.0.txt
2324
.. include:: whatsnew/v0.4.0.txt

docs/source/whatsnew/v0.7.0.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ Bug Fixes
7171
- Updated Google Daily Price API to functional url (:issue:`502`)
7272
- Fix Yahoo! price data (:issue:`498`)
7373
- Added back support for Yahoo! price, dividends, and splits data for stocks
74-
and currency pairs (:issue:`487`).
74+
and currency pairs (:issue:`487`).
7575
- Add `is_list_like` to compatibility layer to avoid failure on pandas >= 0.23 (:issue:`520`)
7676
- Fixed Yahoo! time offset (:issue:`487`).
7777
- Fix Yahoo! quote reader (:issue: `540`)
78+
- Remove import of deprecated `tm.get_data_path` (:issue: `566`)

pandas_datareader/conftest.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import os
2+
3+
import pytest
4+
5+
6+
@pytest.fixture
7+
def datapath(request):
8+
"""Get the path to a data file.
9+
10+
Parameters
11+
----------
12+
path : str
13+
Path to the file, relative to ``pandas/tests/``
14+
15+
Returns
16+
-------
17+
path : path including ``pandas/tests``.
18+
19+
Raises
20+
------
21+
ValueError
22+
If the path doesn't exist and the --strict-data-files option is set.
23+
"""
24+
BASE_PATH = os.path.join(os.path.dirname(__file__), 'tests')
25+
26+
def deco(*args):
27+
path = os.path.join(BASE_PATH, *args)
28+
if not os.path.exists(path):
29+
if request.config.getoption("--strict-data-files"):
30+
msg = "Could not find file {} and --strict-data-files is set."
31+
raise ValueError(msg.format(path))
32+
else:
33+
msg = "Could not find {}."
34+
pytest.skip(msg.format(path))
35+
return path
36+
return deco

pandas_datareader/tests/io/test_jsdmx.py

Lines changed: 69 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -7,79 +7,80 @@
77
import pandas.util.testing as tm
88
import pytest
99

10-
from pandas_datareader.io import read_jsdmx
1110
from pandas_datareader.compat import PANDAS_0210
11+
from pandas_datareader.io import read_jsdmx
12+
1213

14+
@pytest.fixture
15+
def dirpath(datapath):
16+
return datapath("io", "data")
1317

14-
class TestJSDMX(object):
1518

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']
1829

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)
2953

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)
5354

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']
6162

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)

pandas_datareader/tests/io/test_sdmx.py

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,37 @@
55
import numpy as np
66
import pandas as pd
77
import pandas.util.testing as tm
8+
import pytest
89

910
from pandas_datareader.io.sdmx import read_sdmx, _read_sdmx_dsd
1011

1112

12-
class TestSDMX(object):
13+
@pytest.fixture
14+
def dirpath(datapath):
15+
return datapath("io", "data")
1316

14-
def setup_method(self, method):
15-
self.dirpath = tm.get_data_path()
1617

17-
def test_tourism(self):
18-
# Eurostat
19-
# Employed doctorate holders in non managerial and non professional
20-
# occupations by fields of science (%)
21-
dsd = _read_sdmx_dsd(os.path.join(self.dirpath, 'sdmx',
22-
'DSD_cdh_e_fos.xml'))
23-
df = read_sdmx(os.path.join(self.dirpath, 'sdmx',
24-
'cdh_e_fos.xml'), dsd=dsd)
18+
def test_tourism(dirpath):
19+
# Eurostat
20+
# Employed doctorate holders in non managerial and non professional
21+
# occupations by fields of science (%)
22+
dsd = _read_sdmx_dsd(os.path.join(dirpath, 'sdmx',
23+
'DSD_cdh_e_fos.xml'))
24+
df = read_sdmx(os.path.join(dirpath, 'sdmx',
25+
'cdh_e_fos.xml'), dsd=dsd)
2526

26-
assert isinstance(df, pd.DataFrame)
27-
assert df.shape == (2, 336)
27+
assert isinstance(df, pd.DataFrame)
28+
assert df.shape == (2, 336)
2829

29-
df = df['Percentage']['Total']['Natural sciences']
30-
df = df[['Norway', 'Poland', 'Portugal', 'Russia']]
30+
df = df['Percentage']['Total']['Natural sciences']
31+
df = df[['Norway', 'Poland', 'Portugal', 'Russia']]
3132

32-
exp_col = pd.MultiIndex.from_product([['Norway', 'Poland', 'Portugal',
33-
'Russia'], ['Annual']],
34-
names=['GEO', 'FREQ'])
35-
exp_idx = pd.DatetimeIndex(['2009', '2006'], name='TIME_PERIOD')
33+
exp_col = pd.MultiIndex.from_product([['Norway', 'Poland', 'Portugal',
34+
'Russia'], ['Annual']],
35+
names=['GEO', 'FREQ'])
36+
exp_idx = pd.DatetimeIndex(['2009', '2006'], name='TIME_PERIOD')
3637

37-
values = np.array([[20.38, 25.1, 27.77, 38.1],
38-
[25.49, np.nan, 39.05, np.nan]])
39-
expected = pd.DataFrame(values, index=exp_idx, columns=exp_col)
40-
tm.assert_frame_equal(df, expected)
38+
values = np.array([[20.38, 25.1, 27.77, 38.1],
39+
[25.49, np.nan, 39.05, np.nan]])
40+
expected = pd.DataFrame(values, index=exp_idx, columns=exp_col)
41+
tm.assert_frame_equal(df, expected)

pandas_datareader/tests/yahoo/test_options.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,17 @@ def expiry(month, year):
5050

5151

5252
@pytest.fixture
53-
def json1():
54-
dirpath = tm.get_data_path()
53+
def json1(datapath):
54+
dirpath = datapath('yahoo', 'data')
5555
json1 = 'file://' + os.path.join(
5656
dirpath, 'yahoo_options1.json')
5757
return json1
5858

5959

6060
@pytest.fixture
61-
def json2():
61+
def json2(datapath):
6262
# see gh-22: empty table
63-
dirpath = tm.get_data_path()
63+
dirpath = datapath('yahoo', 'data')
6464
json2 = 'file://' + os.path.join(
6565
dirpath, 'yahoo_options2.json')
6666
return json2

0 commit comments

Comments
 (0)