Description
I think get_quote_yahoo and get_components_yahoo in data.py need to decode the bytes returned by urllib.request.urlopen(urlStr).readlines() and urllib.urlopen(urlStr).read().strip().strip('"').split('"\r\n"') in python3.3
Also, the expected INTC values in test_get_data() in test_yahoo.py do not agree with the values Yahoo returns. The Adj Close value for 1-18-12 is 24.28 and the calculated Ret_Index values do not agree with the values in the d array.
The tests pass after making these changes. I have not tested the changes in python2.x
diff --git a/pandas/io/data.py b/pandas/io/data.py
index 5e92fca..dfba151 100644
--- a/pandas/io/data.py
+++ b/pandas/io/data.py
@@ -115,7 +115,7 @@ def get_quote_yahoo(symbols):
return None
for line in lines:
- fields = line.strip().split(',')
+ fields = line.decode().strip().split(',')
for i, field in enumerate(fields):
if field[-2:] == '%"':
data[header[i]].append(float(field.strip('"%')))
@@ -241,7 +241,7 @@ def get_components_yahoo(idx_sym):
#break when no new components are found
while (True in mask):
urlStr = url.format(idx_mod, stats, comp_idx)
- lines = (urllib.urlopen(urlStr).read().strip().
+ lines = (urllib.urlopen(urlStr).read().decode().strip().
strip('"').split('"\r\n"'))
lines = [line.strip().split('","') for line in lines]
diff --git a/pandas/io/tests/test_yahoo.py b/pandas/io/tests/test_yahoo.py
index 1f25e3c..d07c5fd 100644
--- a/pandas/io/tests/test_yahoo.py
+++ b/pandas/io/tests/test_yahoo.py
@@ -92,15 +92,15 @@ class TestYahoo(unittest.TestCase):
pan = web.get_data_yahoo(dfi, 'JAN-01-12', 'JAN-31-12',
adjust_price=True)
- expected = [18.38, 27.45, 24.54]
+ expected = [18.38, 27.45, 24.28]
result = pan.Close.ix['01-18-12'][['GE', 'MSFT', 'INTC']].tolist()
assert result == expected
pan = web.get_data_yahoo(dfi, '2011', ret_index=True)
- d = [[ 1.01757469, 1.01130524, 1.02414183],
- [ 1.00292912, 1.00770812, 1.01735194],
- [ 1.00820152, 1.00462487, 1.01320257],
- [ 1.08025776, 0.99845838, 1.00113165]]
+ d = [[ 1.01757469, 1.01142857, 1.02414183],
+ [ 1.00292912, 1.00779221, 1.01735194],
+ [ 1.00820152, 1.00519481, 1.01320257],
+ [ 1.08025776, 0.99896104, 1.00113165]]
expected = pd.DataFrame(d)
result = pan.Ret_Index.ix['01-18-11':'01-21-11'][['GE', 'INTC', 'MSFT']]
original errors
nosetests-3.3 pandas.io.tests.test_yahoo.TestYahoo pandas
.EEE
ERROR: test_get_quote (pandas.io.tests.test_yahoo.TestYahoo)
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/pandas-0.11.0.dev_b0ee363-py3.3-macosx-10.6-intel.egg/pandas/io/tests/test_yahoo.py", line 49, in test_get_quote
df = web.get_quote_yahoo(pd.Series(['GOOG', 'AAPL', 'GOOG']))
File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/pandas-0.11.0.dev_b0ee363-py3.3-macosx-10.6-intel.egg/pandas/io/data.py", line 118, in get_quote_yahoo
fields = line.strip().split(',')
TypeError: Type str doesn't support the buffer API
ERROR: test_get_components (pandas.io.tests.test_yahoo.TestYahoo)
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/pandas-0.11.0.dev_b0ee363-py3.3-macosx-10.6-intel.egg/pandas/io/tests/test_yahoo.py", line 57, in test_get_components
df = web.get_components_yahoo('^DJI') #Dow Jones
File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/pandas-0.11.0.dev_b0ee363-py3.3-macosx-10.6-intel.egg/pandas/io/data.py", line 245, in get_components_yahoo
strip('"').split('"\r\n"'))
TypeError: Type str doesn't support the buffer API
ERROR: test_get_data (pandas.io.tests.test_yahoo.TestYahoo)
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/pandas-0.11.0.dev_b0ee363-py3.3-macosx-10.6-intel.egg/pandas/io/tests/test_yahoo.py", line 87, in test_get_data
dfi = web.get_components_yahoo('^DJI')
File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/pandas-0.11.0.dev_b0ee363-py3.3-macosx-10.6-intel.egg/pandas/io/data.py", line 245, in get_components_yahoo
strip('"').split('"\r\n"'))
TypeError: Type str doesn't support the buffer API
Ran 4 tests in 0.962s
FAILED (errors=3)