Skip to content

BUG:Fix options strike price float conversions if comma. #11

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

Merged
merged 1 commit into from
Jan 23, 2015
Merged
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
15 changes: 13 additions & 2 deletions pandas_datareader/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]\
.getchildren()[0].text

try:
underlying_price = float(underlying_price)
except ValueError:
# check for comma
underlying_price = underlying_price.replace(',', '')

try:
Copy link
Member

Choose a reason for hiding this comment

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

Note: You could probably indent this block so float is only applied once is the usual case, or always replace (which may be cleaner).

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_datareader/tests/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down