diff --git a/doc/source/whatsnew/v0.15.2.txt b/doc/source/whatsnew/v0.15.2.txt index d64dbf6e14345..73c72ae963f60 100644 --- a/doc/source/whatsnew/v0.15.2.txt +++ b/doc/source/whatsnew/v0.15.2.txt @@ -221,3 +221,5 @@ Bug Fixes - Fixed ValueError raised by cummin/cummax when datetime64 Series contains NaT. (:issue:`8965`) + +- Bug in ``Options`` where parsing the underlying price returns a ValueError when the price has a thousands separator in the HTML text. (:issue:`9010`) diff --git a/pandas/io/data.py b/pandas/io/data.py index 0827d74191842..8216b41014320 100644 --- a/pandas/io/data.py +++ b/pandas/io/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: + # see if there is a comma thousands separator in here that needs to be filtered out + # filtering via join works in both Python 2.7 and Python 3 + underlying_price = ''.join(c for c in underlying_price if c != ',') + 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: @@ -1192,6 +1203,7 @@ def _process_data(self, frame, type): frame["Quote_Time"] = np.nan frame.rename(columns={'Open Int': 'Open_Int'}, inplace=True) frame['Type'] = type + frame.set_index(['Strike', 'Expiry', 'Type', 'Symbol'], inplace=True) return frame diff --git a/pandas/io/tests/test_data.py b/pandas/io/tests/test_data.py index 3fca0393339fc..b23873eecd918 100644 --- a/pandas/io/tests/test_data.py +++ b/pandas/io/tests/test_data.py @@ -320,6 +320,17 @@ def test_get_expiry_dates(self): raise nose.SkipTest(e) self.assertTrue(len(dates) > 1) + @network + def test_get_underlying_price(self): + try: + options_object = web.Options('^spxpm', 'yahoo') + expiry_dates, urls = options_object._get_expiry_dates_and_links() + url = options_object._FINANCE_BASE_URL + urls.values()[0] + quote_price, quote_time = options_object._get_underlying_price( url ) + except RemoteDataError as e: + raise nose.SkipTest(e) + self.assertIsInstance( quote_price, float ) + @network def test_get_all_data(self): try: