Skip to content

Commit 7adaca5

Browse files
Merge pull request #35 from dstephens99/TestGoogle
COMPAT: Fix dl_mult_symbols for python3
2 parents a02e66b + 6fb9321 commit 7adaca5

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

pandas_datareader/data.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,18 +326,23 @@ def _dl_mult_symbols(symbols, start, end, interval, chunksize, retry_count, paus
326326
method):
327327
stocks = {}
328328
failed = []
329+
passed = []
329330
for sym_group in _in_chunks(symbols, chunksize):
330331
for sym in sym_group:
331332
try:
332333
stocks[sym] = method(sym, start, end, interval, retry_count, pause)
334+
passed.append(sym)
333335
except IOError:
334336
warnings.warn('Failed to read symbol: {0!r}, replacing with '
335337
'NaN.'.format(sym), SymbolWarning)
336338
failed.append(sym)
337339

340+
if len(passed) == 0:
341+
raise RemoteDataError("No data fetched using "
342+
"{0!r}".format(method.__name__))
338343
try:
339-
if len(stocks) > 0 and len(failed) > 0:
340-
df_na = stocks.values()[0].copy()
344+
if len(stocks) > 0 and len(failed) > 0 and len(passed) > 0:
345+
df_na = stocks[passed[0]].copy()
341346
df_na[:] = np.nan
342347
for sym in failed:
343348
stocks[sym] = df_na
@@ -347,7 +352,6 @@ def _dl_mult_symbols(symbols, start, end, interval, chunksize, retry_count, paus
347352
raise RemoteDataError("No data fetched using "
348353
"{0!r}".format(method.__name__))
349354

350-
351355
_source_functions = {'google': _get_hist_google, 'yahoo': _get_hist_yahoo}
352356

353357

pandas_datareader/tests/test_data.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ def test_get_multi_invalid(self):
100100
pan = web.get_data_google(sl, '2012')
101101
self.assertIn('INVALID', pan.minor_axis)
102102

103+
def test_get_multi_all_invalid(self):
104+
sl = ['INVALID', 'INVALID2', 'INVALID3']
105+
self.assertRaises(RemoteDataError, web.get_data_google, sl, '2012')
106+
103107
def test_get_multi2(self):
104108
with warnings.catch_warnings(record=True) as w:
105109
for locale in self.locales:

0 commit comments

Comments
 (0)