Skip to content

Commit

Permalink
Merge pull request #85 from davidastephens/csv_quote
Browse files Browse the repository at this point in the history
BUG: get_quote_yahoo doesn't work with names that have commas.
  • Loading branch information
davidastephens committed Sep 21, 2015
2 parents 51ea56b + 9add09d commit 8594382
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
6 changes: 6 additions & 0 deletions pandas_datareader/tests/test_data.py
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
@@ -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

0 comments on commit 8594382

Please sign in to comment.