File tree 2 files changed +24
-2
lines changed
2 files changed +24
-2
lines changed Original file line number Diff line number Diff line change @@ -698,8 +698,19 @@ def _option_frames_from_url(self, url):
698
698
699
699
def _get_underlying_price (self , url ):
700
700
root = self ._parse_url (url )
701
- underlying_price = float (root .xpath ('.//*[@class="time_rtq_ticker Fz-30 Fw-b"]' )[0 ]\
702
- .getchildren ()[0 ].text )
701
+ underlying_price = root .xpath ('.//*[@class="time_rtq_ticker Fz-30 Fw-b"]' )[0 ]\
702
+ .getchildren ()[0 ].text
703
+
704
+ try :
705
+ underlying_price = float (underlying_price )
706
+ except ValueError :
707
+ # check for comma
708
+ underlying_price = underlying_price .replace (',' , '' )
709
+
710
+ try :
711
+ underlying_price = float (underlying_price )
712
+ except ValueError :
713
+ underlying_price = np .nan
703
714
704
715
#Gets the time of the quote, note this is actually the time of the underlying price.
705
716
try :
Original file line number Diff line number Diff line change @@ -322,6 +322,17 @@ def test_get_all_data_calls_only(self):
322
322
raise nose .SkipTest (e )
323
323
self .assertTrue (len (data ) > 1 )
324
324
325
+ def test_get_underlying_price (self ):
326
+ #GH7
327
+ try :
328
+ options_object = web .Options ('^spxpm' , 'yahoo' )
329
+ expiry_dates , urls = options_object ._get_expiry_dates_and_links ()
330
+ url = options_object ._FINANCE_BASE_URL + urls [expiry_dates [0 ]]
331
+ quote_price , quote_time = options_object ._get_underlying_price (url )
332
+ except RemoteDataError as e :
333
+ raise nose .SkipTest (e )
334
+ self .assert_ (isinstance (quote_price , float ))
335
+
325
336
def test_sample_page_price_quote_time1 (self ):
326
337
#Tests the weekend quote time format
327
338
price , quote_time = self .aapl ._get_underlying_price (self .html1 )
You can’t perform that action at this time.
0 commit comments