diff --git a/pandas_datareader/data.py b/pandas_datareader/data.py index 936e5fac..3e077bf5 100644 --- a/pandas_datareader/data.py +++ b/pandas_datareader/data.py @@ -326,18 +326,23 @@ def _dl_mult_symbols(symbols, start, end, interval, chunksize, retry_count, paus method): stocks = {} failed = [] + passed = [] for sym_group in _in_chunks(symbols, chunksize): for sym in sym_group: try: stocks[sym] = method(sym, start, end, interval, retry_count, pause) + passed.append(sym) except IOError: warnings.warn('Failed to read symbol: {0!r}, replacing with ' 'NaN.'.format(sym), SymbolWarning) failed.append(sym) + if len(passed) == 0: + raise RemoteDataError("No data fetched using " + "{0!r}".format(method.__name__)) try: - if len(stocks) > 0 and len(failed) > 0: - df_na = stocks.values()[0].copy() + if len(stocks) > 0 and len(failed) > 0 and len(passed) > 0: + df_na = stocks[passed[0]].copy() df_na[:] = np.nan for sym in failed: stocks[sym] = df_na @@ -347,7 +352,6 @@ def _dl_mult_symbols(symbols, start, end, interval, chunksize, retry_count, paus raise RemoteDataError("No data fetched using " "{0!r}".format(method.__name__)) - _source_functions = {'google': _get_hist_google, 'yahoo': _get_hist_yahoo} diff --git a/pandas_datareader/tests/test_data.py b/pandas_datareader/tests/test_data.py index b8a7afc1..5b38e0f0 100644 --- a/pandas_datareader/tests/test_data.py +++ b/pandas_datareader/tests/test_data.py @@ -100,6 +100,10 @@ def test_get_multi_invalid(self): pan = web.get_data_google(sl, '2012') self.assertIn('INVALID', pan.minor_axis) + def test_get_multi_all_invalid(self): + sl = ['INVALID', 'INVALID2', 'INVALID3'] + self.assertRaises(RemoteDataError, web.get_data_google, sl, '2012') + def test_get_multi2(self): with warnings.catch_warnings(record=True) as w: for locale in self.locales: