Skip to content

Commit 10ba6a3

Browse files
committed
Merge pull request #8743 from dstephens99/issue8433
BUG: DataReaders return missing data as NaN rather than warn.
2 parents 1887ba5 + e9cb077 commit 10ba6a3

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

doc/source/whatsnew/v0.15.1.txt

+2
Original file line numberDiff line numberDiff line change
@@ -300,3 +300,5 @@ Bug Fixes
300300
- Bug in ``date_range`` where partially-specified dates would incorporate current date (:issue:`6961`)
301301

302302
- Bug in Setting by indexer to a scalar value with a mixed-dtype `Panel4d` was failing (:issue:`8702`)
303+
304+
- 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`)

pandas/io/data.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -317,16 +317,22 @@ def get_components_yahoo(idx_sym):
317317
def _dl_mult_symbols(symbols, start, end, chunksize, retry_count, pause,
318318
method):
319319
stocks = {}
320+
failed = []
320321
for sym_group in _in_chunks(symbols, chunksize):
321322
for sym in sym_group:
322323
try:
323324
stocks[sym] = method(sym, start, end, retry_count, pause)
324325
except IOError:
325326
warnings.warn('Failed to read symbol: {0!r}, replacing with '
326327
'NaN.'.format(sym), SymbolWarning)
327-
stocks[sym] = np.nan
328+
failed.append(sym)
328329

329330
try:
331+
if len(stocks) > 0 and len(failed) > 0:
332+
df_na = stocks.values()[0].copy()
333+
df_na[:] = np.nan
334+
for sym in failed:
335+
stocks[sym] = df_na
330336
return Panel(stocks).swapaxes('items', 'minor')
331337
except AttributeError:
332338
# cannot construct a panel with just 1D nans indicating no data

pandas/io/tests/test_data.py

+6
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ def test_get_multi1(self):
9494
else:
9595
self.assertRaises(AttributeError, lambda: pan.Close)
9696

97+
@network
98+
def test_get_multi_invalid(self):
99+
sl = ['AAPL', 'AMZN', 'INVALID']
100+
pan = web.get_data_google(sl, '2012')
101+
self.assertIn('INVALID', pan.minor_axis)
102+
97103
@network
98104
def test_get_multi2(self):
99105
with warnings.catch_warnings(record=True) as w:

0 commit comments

Comments
 (0)