diff --git a/pandas_datareader/data.py b/pandas_datareader/data.py index 3d92d383..f4905308 100644 --- a/pandas_datareader/data.py +++ b/pandas_datareader/data.py @@ -698,8 +698,19 @@ def _option_frames_from_url(self, url): def _get_underlying_price(self, url): root = self._parse_url(url) - underlying_price = float(root.xpath('.//*[@class="time_rtq_ticker Fz-30 Fw-b"]')[0]\ - .getchildren()[0].text) + underlying_price = root.xpath('.//*[@class="time_rtq_ticker Fz-30 Fw-b"]')[0]\ + .getchildren()[0].text + + try: + underlying_price = float(underlying_price) + except ValueError: + # check for comma + underlying_price = underlying_price.replace(',', '') + + try: + underlying_price = float(underlying_price) + except ValueError: + underlying_price = np.nan #Gets the time of the quote, note this is actually the time of the underlying price. try: diff --git a/pandas_datareader/tests/test_data.py b/pandas_datareader/tests/test_data.py index ee72f090..731aae78 100644 --- a/pandas_datareader/tests/test_data.py +++ b/pandas_datareader/tests/test_data.py @@ -322,6 +322,17 @@ def test_get_all_data_calls_only(self): raise nose.SkipTest(e) self.assertTrue(len(data) > 1) + def test_get_underlying_price(self): + #GH7 + try: + options_object = web.Options('^spxpm', 'yahoo') + expiry_dates, urls = options_object._get_expiry_dates_and_links() + url = options_object._FINANCE_BASE_URL + urls[expiry_dates[0]] + quote_price, quote_time = options_object._get_underlying_price(url) + except RemoteDataError as e: + raise nose.SkipTest(e) + self.assert_(isinstance(quote_price, float)) + def test_sample_page_price_quote_time1(self): #Tests the weekend quote time format price, quote_time = self.aapl._get_underlying_price(self.html1)