Skip to content

BUG: fix for GH9010 #9198

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.16.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
14 changes: 12 additions & 2 deletions pandas/io/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 != ',')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think this should just be underlying_price.replace(',', ''). As noted in the other PR, this method is not deprecated in Python 3: https://docs.python.org/3/library/stdtypes.html#str.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:
Expand Down
11 changes: 11 additions & 0 deletions pandas/io/tests/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down