File tree Expand file tree Collapse file tree 2 files changed +24
-2
lines changed Expand file tree Collapse file tree 2 files changed +24
-2
lines changed Original file line number Diff line number Diff line change @@ -706,8 +706,19 @@ def _option_frames_from_url(self, url):
706706
707707 def _get_underlying_price (self , url ):
708708 root = self ._parse_url (url )
709- underlying_price = float (root .xpath ('.//*[@class="time_rtq_ticker Fz-30 Fw-b"]' )[0 ]\
710- .getchildren ()[0 ].text )
709+ underlying_price = root .xpath ('.//*[@class="time_rtq_ticker Fz-30 Fw-b"]' )[0 ]\
710+ .getchildren ()[0 ].text
711+
712+ try :
713+ underlying_price = float (underlying_price )
714+ except ValueError :
715+ # check for comma
716+ underlying_price = underlying_price .replace (',' , '' )
717+
718+ try :
719+ underlying_price = float (underlying_price )
720+ except ValueError :
721+ underlying_price = np .nan
711722
712723 #Gets the time of the quote, note this is actually the time of the underlying price.
713724 try :
Original file line number Diff line number Diff line change @@ -328,6 +328,17 @@ def test_get_all_data_calls_only(self):
328328 raise nose .SkipTest (e )
329329 self .assertTrue (len (data ) > 1 )
330330
331+ def test_get_underlying_price (self ):
332+ #GH7
333+ try :
334+ options_object = web .Options ('^spxpm' , 'yahoo' )
335+ expiry_dates , urls = options_object ._get_expiry_dates_and_links ()
336+ url = options_object ._FINANCE_BASE_URL + urls [expiry_dates [0 ]]
337+ quote_price , quote_time = options_object ._get_underlying_price (url )
338+ except RemoteDataError as e :
339+ raise nose .SkipTest (e )
340+ self .assert_ (isinstance (quote_price , float ))
341+
331342 def test_sample_page_price_quote_time1 (self ):
332343 #Tests the weekend quote time format
333344 price , quote_time = self .aapl ._get_underlying_price (self .html1 )
You can’t perform that action at this time.
0 commit comments