Skip to content

Commit 1b20593

Browse files
COMPAT: Fix dl_mult_symbols for Python3
1 parent dd857ba commit 1b20593

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

pandas/io/data.py

+7-3
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/io/tests/test_data.py

+4
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ def test_get_multi_invalid(self):
101101
self.assertIn('INVALID', pan.minor_axis)
102102

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

0 commit comments

Comments
 (0)