Skip to content

Commit 94a7d37

Browse files
committed
MAINT: More work on broken APIs
1 parent 89cf44b commit 94a7d37

File tree

19 files changed

+40
-115
lines changed

19 files changed

+40
-115
lines changed

pandas_datareader/bankofcanada.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from __future__ import unicode_literals
22

33
from pandas_datareader.base import _BaseReader
4-
from pandas_datareader.compat import string_types
54

65

76
class BankOfCanadaReader(_BaseReader):
@@ -16,7 +15,7 @@ class BankOfCanadaReader(_BaseReader):
1615
@property
1716
def url(self):
1817
"""API URL"""
19-
if not isinstance(self.symbols, string_types):
18+
if not isinstance(self.symbols, str):
2019
raise ValueError("data name must be string")
2120

2221
return "{0}/{1}/csv".format(self._URL, self.symbols)

pandas_datareader/base.py

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import datetime
2+
from io import StringIO
23
import time
34
from urllib.parse import urlencode
45
import warnings
@@ -13,13 +14,6 @@
1314
_init_session,
1415
_sanitize_dates,
1516
)
16-
from pandas_datareader.compat import (
17-
PANDAS_0230,
18-
StringIO,
19-
binary_type,
20-
bytes_to_str,
21-
string_types,
22-
)
2317

2418

2519
class _BaseReader(object):
@@ -124,8 +118,8 @@ def _read_url_as_StringIO(self, url, params=None):
124118
"{} request returned no data; check URL for invalid "
125119
"inputs: {}".format(service, self.url)
126120
)
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"))
129123
else:
130124
out.write(text)
131125
out.seek(0)
@@ -248,7 +242,7 @@ def _get_params(self, *args, **kwargs):
248242
def read(self):
249243
"""Read data"""
250244
# If a single symbol, (e.g., 'GOOG')
251-
if isinstance(self.symbols, (string_types, int)):
245+
if isinstance(self.symbols, (str, int)):
252246
df = self._read_one_data(self.url, params=self._get_params(self.symbols))
253247
# Or multiple symbols, (e.g., ['GOOG', 'AAPL', 'MSFT'])
254248
elif isinstance(self.symbols, DataFrame):
@@ -280,11 +274,8 @@ def _dl_mult_symbols(self, symbols):
280274
df_na[:] = np.nan
281275
for sym in failed:
282276
stocks[sym] = df_na
283-
if PANDAS_0230:
284277
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"]
288279
return result
289280
except AttributeError as exc:
290281
# cannot construct a panel with just 1D nans indicating no data

pandas_datareader/compat/__init__.py

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,13 @@
77
from pandas.io import common as com
88
from pandas.testing import assert_frame_equal
99

10-
PANDAS_VERSION = version.parse(pd.__version__)
11-
12-
PANDAS_0210 = PANDAS_VERSION >= version.parse("0.21.0")
13-
PANDAS_0220 = PANDAS_VERSION >= version.parse("0.22.0")
14-
PANDAS_0230 = PANDAS_VERSION >= version.parse("0.23.0")
15-
1610
__all__ = [
1711
"HTTPError",
1812
"StringIO",
19-
"PANDAS_0210",
20-
"PANDAS_0220",
21-
"PANDAS_0230",
2213
"get_filepath_or_buffer",
23-
"str_to_bytes",
24-
"string_types",
2514
"assert_frame_equal",
2615
"is_list_like",
2716
"is_number",
28-
"lmap",
29-
"lrange",
30-
"concat",
3117
"reduce",
3218
]
3319

@@ -47,34 +33,3 @@ def get_filepath_or_buffer(filepath_or_buffer, encoding=None, compression=None):
4733
filepath_or_buffer, encoding=encoding, compression=None
4834
)
4935
return tmp
50-
51-
52-
string_types = (str,)
53-
binary_type = bytes
54-
55-
56-
def str_to_bytes(s, encoding=None):
57-
if isinstance(s, bytes):
58-
return s
59-
return s.encode(encoding or "ascii")
60-
61-
62-
def bytes_to_str(b, encoding=None):
63-
return b.decode(encoding or "utf-8")
64-
65-
66-
def lmap(*args, **kwargs):
67-
return list(map(*args, **kwargs))
68-
69-
70-
def lrange(*args, **kwargs):
71-
return list(range(*args, **kwargs))
72-
73-
74-
def concat(*args, **kwargs):
75-
"""
76-
Shim to wokr around sort keyword
77-
"""
78-
if not PANDAS_0230 and "sort" in kwargs:
79-
del kwargs["sort"]
80-
return pd.concat(*args, **kwargs)

pandas_datareader/enigma.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import pandas as pd
55

6-
from pandas_datareader.base import _BaseReader, string_types
6+
from pandas_datareader.base import _BaseReader
77
from pandas_datareader.compat import StringIO
88
from pandas_datareader.exceptions import DEP_ERROR_MSG, ImmediateDeprecationError
99

