7
7
8
8
import nose
9
9
import pandas .util .testing as tm
10
- from pandas_datareader .tests ._utils import _skip_if_no_lxml
11
10
12
11
import pandas_datareader .data as web
13
12
from pandas_datareader ._utils import RemoteDataError
@@ -18,7 +17,6 @@ class TestYahooOptions(tm.TestCase):
18
17
@classmethod
19
18
def setUpClass (cls ):
20
19
super (TestYahooOptions , cls ).setUpClass ()
21
- _skip_if_no_lxml ()
22
20
23
21
# aapl has monthlies
24
22
cls .aapl = web .Options ('aapl' , 'yahoo' )
@@ -30,10 +28,9 @@ def setUpClass(cls):
30
28
cls .year = cls .year + 1
31
29
cls .expiry = datetime (cls .year , cls .month , 1 )
32
30
cls .dirpath = tm .get_data_path ()
33
- cls .html1 = 'file://' + os .path .join (cls .dirpath , 'yahoo_options1.html' )
34
- cls .html2 = 'file://' + os .path .join (cls .dirpath , 'yahoo_options2.html' )
35
- cls .html3 = 'file://' + os .path .join (cls .dirpath , 'yahoo_options3.html' ) # Empty table GH#22
36
- cls .data1 = cls .aapl ._option_frames_from_url (cls .html1 )['puts' ]
31
+ cls .json1 = 'file://' + os .path .join (cls .dirpath , 'yahoo_options1.json' )
32
+ cls .json2 = 'file://' + os .path .join (cls .dirpath , 'yahoo_options2.json' ) # Empty table GH#22
33
+ cls .data1 = cls .aapl ._process_data (cls .aapl ._parse_url (cls .json1 ))
37
34
38
35
@classmethod
39
36
def tearDownClass (cls ):
@@ -49,12 +46,13 @@ def assert_option_result(self, df):
49
46
50
47
exp_columns = pd .Index (['Last' , 'Bid' , 'Ask' , 'Chg' , 'PctChg' , 'Vol' , 'Open_Int' ,
51
48
'IV' , 'Root' , 'IsNonstandard' , 'Underlying' ,
52
- 'Underlying_Price' , 'Quote_Time' ])
49
+ 'Underlying_Price' , 'Quote_Time' , 'Last_Trade_Date' , 'JSON' ])
53
50
tm .assert_index_equal (df .columns , exp_columns )
54
51
tm .assert_equal (df .index .names , [u'Strike' , u'Expiry' , u'Type' , u'Symbol' ])
55
52
56
53
dtypes = [np .dtype (x ) for x in ['float64' ] * 5 +
57
- ['int64' , 'int64' , 'float64' , 'object' , 'bool' , 'object' , 'float64' , 'datetime64[ns]' ]]
54
+ ['int64' , 'int64' , 'float64' , 'object' , 'bool' , 'object' , 'float64' , 'datetime64[ns]' ,
55
+ 'datetime64[ns]' , 'object' ]]
58
56
tm .assert_series_equal (df .dtypes , pd .Series (dtypes , index = exp_columns ))
59
57
60
58
def test_get_options_data (self ):
@@ -103,7 +101,7 @@ def test_get_put_data(self):
103
101
104
102
def test_get_expiry_dates (self ):
105
103
try :
106
- dates , _ = self .aapl ._get_expiry_dates_and_links ()
104
+ dates = self .aapl ._get_expiry_dates ()
107
105
except RemoteDataError as e : # pragma: no cover
108
106
raise nose .SkipTest (e )
109
107
self .assertTrue (len (dates ) > 1 )
@@ -139,21 +137,13 @@ def test_get_underlying_price(self):
139
137
# GH7
140
138
try :
141
139
options_object = web .Options ('^spxpm' , 'yahoo' )
142
- url = options_object ._yahoo_url_from_expiry (options_object .expiry_dates [0 ])
143
- root = options_object ._parse_url (url )
144
- quote_price = options_object ._underlying_price_from_root (root )
140
+ quote_price = options_object .underlying_price
145
141
except RemoteDataError as e : # pragma: no cover
146
142
raise nose .SkipTest (e )
147
143
self .assertTrue (isinstance (quote_price , float ))
148
144
149
145
# Tests the weekend quote time format
150
- price , quote_time = self .aapl ._underlying_price_and_time_from_url (self .html1 )
151
- self .assertTrue (isinstance (price , (int , float , complex )))
152
- self .assertTrue (isinstance (quote_time , (datetime , pd .Timestamp )))
153
-
154
- # Tests the EDT page format
155
- # regression test for #8741
156
- price , quote_time = self .aapl ._underlying_price_and_time_from_url (self .html2 )
146
+ price , quote_time = self .aapl .underlying_price , self .aapl .quote_time
157
147
self .assertTrue (isinstance (price , (int , float , complex )))
158
148
self .assertTrue (isinstance (quote_time , (datetime , pd .Timestamp )))
159
149
@@ -194,7 +184,7 @@ def test_month_year(self):
194
184
195
185
def test_empty_table (self ):
196
186
# GH22
197
- empty = self .aapl ._option_frames_from_url (self .html3 )[ 'puts' ]
187
+ empty = self .aapl ._process_data (self .aapl . _parse_url ( self . json2 ))
198
188
self .assertTrue (len (empty ) == 0 )
199
189
200
190
if __name__ == '__main__' :
0 commit comments