Skip to content

Commit

Permalink
Merge pull request #11 from dstephens99/issue7
Browse files Browse the repository at this point in the history
BUG:Fix options strike price float conversions if comma.
  • Loading branch information
davidastephens committed Jan 23, 2015
2 parents 1a39330 + 59f09cc commit 5d7f044
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
15 changes: 13 additions & 2 deletions pandas_datareader/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,8 +706,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:
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 @@ -328,6 +328,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

0 comments on commit 5d7f044

Please sign in to comment.