Skip to content

COMPAT: Fix dl_mult_symbols for python3 #35

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
Apr 7, 2015
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
10 changes: 7 additions & 3 deletions pandas_datareader/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}


Expand Down
4 changes: 4 additions & 0 deletions pandas_datareader/tests/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down