Skip to content

Commit 85f9210

Browse files
committed
MAINT: Fix flake8 complaints
1 parent d1edd7e commit 85f9210

22 files changed

+67
-61
lines changed

pandas_datareader/av/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,18 @@ def data_key(self):
7070
def _read_lines(self, out):
7171
try:
7272
df = pd.DataFrame.from_dict(out[self.data_key], orient="index")
73-
except KeyError:
73+
except KeyError as exc:
7474
if "Error Message" in out:
7575
raise ValueError(
7676
"The requested symbol {} could not be "
7777
"retrieved. Check valid ticker"
7878
".".format(self.symbols)
79-
)
79+
) from exc
8080
else:
8181
raise RemoteDataError(
8282
" Their was an issue from the data vendor "
8383
"side, here is their response: {}".format(out)
84-
)
84+
) from exc
8585
df = df[sorted(df.columns)]
8686
df.columns = [id[3:] for id in df.columns]
8787
return df

pandas_datareader/av/forex.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def __init__(
5656
"Please input a currency pair "
5757
"formatted 'FROM/TO' or a list of "
5858
"currency symbols"
59-
)
59+
) from e
6060

6161
@property
6262
def function(self):
@@ -88,8 +88,8 @@ def read(self):
8888
def _read_lines(self, out):
8989
try:
9090
df = pd.DataFrame.from_dict(out[self.data_key], orient="index")
91-
except KeyError:
92-
raise RemoteDataError()
91+
except KeyError as exc:
92+
raise RemoteDataError() from exc
9393
df.sort_index(ascending=True, inplace=True)
9494
df.index = [id[3:] for id in df.index]
9595
return df

pandas_datareader/base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ def _dl_mult_symbols(self, symbols):
268268
passed.append(sym)
269269
except (IOError, KeyError):
270270
msg = "Failed to read symbol: {0!r}, replacing with NaN."
271-
warnings.warn(msg.format(sym), SymbolWarning)
271+
warnings.warn(msg.format(sym), SymbolWarning, stacklevel=2)
272272
failed.append(sym)
273273

274274
if len(passed) == 0:
@@ -286,10 +286,10 @@ def _dl_mult_symbols(self, symbols):
286286
result = concat(stocks).unstack(level=0)
287287
result.columns.names = ["Attributes", "Symbols"]
288288
return result
289-
except AttributeError:
289+
except AttributeError as exc:
290290
# cannot construct a panel with just 1D nans indicating no data
291291
msg = "No data fetched using {0!r}"
292-
raise RemoteDataError(msg.format(self.__class__.__name__))
292+
raise RemoteDataError(msg.format(self.__class__.__name__)) from exc
293293

294294

295295
def _in_chunks(seq, size):

pandas_datareader/famafrench.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def _read_one_data(self, url, params):
8888
else:
8989
c = ["Count"]
9090
r = list(range(0, 105, 5))
91-
params["names"] = ["Date"] + c + list(zip(r, r[1:]))
91+
params["names"] = ["Date"] + c + list(zip(r, r[1:], strict=True))
9292

9393
if self.symbols != "Prior_2-12_Breakpoints":
9494
params["skiprows"] = 1
@@ -144,11 +144,11 @@ def get_available_datasets(self):
144144
"""
145145
try:
146146
from lxml.html import document_fromstring
147-
except ImportError:
147+
except ImportError as exc:
148148
raise ImportError(
149149
"Please install lxml if you want to use the "
150150
"get_datasets_famafrench function"
151-
)
151+
) from exc
152152

153153
response = self.session.get(_URL + "data_library.html")
154154
root = document_fromstring(response.content)

pandas_datareader/fred.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ def fetch_data(url, name):
5050
)
5151
try:
5252
return data.truncate(self.start, self.end)
53-
except KeyError: # pragma: no cover
53+
except KeyError as exc: # pragma: no cover
5454
if data.iloc[3].name[7:12] == "Error":
5555
raise IOError(
5656
"Failed to get the data. Check that "
5757
"{0!r} is a valid FRED series.".format(name)
58-
)
58+
) from exc
5959
raise
6060

6161
df = concat(

pandas_datareader/iex/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ def _output_error(self, out):
7171
"""
7272
try:
7373
content = json.loads(out.text)
74-
except Exception:
75-
raise TypeError("Failed to interpret response as JSON.")
74+
except Exception as exc:
75+
raise TypeError("Failed to interpret response as JSON.") from exc
7676

7777
for key, string in content.items():
7878
e = "IEX Output error encountered: {}".format(string)

pandas_datareader/iex/stats.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ def __init__(
2323
import warnings
2424

2525
warnings.warn(
26-
"Daily statistics is not working due to issues with the " "IEX API",
26+
"Daily statistics is not working due to issues with the IEX API",
2727
UnstableAPIWarning,
28+
stacklevel=2,
2829
)
2930
self.curr_date = start
3031
super(DailySummaryReader, self).__init__(

pandas_datareader/io/jsdmx.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ def read_jsdmx(path_or_buf):
3131

3232
try:
3333
import simplejson as json
34-
except ImportError:
34+
except ImportError as exc:
3535
if sys.version_info[:2] < (2, 7):
36-
raise ImportError("simplejson is required in python 2.6")
36+
raise ImportError("simplejson is required in python 2.6") from exc
3737
import json
3838

3939
if isinstance(jdata, dict):

pandas_datareader/io/sdmx.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ def read_sdmx(path_or_buf, dtype="float64", dsd=None):
5353

5454
try:
5555
structure = _get_child(root, _MESSAGE + "Structure")
56-
except ValueError:
56+
except ValueError as exc:
5757
# get zipped path
5858
result = list(root.iter(_COMMON + "Text"))[1].text
5959
if not result.startswith("http"):
60-
raise ValueError(result)
60+
raise ValueError(result) from exc
6161

6262
for _ in range(60):
6363
# wait zipped data is prepared
@@ -72,7 +72,7 @@ def read_sdmx(path_or_buf, dtype="float64", dsd=None):
7272
"Unable to download zipped data within 60 secs, "
7373
"please download it manually from: {0}"
7474
)
75-
raise ValueError(msg.format(result))
75+
raise ValueError(msg.format(result)) from exc
7676

7777
idx_name = structure.get("dimensionAtObservation")
7878
dataset = _get_child(root, _DATASET)

pandas_datareader/nasdaq_trader.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,17 @@ def _download_nasdaq_symbols(timeout):
4141
ftp_session = FTP(_NASDAQ_FTP_SERVER, timeout=timeout)
4242
ftp_session.login()
4343
except all_errors as err:
44-
raise RemoteDataError("Error connecting to %r: %s" % (_NASDAQ_FTP_SERVER, err))
44+
raise RemoteDataError(
45+
"Error connecting to %r: %s" % (_NASDAQ_FTP_SERVER, err)
46+
) from err
4547

4648
lines = []
4749
try:
4850
ftp_session.retrlines("RETR " + _NASDAQ_TICKER_LOC, lines.append)
4951
except all_errors as err:
5052
raise RemoteDataError(
5153
"Error downloading from %r: %s" % (_NASDAQ_FTP_SERVER, err)
52-
)
54+
) from err
5355
finally:
5456
ftp_session.close()
5557

0 commit comments

Comments
 (0)