Skip to content

Commit a01810e

Browse files
committed
Merge pull request #9742 from dstephens99/data_reader_update
BUG: Bring pandas up to date with pandas-datareader
2 parents 8d2818e + 1b20593 commit a01810e

File tree

3 files changed

+2832
-13
lines changed

3 files changed

+2832
-13
lines changed

pandas/io/data.py

+14-13
Original file line numberDiff line numberDiff line change
@@ -172,14 +172,14 @@ def _retry_read_url(url, retry_count, pause, name):
172172
if len(rs) > 2 and rs.index[-1] == rs.index[-2]: # pragma: no cover
173173
rs = rs[:-1]
174174

175-
#Get rid of unicode characters in index name.
176-
try:
177-
rs.index.name = rs.index.name.decode('unicode_escape').encode('ascii', 'ignore')
178-
except AttributeError:
179-
#Python 3 string has no decode method.
180-
rs.index.name = rs.index.name.encode('ascii', 'ignore').decode()
175+
#Get rid of unicode characters in index name.
176+
try:
177+
rs.index.name = rs.index.name.decode('unicode_escape').encode('ascii', 'ignore')
178+
except AttributeError:
179+
#Python 3 string has no decode method.
180+
rs.index.name = rs.index.name.encode('ascii', 'ignore').decode()
181181

182-
return rs
182+
return rs
183183

184184
raise IOError("after %d tries, %s did not "
185185
"return a 200 for url %r" % (retry_count, name, url))
@@ -326,18 +326,23 @@ def _dl_mult_symbols(symbols, start, end, interval, chunksize, retry_count, paus
326326
method):
327327
stocks = {}
328328
failed = []
329+
passed = []
329330
for sym_group in _in_chunks(symbols, chunksize):
330331
for sym in sym_group:
331332
try:
332333
stocks[sym] = method(sym, start, end, interval, retry_count, pause)
334+
passed.append(sym)
333335
except IOError:
334336
warnings.warn('Failed to read symbol: {0!r}, replacing with '
335337
'NaN.'.format(sym), SymbolWarning)
336338
failed.append(sym)
337339

340+
if len(passed) == 0:
341+
raise RemoteDataError("No data fetched using "
342+
"{0!r}".format(method.__name__))
338343
try:
339-
if len(stocks) > 0 and len(failed) > 0:
340-
df_na = stocks.values()[0].copy()
344+
if len(stocks) > 0 and len(failed) > 0 and len(passed) > 0:
345+
df_na = stocks[passed[0]].copy()
341346
df_na[:] = np.nan
342347
for sym in failed:
343348
stocks[sym] = df_na
@@ -347,7 +352,6 @@ def _dl_mult_symbols(symbols, start, end, interval, chunksize, retry_count, paus
347352
raise RemoteDataError("No data fetched using "
348353
"{0!r}".format(method.__name__))
349354

350-
351355
_source_functions = {'google': _get_hist_google, 'yahoo': _get_hist_yahoo}
352356

353357

@@ -701,9 +705,6 @@ def _option_frames_from_url(self, url):
701705
calls = frames[self._TABLE_LOC['calls']]
702706
puts = frames[self._TABLE_LOC['puts']]
703707

704-
if len(calls) == 0 or len(puts) == 0:
705-
raise RemoteDataError('Received no data from Yahoo at url: %s' % url)
706-
707708
calls = self._process_data(calls, 'call')
708709
puts = self._process_data(puts, 'put')
709710

0 commit comments

Comments
 (0)