diff --git a/doc/source/whatsnew/v0.16.0.txt b/doc/source/whatsnew/v0.16.0.txt index 21b1ddea0e9da..03f90c74ea4b7 100644 --- a/doc/source/whatsnew/v0.16.0.txt +++ b/doc/source/whatsnew/v0.16.0.txt @@ -141,3 +141,4 @@ Bug Fixes - Bug in read_csv when using skiprows on a file with CR line endings with the c engine. (:issue:`9079`) - isnull now detects NaT in PeriodIndex (:issue:`9129`) - Bug in groupby ``.nth()`` with a multiple column groupby (:issue:`8979`) +- 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 3d92d383badf8..5f9c57534cd20 100644 --- a/pandas/io/data.py +++ b/pandas/io/data.py @@ -698,8 +698,18 @@ 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 that needs to be filtered out + 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: diff --git a/pandas/io/tests/test_data.py b/pandas/io/tests/test_data.py index a65722dc76556..45cb7b648e9dc 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: