|
1 | 1 | import datetime |
| 2 | +from io import StringIO |
2 | 3 | import time |
3 | 4 | from urllib.parse import urlencode |
4 | 5 | import warnings |
|
13 | 14 | _init_session, |
14 | 15 | _sanitize_dates, |
15 | 16 | ) |
16 | | -from pandas_datareader.compat import ( |
17 | | - PANDAS_0230, |
18 | | - StringIO, |
19 | | - binary_type, |
20 | | - bytes_to_str, |
21 | | - string_types, |
22 | | -) |
23 | 17 |
|
24 | 18 |
|
25 | 19 | class _BaseReader(object): |
@@ -124,8 +118,8 @@ def _read_url_as_StringIO(self, url, params=None): |
124 | 118 | "{} request returned no data; check URL for invalid " |
125 | 119 | "inputs: {}".format(service, self.url) |
126 | 120 | ) |
127 | | - if isinstance(text, binary_type): |
128 | | - out.write(bytes_to_str(text)) |
| 121 | + if isinstance(text, bytes): |
| 122 | + out.write(text.decode("utf-8")) |
129 | 123 | else: |
130 | 124 | out.write(text) |
131 | 125 | out.seek(0) |
@@ -248,7 +242,7 @@ def _get_params(self, *args, **kwargs): |
248 | 242 | def read(self): |
249 | 243 | """Read data""" |
250 | 244 | # If a single symbol, (e.g., 'GOOG') |
251 | | - if isinstance(self.symbols, (string_types, int)): |
| 245 | + if isinstance(self.symbols, (str, int)): |
252 | 246 | df = self._read_one_data(self.url, params=self._get_params(self.symbols)) |
253 | 247 | # Or multiple symbols, (e.g., ['GOOG', 'AAPL', 'MSFT']) |
254 | 248 | elif isinstance(self.symbols, DataFrame): |
@@ -280,11 +274,8 @@ def _dl_mult_symbols(self, symbols): |
280 | 274 | df_na[:] = np.nan |
281 | 275 | for sym in failed: |
282 | 276 | stocks[sym] = df_na |
283 | | - if PANDAS_0230: |
284 | 277 | result = concat(stocks, sort=True).unstack(level=0) |
285 | | - else: |
286 | | - result = concat(stocks).unstack(level=0) |
287 | | - result.columns.names = ["Attributes", "Symbols"] |
| 278 | + result.columns.names = ["Attributes", "Symbols"] |
288 | 279 | return result |
289 | 280 | except AttributeError as exc: |
290 | 281 | # cannot construct a panel with just 1D nans indicating no data |
|
0 commit comments