Skip to content

Commit 6572ed4

Browse files
committedSep 17, 2019
MAINT: Restore flake8
Restore flake8 tests to improve code quality
1 parent aaaa4ed commit 6572ed4

File tree

12 files changed

+49
-14
lines changed

12 files changed

+49
-14
lines changed
 

‎.github/PULL_REQUEST_TEMPLATE.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
- [ ] closes #xxxx
22
- [ ] tests added / passed
3+
- [ ] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
34
- [ ] passes `black --check pandas_datareader`
45
- [ ] added entry to docs/source/whatsnew/vLATEST.txt

‎.travis.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,11 @@ script:
4848
- if [[ -n "${TEST_TYPE+x}" ]]; then export MARKERS="-m ${TEST_TYPE}"; fi
4949
- pytest -v -s -r xX "${MARKERS}" --cov-config .coveragerc --cov=pandas_datareader --cov-report xml:/tmp/cov-datareader.xml --junitxml=/tmp/datareader.xml
5050
- |
51-
if [[ "$TRAVIS_PYTHON_VERSION" -gt 3.5 ]]; then
51+
if (( $(echo "$TRAVIS_PYTHON_VERSION > 3.5" | bc -l) )); then
5252
black --check pandas_datareader
5353
fi
54+
- flake8 --version
55+
- flake8 pandas_datareader
5456

5557
after_script:
5658
- |

‎ci/pypi-install.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#!/usr/bin/env bash
22

33
pip install pip --upgrade
4-
pip install numpy=="$NUMPY" pytz python-dateutil coverage setuptools html5lib lxml pytest pytest-cov wrapt codecov coveralls beautifulsoup4 isort
4+
pip install numpy=="$NUMPY" pytz python-dateutil coverage setuptools html5lib lxml pytest pytest-cov wrapt codecov coveralls beautifulsoup4 isort flake8
55

6-
if [[ "$TRAVIS_PYTHON_VERSION" != 2.7 ]]; then
7-
pip install black
6+
if (( $(echo "$TRAVIS_PYTHON_VERSION > 3.5" | bc -l) )); then
7+
pip install black flake8-bugbear
88
fi
99

1010
if [[ "$PANDAS" == "MASTER" ]]; then

‎pandas_datareader/_version.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def versions_from_parentdir(parentdir_prefix, root, verbose):
116116
"""
117117
rootdirs = []
118118

119-
for i in range(3):
119+
for _ in range(3):
120120
dirname = os.path.basename(root)
121121
if dirname.startswith(parentdir_prefix):
122122
return {
@@ -524,7 +524,7 @@ def get_versions():
524524
# versionfile_source is the relative path from the top of the source
525525
# tree (where the .git directory might live) to this file. Invert
526526
# this to find the root from __file__.
527-
for i in cfg.versionfile_source.split("/"):
527+
for _ in cfg.versionfile_source.split("/"):
528528
root = os.path.dirname(root)
529529
except NameError:
530530
return {

‎pandas_datareader/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def _get_response(self, url, params=None, headers=None):
144144
# initial attempt + retry
145145
pause = self.pause
146146
last_response_text = ""
147-
for i in range(self.retry_count + 1):
147+
for _ in range(self.retry_count + 1):
148148
response = self.session.get(url, params=params, headers=headers)
149149
if response.status_code == requests.codes.ok:
150150
return response

‎pandas_datareader/compat/__init__.py

+19-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,24 @@
1515
PANDAS_0230 = PANDAS_VERSION >= LooseVersion("0.23.0")
1616

1717

18+
__all__ = [
19+
"HTTPError",
20+
"StringIO",
21+
"PANDAS_0210",
22+
"PANDAS_0220",
23+
"PANDAS_0230",
24+
"get_filepath_or_buffer",
25+
"str_to_bytes",
26+
"string_types",
27+
"assert_frame_equal",
28+
"is_list_like",
29+
"is_number",
30+
"lmap",
31+
"lrange",
32+
"concat",
33+
]
34+
35+
1836
def get_filepath_or_buffer(filepath_or_buffer, encoding=None, compression=None):
1937

2038
# Dictionaries are no longer considered valid inputs
@@ -48,7 +66,7 @@ def bytes_to_str(b, encoding=None):
4866

4967
reduce = reduce
5068
binary_type = str
51-
string_types = (basestring,)
69+
string_types = (basestring,) # noqa: F821
5270

5371
def bytes_to_str(b, encoding=None):
5472
return b

‎pandas_datareader/data.py

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
Module contains tools for collecting data from various remote sources
33
"""
44

5+
# flake8: noqa
6+
57
import warnings
68

79
from pandas_datareader.av.forex import AVForexReader

‎pandas_datareader/moex.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def read(self):
138138
urls = self.url # generate urls per symbols
139139
dfs = [] # an array of pandas dataframes per symbol to concatenate
140140

141-
for i, symbol in enumerate(self.symbols):
141+
for i in range(len(self.symbols)):
142142
out_list = []
143143
date_column = None
144144

‎pandas_datareader/tests/io/test_jsdmx.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ def test_land_use(dirpath):
150150

151151
@pytest.mark.skipif(not PANDAS_0210, reason="Broken on old pandas")
152152
def test_quartervalue(dirpath):
153-
# https://stats.oecd.org/sdmx-json/data/QNA/AUS+AUT+BEL+CAN+CHL.GDP+B1_GE.CUR+VOBARSA.Q/all?startTime=2009-Q1&endTime=2011-Q4
153+
# https://stats.oecd.org/sdmx-json/data/QNA/AUS+AUT+BEL+CAN+CHL.GDP+B1_
154+
# GE.CUR+VOBARSA.Q/all?startTime=2009-Q1&endTime=2011-Q4
154155
result = read_jsdmx(os.path.join(dirpath, "jsdmx", "oecd1.json"))
155156
assert isinstance(result, pd.DataFrame)
156157
expected = pd.DatetimeIndex(

‎pandas_datareader/tests/yahoo/test_options.py

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ def data1(aapl, json1):
6969

7070

7171
class TestYahooOptions(object):
72+
@classmethod
7273
def setup_class(cls):
7374
pytest.skip("Skip all Yahoo! tests.")
7475

‎pandas_datareader/yahoo/daily.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,10 @@ def __init__(
8585
"Expires": str(-1),
8686
"Upgrade-Insecure-Requests": str(1),
8787
# Google Chrome:
88-
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36", # noqa
88+
"User-Agent": (
89+
"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 "
90+
"(KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36"
91+
),
8992
}
9093

9194
self.adjust_price = adjust_price
@@ -95,9 +98,10 @@ def __init__(
9598

9699
if self.interval not in ["d", "wk", "mo", "m", "w"]:
97100
raise ValueError(
98-
"Invalid interval: valid values are 'd', 'wk' and 'mo'. 'm' and 'w' have been implemented for " # noqa
99-
"backward compatibility. 'v' has been moved to the yahoo-actions or yahoo-dividends APIs."
100-
) # noqa
101+
"Invalid interval: valid values are 'd', 'wk' and 'mo'. 'm' and 'w' "
102+
"have been implemented for backward compatibility. 'v' has been moved "
103+
"to the yahoo-actions or yahoo-dividends APIs."
104+
)
101105
elif self.interval in ["m", "mo"]:
102106
self.pdinterval = "m"
103107
self.interval = "mo"

‎setup.cfg

+6
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,9 @@ markers =
3131
requires_api_key: mark a test as requiring an API key
3232
alpha_vantage: mark a test of the AlphaVantage reader
3333
quandl: mark a test of the Quandl readaer
34+
35+
[flake8]
36+
ignore = E203, E266, E501, W503
37+
max-line-length = 80
38+
max-complexity = 18
39+
select = B,C,E,F,W,T4,B9

0 commit comments

Comments
 (0)
Please sign in to comment.