Skip to content

Commit 8594382

Browse files
Merge pull request #85 from davidastephens/csv_quote
BUG: get_quote_yahoo doesn't work with names that have commas.
2 parents 51ea56b + 9add09d commit 8594382

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

pandas_datareader/tests/test_data.py

+6
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,12 @@ def test_get_quote_stringlist(self):
171171
df = web.get_quote_yahoo(['GOOG', 'AAPL', 'GOOG'])
172172
assert_series_equal(df.ix[0], df.ix[2])
173173

174+
def test_get_quote_comma_name(self):
175+
_yahoo_codes.update({'name': 'n'})
176+
df = web.get_quote_yahoo(['RGLD'])
177+
del _yahoo_codes['name']
178+
self.assertEqual(df['name'][0], 'Royal Gold, Inc.')
179+
174180
def test_get_components_dow_jones(self): # pragma: no cover
175181
raise nose.SkipTest('unreliable test, receive partial components back for dow_jones')
176182

pandas_datareader/yahoo/quotes.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
from collections import defaultdict
2+
import csv
3+
24
import pandas.compat as compat
35
from pandas.io.common import urlopen
46
from pandas import DataFrame
@@ -37,9 +39,12 @@ def _get_data(symbols):
3739
with urlopen(url) as response:
3840
lines = response.readlines()
3941

40-
for line in lines:
41-
fields = line.decode('utf-8').strip().split(',')
42-
for i, field in enumerate(fields):
42+
def line_gen(lines):
43+
for line in lines:
44+
yield line.decode('utf-8').strip()
45+
46+
for line in csv.reader(line_gen(lines)):
47+
for i, field in enumerate(line):
4348
if field[-2:] == '%"':
4449
v = float(field.strip('"%'))
4550
elif field[0] == '"':

0 commit comments

Comments
 (0)