Skip to content

Commit

Permalink
MAINT: Restore flake8
Browse files Browse the repository at this point in the history
Restore flake8 tests to improve code quality
  • Loading branch information
bashtage committed Sep 17, 2019
1 parent aaaa4ed commit 6572ed4
Show file tree
Hide file tree
Showing 12 changed files with 49 additions and 14 deletions.
1 change: 1 addition & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
- [ ] closes #xxxx
- [ ] tests added / passed
- [ ] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [ ] passes `black --check pandas_datareader`
- [ ] added entry to docs/source/whatsnew/vLATEST.txt
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ script:
- if [[ -n "${TEST_TYPE+x}" ]]; then export MARKERS="-m ${TEST_TYPE}"; fi
- pytest -v -s -r xX "${MARKERS}" --cov-config .coveragerc --cov=pandas_datareader --cov-report xml:/tmp/cov-datareader.xml --junitxml=/tmp/datareader.xml
- |
if [[ "$TRAVIS_PYTHON_VERSION" -gt 3.5 ]]; then
if (( $(echo "$TRAVIS_PYTHON_VERSION > 3.5" | bc -l) )); then
black --check pandas_datareader
fi
- flake8 --version
- flake8 pandas_datareader

after_script:
- |
Expand Down
6 changes: 3 additions & 3 deletions ci/pypi-install.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/env bash

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

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

if [[ "$PANDAS" == "MASTER" ]]; then
Expand Down
4 changes: 2 additions & 2 deletions pandas_datareader/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def versions_from_parentdir(parentdir_prefix, root, verbose):
"""
rootdirs = []

for i in range(3):
for _ in range(3):
dirname = os.path.basename(root)
if dirname.startswith(parentdir_prefix):
return {
Expand Down Expand Up @@ -524,7 +524,7 @@ def get_versions():
# versionfile_source is the relative path from the top of the source
# tree (where the .git directory might live) to this file. Invert
# this to find the root from __file__.
for i in cfg.versionfile_source.split("/"):
for _ in cfg.versionfile_source.split("/"):
root = os.path.dirname(root)
except NameError:
return {
Expand Down
2 changes: 1 addition & 1 deletion pandas_datareader/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def _get_response(self, url, params=None, headers=None):
# initial attempt + retry
pause = self.pause
last_response_text = ""
for i in range(self.retry_count + 1):
for _ in range(self.retry_count + 1):
response = self.session.get(url, params=params, headers=headers)
if response.status_code == requests.codes.ok:
return response
Expand Down
20 changes: 19 additions & 1 deletion pandas_datareader/compat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,24 @@
PANDAS_0230 = PANDAS_VERSION >= LooseVersion("0.23.0")


__all__ = [
"HTTPError",
"StringIO",
"PANDAS_0210",
"PANDAS_0220",
"PANDAS_0230",
"get_filepath_or_buffer",
"str_to_bytes",
"string_types",
"assert_frame_equal",
"is_list_like",
"is_number",
"lmap",
"lrange",
"concat",
]


def get_filepath_or_buffer(filepath_or_buffer, encoding=None, compression=None):

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

reduce = reduce
binary_type = str
string_types = (basestring,)
string_types = (basestring,) # noqa: F821

def bytes_to_str(b, encoding=None):
return b
Expand Down
2 changes: 2 additions & 0 deletions pandas_datareader/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
Module contains tools for collecting data from various remote sources
"""

# flake8: noqa

import warnings

from pandas_datareader.av.forex import AVForexReader
Expand Down
2 changes: 1 addition & 1 deletion pandas_datareader/moex.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def read(self):
urls = self.url # generate urls per symbols
dfs = [] # an array of pandas dataframes per symbol to concatenate

for i, symbol in enumerate(self.symbols):
for i in range(len(self.symbols)):
out_list = []
date_column = None

Expand Down
3 changes: 2 additions & 1 deletion pandas_datareader/tests/io/test_jsdmx.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ def test_land_use(dirpath):

@pytest.mark.skipif(not PANDAS_0210, reason="Broken on old pandas")
def test_quartervalue(dirpath):
# 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
# 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
result = read_jsdmx(os.path.join(dirpath, "jsdmx", "oecd1.json"))
assert isinstance(result, pd.DataFrame)
expected = pd.DatetimeIndex(
Expand Down
1 change: 1 addition & 0 deletions pandas_datareader/tests/yahoo/test_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def data1(aapl, json1):


class TestYahooOptions(object):
@classmethod
def setup_class(cls):
pytest.skip("Skip all Yahoo! tests.")

Expand Down
12 changes: 8 additions & 4 deletions pandas_datareader/yahoo/daily.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ def __init__(
"Expires": str(-1),
"Upgrade-Insecure-Requests": str(1),
# Google Chrome:
"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
"User-Agent": (
"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 "
"(KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36"
),
}

self.adjust_price = adjust_price
Expand All @@ -95,9 +98,10 @@ def __init__(

if self.interval not in ["d", "wk", "mo", "m", "w"]:
raise ValueError(
"Invalid interval: valid values are 'd', 'wk' and 'mo'. 'm' and 'w' have been implemented for " # noqa
"backward compatibility. 'v' has been moved to the yahoo-actions or yahoo-dividends APIs."
) # noqa
"Invalid interval: valid values are 'd', 'wk' and 'mo'. 'm' and 'w' "
"have been implemented for backward compatibility. 'v' has been moved "
"to the yahoo-actions or yahoo-dividends APIs."
)
elif self.interval in ["m", "mo"]:
self.pdinterval = "m"
self.interval = "mo"
Expand Down
6 changes: 6 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,9 @@ markers =
requires_api_key: mark a test as requiring an API key
alpha_vantage: mark a test of the AlphaVantage reader
quandl: mark a test of the Quandl readaer

[flake8]
ignore = E203, E266, E501, W503
max-line-length = 80
max-complexity = 18
select = B,C,E,F,W,T4,B9

0 comments on commit 6572ed4

Please sign in to comment.