Skip to content

BUG: DataReaders return missing data as NaN rather than warn. #8743

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 6, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/source/whatsnew/v0.15.1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
8 changes: 7 additions & 1 deletion pandas/io/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,16 +317,22 @@ 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:
stocks[sym] = method(sym, start, end, 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
Expand Down
6 changes: 6 additions & 0 deletions pandas/io/tests/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down