Skip to content

Gh9010 yahoo options parsing bug #9024

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 4 commits 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
2 changes: 2 additions & 0 deletions doc/source/whatsnew/v0.15.2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
16 changes: 14 additions & 2 deletions pandas/io/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]\
Copy link
Contributor

Choose a reason for hiding this comment

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

looks like this needs 1 more space to format properly

.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:
Expand Down Expand Up @@ -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

Copy link
Contributor

Choose a reason for hiding this comment

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

This is simpler

In [1]: '1,000'.replace(',','')
Out[1]: '1000'

frame.set_index(['Strike', 'Expiry', 'Type', 'Symbol'], inplace=True)

return frame
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