Skip to content

Commit 59f09cc

Browse files
BUG:Fix options strike price float conversions if comma.
1 parent 0a20235 commit 59f09cc

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

pandas_datareader/data.py

+13-2
Original file line numberDiff line numberDiff line change
@@ -698,8 +698,19 @@ def _option_frames_from_url(self, url):
698698

699699
def _get_underlying_price(self, url):
700700
root = self._parse_url(url)
701-
underlying_price = float(root.xpath('.//*[@class="time_rtq_ticker Fz-30 Fw-b"]')[0]\
702-
.getchildren()[0].text)
701+
underlying_price = root.xpath('.//*[@class="time_rtq_ticker Fz-30 Fw-b"]')[0]\
702+
.getchildren()[0].text
703+
704+
try:
705+
underlying_price = float(underlying_price)
706+
except ValueError:
707+
# check for comma
708+
underlying_price = underlying_price.replace(',', '')
709+
710+
try:
711+
underlying_price = float(underlying_price)
712+
except ValueError:
713+
underlying_price = np.nan
703714

704715
#Gets the time of the quote, note this is actually the time of the underlying price.
705716
try:

pandas_datareader/tests/test_data.py

+11
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,17 @@ def test_get_all_data_calls_only(self):
322322
raise nose.SkipTest(e)
323323
self.assertTrue(len(data) > 1)
324324

325+
def test_get_underlying_price(self):
326+
#GH7
327+
try:
328+
options_object = web.Options('^spxpm', 'yahoo')
329+
expiry_dates, urls = options_object._get_expiry_dates_and_links()
330+
url = options_object._FINANCE_BASE_URL + urls[expiry_dates[0]]
331+
quote_price, quote_time = options_object._get_underlying_price(url)
332+
except RemoteDataError as e:
333+
raise nose.SkipTest(e)
334+
self.assert_(isinstance(quote_price, float))
335+
325336
def test_sample_page_price_quote_time1(self):
326337
#Tests the weekend quote time format
327338
price, quote_time = self.aapl._get_underlying_price(self.html1)

0 commit comments

Comments
 (0)