Skip to content

BUG: get_quote_yahoo doesn't work with names that have commas. #85

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
Sep 21, 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
6 changes: 6 additions & 0 deletions pandas_datareader/tests/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,12 @@ def test_get_quote_stringlist(self):
df = web.get_quote_yahoo(['GOOG', 'AAPL', 'GOOG'])
assert_series_equal(df.ix[0], df.ix[2])

def test_get_quote_comma_name(self):
_yahoo_codes.update({'name': 'n'})
df = web.get_quote_yahoo(['RGLD'])
del _yahoo_codes['name']
self.assertEqual(df['name'][0], 'Royal Gold, Inc.')

def test_get_components_dow_jones(self): # pragma: no cover
raise nose.SkipTest('unreliable test, receive partial components back for dow_jones')

Expand Down
11 changes: 8 additions & 3 deletions pandas_datareader/yahoo/quotes.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from collections import defaultdict
import csv

import pandas.compat as compat
from pandas.io.common import urlopen
from pandas import DataFrame
Expand Down Expand Up @@ -37,9 +39,12 @@ def _get_data(symbols):
with urlopen(url) as response:
lines = response.readlines()

for line in lines:
fields = line.decode('utf-8').strip().split(',')
for i, field in enumerate(fields):
def line_gen(lines):
for line in lines:
yield line.decode('utf-8').strip()

for line in csv.reader(line_gen(lines)):
for i, field in enumerate(line):
if field[-2:] == '%"':
v = float(field.strip('"%'))
elif field[0] == '"':
Expand Down