@@ -71,7 +71,7 @@ def __init__(
7171
self._api_key = api_key
7272

7373
self._dataset_id = dataset_id
74-
if not isinstance(self._dataset_id, string_types):
74+
if not isinstance(self._dataset_id, str):
7575
raise ValueError(
7676
"The Enigma dataset_id must be a string (ex: "
7777
"'bedaf052-5fcd-4758-8d27-048ce8746c6a')"

pandas_datareader/eurostat.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import pandas as pd
44

55
from pandas_datareader.base import _BaseReader
6-
from pandas_datareader.compat import string_types
76
from pandas_datareader.io.sdmx import _read_sdmx_dsd, read_sdmx
87

98

@@ -15,7 +14,7 @@ class EurostatReader(_BaseReader):
1514
@property
1615
def url(self):
1716
"""API URL"""
18-
if not isinstance(self.symbols, string_types):
17+
if not isinstance(self.symbols, str):
1918
raise ValueError("data name must be string")
2019

2120
q = "{0}/data/{1}/?startperiod={2}&endperiod={3}"
@@ -24,7 +23,7 @@ def url(self):
2423
@property
2524
def dsd_url(self):
2625
"""API DSD URL"""
27-
if not isinstance(self.symbols, string_types):
26+
if not isinstance(self.symbols, str):
2827
raise ValueError("data name must be string")
2928

3029
return "{0}/datastructure/ESTAT/DSD_{1}".format(self._URL, self.symbols)

pandas_datareader/famafrench.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from pandas import read_csv, to_datetime
77

88
from pandas_datareader.base import _BaseReader
9-
from pandas_datareader.compat import StringIO, lmap
9+
from pandas_datareader.compat import StringIO
1010

1111
_URL = "http://mba.tuck.dartmouth.edu/pages/faculty/ken.french/"
1212
_URL_PREFIX = "ftp/"
@@ -162,4 +162,4 @@ def get_available_datasets(self):
162162
if ds.startswith(_URL_PREFIX) and ds.endswith(_URL_SUFFIX)
163163
]
164164

165-
return lmap(lambda x: x[len(_URL_PREFIX) : -len(_URL_SUFFIX)], datasets)
165+
return list(map(lambda x: x[len(_URL_PREFIX) : -len(_URL_SUFFIX)], datasets))

pandas_datareader/io/sdmx.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import pandas as pd
99

10-
from pandas_datareader.compat import HTTPError, str_to_bytes
10+
from pandas_datareader.compat import HTTPError
1111
from pandas_datareader.io.util import _read_content
1212

1313
_STRUCTURE = "{http://www.sdmx.org/resources/sdmxml/schemas/v2_1/structure}"
@@ -234,8 +234,10 @@ def _read_zipped_sdmx(path_or_buf):
234234
"""Unzipp data contains SDMX-XML"""
235235
data = _read_content(path_or_buf)
236236

237+
if not isinstance(data, bytes):
238+
data = data.encode("ascii")
237239
zp = BytesIO()
238-
zp.write(str_to_bytes(data))
240+
zp.write(data)
239241
f = zipfile.ZipFile(zp)
240242
files = f.namelist()
241243
assert len(files) == 1

pandas_datareader/io/util.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import os
44

5-
from pandas_datareader.compat import get_filepath_or_buffer, string_types
5+
from pandas_datareader.compat import get_filepath_or_buffer
66

77

88
def _read_content(path_or_buf):
@@ -12,7 +12,7 @@ def _read_content(path_or_buf):
1212

1313
filepath_or_buffer = get_filepath_or_buffer(path_or_buf)[0]
1414

15-
if isinstance(filepath_or_buffer, string_types):
15+
if isinstance(filepath_or_buffer, str):
1616
try:
1717
exists = os.path.exists(filepath_or_buffer)
1818
except (TypeError, ValueError):

pandas_datareader/moex.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import datetime as dt
2+
from io import StringIO
23

34
import pandas as pd
45

56
from pandas_datareader.base import _DailyBaseReader
6-
from pandas_datareader.compat import StringIO, binary_type, concat, is_list_like
7+
from pandas_datareader.compat import is_list_like
78

89

910
class MoexReader(_DailyBaseReader):
@@ -108,7 +109,7 @@ def _get_metadata(self):
108109
"{} request returned no data; check URL for invalid "
109110
"inputs: {}".format(service, self.__url_metadata)
110111
)
111-
if isinstance(text, binary_type):
112+
if isinstance(text, bytes):
112113
text = text.decode("windows-1251")
113114

114115
header_str = "secid;boardid;"
@@ -200,7 +201,7 @@ def read_all_boards(self):
200201
"check URL or correct a date".format(self.__class__.__name__)
201202
)
202203
elif len(dfs) > 1:
203-
b = concat(dfs, axis=0, join="outer", sort=True)
204+
b = pd.concat(dfs, axis=0, join="outer", sort=True)
204205
else:
205206
b = dfs[0]
206207
return b
@@ -228,7 +229,7 @@ def _read_url_as_String(self, url, params=None):
228229
"{} request returned no data; check URL for invalid "
229230
"inputs: {}".format(service, self.url)
230231
)
231-
if isinstance(text, binary_type):
232+
if isinstance(text, bytes):
232233
text = text.decode("windows-1251")
233234
return text
234235

pandas_datareader/naver.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
import numpy as np
55
from pandas import DataFrame, to_datetime
6-
from six import string_types
76

87
from pandas_datareader.base import _DailyBaseReader
98

@@ -32,7 +31,7 @@ def __init__(
3231
get_actions=False,
3332
adjust_dividends=True,
3433
):
35-
if not isinstance(symbols, string_types):
34+
if not isinstance(symbols, str):
3635
raise NotImplementedError("Bulk-fetching is not implemented")
3736

3837
super().__init__(

0 commit comments

Comments
 (0)