Skip to content

Commit 4812d1c

Browse files
authored
Merge pull request #438 from bashtage/mark-xfail
TST: Mark currently failing tests as xfail
2 parents 3b88171 + dde5717 commit 4812d1c

File tree

8 files changed

+46
-20
lines changed

8 files changed

+46
-20
lines changed

pandas_datareader/famafrench.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import tempfile
2-
import re
31
import datetime as dt
2+
import re
3+
import tempfile
44
from zipfile import ZipFile
5-
from pandas.compat import lmap, StringIO
5+
66
from pandas import read_csv, to_datetime
7+
from pandas.compat import lmap, StringIO
78

89
from pandas_datareader.base import _BaseReader
910

@@ -32,13 +33,12 @@ def _parse_date_famafrench(x):
3233
x = x.strip()
3334
try:
3435
return dt.datetime.strptime(x, '%Y%m')
35-
except:
36+
except Exception:
3637
pass
3738
return to_datetime(x)
3839

3940

4041
class FamaFrenchReader(_BaseReader):
41-
4242
"""
4343
Get data for the given name from the Fama/French data library.
4444
@@ -106,7 +106,7 @@ def _read_one_data(self, url, params):
106106
idx_name = df.index.name # hack for pandas 0.16.2
107107
df = df.to_period(df.index.inferred_freq[:1])
108108
df.index.name = idx_name
109-
except:
109+
except Exception:
110110
pass
111111
df = df.truncate(self.start, self.end)
112112
datasets[i] = df
@@ -141,9 +141,9 @@ def get_available_datasets(self):
141141
response = self.session.get(_URL + 'data_library.html')
142142
root = document_fromstring(response.content)
143143

144-
l = filter(lambda x: (x.startswith(_URL_PREFIX) and
145-
x.endswith(_URL_SUFFIX)),
146-
[e.attrib['href'] for e in root.findall('.//a')
147-
if 'href' in e.attrib])
144+
datasets = [e.attrib['href'] for e in root.findall('.//a')
145+
if 'href' in e.attrib]
146+
datasets = [ds for ds in datasets if ds.startswith(_URL_PREFIX)
147+
and ds.endswith(_URL_SUFFIX)]
148148

149-
return lmap(lambda x: x[len(_URL_PREFIX):-len(_URL_SUFFIX)], l)
149+
return lmap(lambda x: x[len(_URL_PREFIX):-len(_URL_SUFFIX)], datasets)

pandas_datareader/tests/google/test_options.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ def setup_class(cls):
1616
# GOOG has monthlies
1717
cls.goog = web.Options('GOOG', 'google')
1818

19+
@pytest.mark.xfail(reason='Parsing error')
1920
def test_get_options_data(self):
2021
options = self.goog.get_options_data(expiry=self.goog.expiry_dates[0])
2122

@@ -43,6 +44,7 @@ def test_get_options_data_yearmonth(self):
4344
with pytest.raises(NotImplementedError):
4445
self.goog.get_options_data(month=1, year=2016)
4546

47+
@pytest.mark.xfail(reason='Parsing error')
4648
def test_expiry_dates(self):
4749
dates = self.goog.expiry_dates
4850

pandas_datareader/tests/io/test_jsdmx.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
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 import read_jsdmx
1011

@@ -14,6 +15,7 @@ class TestJSDMX(object):
1415
def setup_method(self, method):
1516
self.dirpath = tm.get_data_path()
1617

18+
@pytest.mark.xfail(reason='Parsing error')
1719
def test_tourism(self):
1820
# OECD -> Industry and Services -> Inbound Tourism
1921
result = read_jsdmx(os.path.join(self.dirpath, 'jsdmx',
@@ -45,6 +47,7 @@ def test_tourism(self):
4547
expected = pd.DataFrame(values, index=exp_idx, columns=exp_col)
4648
tm.assert_frame_equal(result, expected)
4749

50+
@pytest.mark.xfail(reason='Parsing error')
4851
def test_land_use(self):
4952
# OECD -> Environment -> Resources Land Use
5053
result = read_jsdmx(os.path.join(self.dirpath, 'jsdmx',

pandas_datareader/tests/test_famafrench.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ def test_get_data(self):
2323

2424
def test_get_available_datasets(self):
2525
pytest.importorskip("lxml")
26-
l = get_available_datasets()
27-
assert len(l) > 100
26+
avail = get_available_datasets()
27+
assert len(avail) > 100
2828

2929
def test_index(self):
3030
ff = web.DataReader('F-F_Research_Data_Factors', 'famafrench')

pandas_datareader/tests/test_oecd.py

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

1111
class TestOECD(object):
1212

13+
@pytest.mark.xfail(reason='Incorrect URL')
1314
def test_get_un_den(self):
1415
df = web.DataReader('UN_DEN', 'oecd', start=datetime(1960, 1, 1),
1516
end=datetime(2012, 1, 1))
@@ -64,6 +65,7 @@ def test_get_un_den(self):
6465
expected = pd.Series(values, index=index, name=label)
6566
tm.assert_series_equal(df[label], expected)
6667

68+
@pytest.mark.xfail(reason='Incorrect URL')
6769
def test_get_tourism(self):
6870
df = web.DataReader('TOURISM_INBOUND', 'oecd',
6971
start=datetime(2008, 1, 1),

pandas_datareader/tests/yahoo/test_options.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ def test_get_underlying_price(self, aapl):
159159
assert isinstance(price, (int, float, complex))
160160
assert isinstance(quote_time, (datetime, pd.Timestamp))
161161

162+
@pytest.mark.xfail(reason='Invalid URL scheme')
162163
def test_chop(self, aapl, data1):
163164
# gh-7625: regression test
164165
aapl._chop_data(data1, above_below=2,
@@ -175,6 +176,7 @@ def test_chop(self, aapl, data1):
175176
assert isinstance(chopped2, pd.DataFrame)
176177
assert len(chopped2) > 1
177178

179+
@pytest.mark.xfail(reason='Invalid URL scheme')
178180
def test_chop_out_of_strike_range(self, aapl, data1):
179181
# gh-7625: regression test
180182
aapl._chop_data(data1, above_below=2,
@@ -185,6 +187,7 @@ def test_chop_out_of_strike_range(self, aapl, data1):
185187
assert isinstance(chopped, pd.DataFrame)
186188
assert len(chopped) > 1
187189

190+
@pytest.mark.xfail(reason='Invalid URL scheme')
188191
def test_sample_page_chg_float(self, data1):
189192
# Tests that numeric columns with comma's are appropriately dealt with
190193
assert data1['Chg'].dtype == 'float64'
@@ -198,6 +201,7 @@ def test_month_year(self, aapl, month, year):
198201

199202
self.assert_option_result(data)
200203

204+
@pytest.mark.xfail(reason='Invalid URL scheme')
201205
def test_empty_table(self, aapl, json2):
202206
# see gh-22
203207
empty = aapl._process_data(aapl._parse_url(json2))

pandas_datareader/tests/yahoo/test_yahoo.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import numpy as np
55
import pandas as pd
66
from pandas import DataFrame
7-
7+
from requests.exceptions import ConnectionError
88
import pytest
99
import pandas.util.testing as tm
1010

@@ -14,6 +14,8 @@
1414
from pandas_datareader._utils import RemoteDataError
1515
from pandas_datareader._testing import skip_on_exception
1616

17+
XFAIL_REASON = 'Known connection failures on Yahoo when testing!'
18+
1719

1820
class TestYahoo(object):
1921

@@ -37,21 +39,34 @@ def test_yahoo_fails(self):
3739
web.DataReader('NON EXISTENT TICKER', 'yahoo', start, end)
3840

3941
def test_get_quote_series(self):
40-
df = web.get_quote_yahoo(pd.Series(['GOOG', 'AAPL', 'GOOG']))
42+
try:
43+
df = web.get_quote_yahoo(pd.Series(['GOOG', 'AAPL', 'GOOG']))
44+
except ConnectionError:
45+
pytest.xfail(reason=XFAIL_REASON)
4146
tm.assert_series_equal(df.iloc[0], df.iloc[2])
4247

4348
def test_get_quote_string(self):
4449
_yahoo_codes.update({'MarketCap': 'j1'})
45-
df = web.get_quote_yahoo('GOOG')
50+
try:
51+
df = web.get_quote_yahoo('GOOG')
52+
except ConnectionError:
53+
pytest.xfail(reason=XFAIL_REASON)
54+
4655
assert not pd.isnull(df['MarketCap'][0])
4756

4857
def test_get_quote_stringlist(self):
49-
df = web.get_quote_yahoo(['GOOG', 'AAPL', 'GOOG'])
58+
try:
59+
df = web.get_quote_yahoo(['GOOG', 'AAPL', 'GOOG'])
60+
except ConnectionError:
61+
pytest.xfail(reason=XFAIL_REASON)
5062
tm.assert_series_equal(df.iloc[0], df.iloc[2])
5163

5264
def test_get_quote_comma_name(self):
5365
_yahoo_codes.update({'name': 'n'})
54-
df = web.get_quote_yahoo(['RGLD'])
66+
try:
67+
df = web.get_quote_yahoo(['RGLD'])
68+
except ConnectionError:
69+
pytest.xfail(reason=XFAIL_REASON)
5570
del _yahoo_codes['name']
5671
assert df['name'][0] == 'Royal Gold, Inc.'
5772

pandas_datareader/wb.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ def _read_lines(self, out):
201201
try:
202202
msg = msg['key'].split() + ["\n "] + msg['value'].split()
203203
wb_err = ' '.join(msg)
204-
except:
204+
except Exception:
205205
wb_err = ""
206206
if 'key' in msg.keys():
207207
wb_err = msg['key'] + "\n "
@@ -274,7 +274,7 @@ def encode_ascii(x):
274274
def get_value(x):
275275
try:
276276
return x['value']
277-
except:
277+
except Exception:
278278
return ''
279279

280280
def get_list_of_values(x):

0 commit comments

Comments
 (0)