Skip to content

Commit ac755b5

Browse files
committed
Merge pull request #7549 from cpcloud/fix-network-error-yahoo-options
TST: some yahoo options tests missing network decorator
2 parents 1a6d483 + af5e245 commit ac755b5

File tree

1 file changed

+27
-27
lines changed

1 file changed

+27
-27
lines changed

pandas/io/tests/test_data.py

+27-27
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import warnings
44
import nose
55
from nose.tools import assert_equal
6-
from datetime import datetime, date
6+
from datetime import datetime
77
import os
88

99
import numpy as np
@@ -21,6 +21,7 @@
2121
else:
2222
from urllib2 import HTTPError
2323

24+
2425
def _skip_if_no_lxml():
2526
try:
2627
import lxml
@@ -125,8 +126,8 @@ def test_yahoo(self):
125126
start = datetime(2010, 1, 1)
126127
end = datetime(2013, 1, 27)
127128

128-
self.assertEqual( web.DataReader("F", 'yahoo', start,
129-
end)['Close'][-1], 13.68)
129+
self.assertEqual(web.DataReader("F", 'yahoo', start, end)['Close'][-1],
130+
13.68)
130131

131132
@network
132133
def test_yahoo_fails(self):
@@ -200,17 +201,18 @@ def test_get_data_multiple_symbols(self):
200201

201202
@network
202203
def test_get_data_multiple_symbols_two_dates(self):
203-
pan = web.get_data_yahoo(['GE', 'MSFT', 'INTC'], 'JAN-01-12', 'JAN-31-12')
204+
pan = web.get_data_yahoo(['GE', 'MSFT', 'INTC'], 'JAN-01-12',
205+
'JAN-31-12')
204206
result = pan.Close.ix['01-18-12']
205207
self.assertEqual(len(result), 3)
206208

207209
# sanity checking
208210
assert np.issubdtype(result.dtype, np.floating)
209211

210-
expected = np.array([[ 18.99, 28.4 , 25.18],
211-
[ 18.58, 28.31, 25.13],
212-
[ 19.03, 28.16, 25.52],
213-
[ 18.81, 28.82, 25.87]])
212+
expected = np.array([[18.99, 28.4, 25.18],
213+
[18.58, 28.31, 25.13],
214+
[19.03, 28.16, 25.52],
215+
[18.81, 28.82, 25.87]])
214216
result = pan.Open.ix['Jan-15-12':'Jan-20-12']
215217
self.assertEqual(expected.shape, result.shape)
216218

@@ -249,49 +251,44 @@ def setUpClass(cls):
249251
cls.root1 = cls.aapl._parse_url(cls.html1)
250252
cls.root2 = cls.aapl._parse_url(cls.html2)
251253

252-
253254
@classmethod
254255
def tearDownClass(cls):
255256
super(TestYahooOptions, cls).tearDownClass()
256257
del cls.aapl, cls.expiry
257258

258259
@network
259260
def test_get_options_data(self):
261+
# regression test GH6105
262+
self.assertRaises(ValueError, self.aapl.get_options_data, month=3)
263+
self.assertRaises(ValueError, self.aapl.get_options_data, year=1992)
264+
260265
try:
261266
options = self.aapl.get_options_data(expiry=self.expiry)
262267
except RemoteDataError as e:
263268
nose.SkipTest(e)
264269
else:
265-
assert len(options)>1
266-
267-
268-
def test_get_options_data(self):
269-
270-
# regression test GH6105
271-
self.assertRaises(ValueError, self.aapl.get_options_data, month=3)
272-
self.assertRaises(ValueError, self.aapl.get_options_data, year=1992)
270+
assert len(options) > 1
273271

274272
@network
275273
def test_get_near_stock_price(self):
276274
try:
277275
options = self.aapl.get_near_stock_price(call=True, put=True,
278-
expiry=self.expiry)
276+
expiry=self.expiry)
279277
except RemoteDataError as e:
280278
nose.SkipTest(e)
281279
else:
282-
assert len(options)> 1
280+
assert len(options) > 1
283281

284282
self.assertTrue(len(options) > 1)
285283

286-
287284
@network
288285
def test_get_call_data(self):
289286
try:
290287
calls = self.aapl.get_call_data(expiry=self.expiry)
291288
except RemoteDataError as e:
292289
nose.SkipTest(e)
293290
else:
294-
assert len(calls)>1
291+
assert len(calls) > 1
295292

296293
@network
297294
def test_get_put_data(self):
@@ -300,7 +297,7 @@ def test_get_put_data(self):
300297
except RemoteDataError as e:
301298
nose.SkipTest(e)
302299
else:
303-
assert len(puts)>1
300+
assert len(puts) > 1
304301

305302
@network
306303
def test_get_expiry_months(self):
@@ -328,18 +325,21 @@ def test_get_all_data_calls_only(self):
328325

329326
self.assertTrue(len(data) > 1)
330327

328+
@network
331329
def test_sample_page_price_quote_time1(self):
332330
#Tests the weekend quote time format
333331
price, quote_time = self.aapl._get_underlying_price(self.root1)
334332
self.assertIsInstance(price, (int, float, complex))
335333
self.assertIsInstance(quote_time, (datetime, Timestamp))
336334

335+
@network
337336
def test_sample_page_price_quote_time2(self):
338337
#Tests the weekday quote time format
339338
price, quote_time = self.aapl._get_underlying_price(self.root2)
340339
self.assertIsInstance(price, (int, float, complex))
341340
self.assertIsInstance(quote_time, (datetime, Timestamp))
342341

342+
@network
343343
def test_sample_page_chg_float(self):
344344
#Tests that numeric columns with comma's are appropriately dealt with
345345
tables = self.root1.xpath('.//table')
@@ -348,7 +348,6 @@ def test_sample_page_chg_float(self):
348348
self.assertEqual(option_data['Chg'].dtype, 'float64')
349349

350350

351-
352351
class TestOptionsWarnings(tm.TestCase):
353352
@classmethod
354353
def setUpClass(cls):
@@ -383,9 +382,9 @@ def test_get_near_stock_price_warning(self):
383382
with assert_produces_warning():
384383
try:
385384
options_near = self.aapl.get_near_stock_price(call=True,
386-
put=True,
387-
month=self.month,
388-
year=self.year)
385+
put=True,
386+
month=self.month,
387+
year=self.year)
389388
except RemoteDataError as e:
390389
nose.SkipTest(e)
391390

@@ -430,7 +429,7 @@ def test_read_fred(self):
430429
def test_read_famafrench(self):
431430
for name in ("F-F_Research_Data_Factors",
432431
"F-F_Research_Data_Factors_weekly", "6_Portfolios_2x3",
433-
"F-F_ST_Reversal_Factor","F-F_Momentum_Factor"):
432+
"F-F_ST_Reversal_Factor", "F-F_Momentum_Factor"):
434433
ff = DataReader(name, "famafrench")
435434
assert ff
436435
assert isinstance(ff, dict)
@@ -508,6 +507,7 @@ def test_fred_multi_bad_series(self):
508507
with tm.assertRaises(HTTPError):
509508
DataReader(names, data_source="fred")
510509

510+
511511
if __name__ == '__main__':
512512
nose.runmodule(argv=[__file__, '-vvs', '-x', '--pdb', '--pdb-failure'],
513513
exit=False)

0 commit comments

Comments
 (0)