diff --git a/doc/source/whatsnew/v0.15.1.txt b/doc/source/whatsnew/v0.15.1.txt index aca3e651c7ddf..f0767b9d66c24 100644 --- a/doc/source/whatsnew/v0.15.1.txt +++ b/doc/source/whatsnew/v0.15.1.txt @@ -300,3 +300,5 @@ Bug Fixes - Bug in ``date_range`` where partially-specified dates would incorporate current date (:issue:`6961`) - Bug in Setting by indexer to a scalar value with a mixed-dtype `Panel4d` was failing (:issue:`8702`) + +- Bug where ``DataReader``'s would fail if one of the symbols passed was invalid. Now returns data for valid symbols and np.nan for invalid (:issue:`8494`) \ No newline at end of file diff --git a/pandas/io/data.py b/pandas/io/data.py index 6cad478ee841b..8e7474b6e5d1d 100644 --- a/pandas/io/data.py +++ b/pandas/io/data.py @@ -317,6 +317,7 @@ def get_components_yahoo(idx_sym): def _dl_mult_symbols(symbols, start, end, chunksize, retry_count, pause, method): stocks = {} + failed = [] for sym_group in _in_chunks(symbols, chunksize): for sym in sym_group: try: @@ -324,9 +325,14 @@ def _dl_mult_symbols(symbols, start, end, chunksize, retry_count, pause, except IOError: warnings.warn('Failed to read symbol: {0!r}, replacing with ' 'NaN.'.format(sym), SymbolWarning) - stocks[sym] = np.nan + failed.append(sym) try: + if len(stocks) > 0 and len(failed) > 0: + df_na = stocks.values()[0].copy() + df_na[:] = np.nan + for sym in failed: + stocks[sym] = df_na return Panel(stocks).swapaxes('items', 'minor') except AttributeError: # cannot construct a panel with just 1D nans indicating no data diff --git a/pandas/io/tests/test_data.py b/pandas/io/tests/test_data.py index f872c15446f08..549a60a85e25e 100644 --- a/pandas/io/tests/test_data.py +++ b/pandas/io/tests/test_data.py @@ -94,6 +94,12 @@ def test_get_multi1(self): else: self.assertRaises(AttributeError, lambda: pan.Close) + @network + def test_get_multi_invalid(self): + sl = ['AAPL', 'AMZN', 'INVALID'] + pan = web.get_data_google(sl, '2012') + self.assertIn('INVALID', pan.minor_axis) + @network def test_get_multi2(self): with warnings.catch_warnings(record=True) as w: