Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix PEP-8 violations reported by flake8 on asv folder #988

Merged
merged 33 commits into from
Feb 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
c354c2a
remove library and variable not used.
LucyJimenez Jan 24, 2022
02f051f
Revert "remove library and variable not used."
LucyJimenez Jan 24, 2022
58bef46
fix issues pep8 related
LucyJimenez Jan 25, 2022
d5fc73e
fix issues pep8 related
LucyJimenez Jan 26, 2022
2bb6f61
fix pep8 issues
LucyJimenez Jan 27, 2022
e4971f7
fix pep8 issues
LucyJimenez Jan 27, 2022
057ad1f
fix pep8 issues
LucyJimenez Jan 27, 2022
7ee40dc
fix pep8 issues
LucyJimenez Jan 27, 2022
0aab939
remove libraries imported but unused
LucyJimenez Jan 27, 2022
5a4b19d
Merge branch 'master' into flake8_issue6
LucyJimenez Jan 31, 2022
dcfe6b6
Merge branch 'flake8_issue5' into flake8_issue6
LucyJimenez Jan 31, 2022
8ca7dd0
Merge branch 'airspeed-velocity:master' into flake8_issue6
LucyJimenez Jan 31, 2022
18f3166
Merge branch 'airspeed-velocity:master' into flake8_issue5
LucyJimenez Jan 31, 2022
05b0045
Merge branch 'airspeed-velocity:master' into check_flake8
LucyJimenez Jan 31, 2022
6cb5640
Merge branch 'airspeed-velocity:master' into flake8_issue2
LucyJimenez Jan 31, 2022
c152b57
Merge branch 'airspeed-velocity:master' into flake8_issue3
LucyJimenez Jan 31, 2022
e5680c7
Merge branch 'airspeed-velocity:master' into flake8_issue4
LucyJimenez Jan 31, 2022
32372c6
Merge branch 'flake8_issue2' into check_flake8
LucyJimenez Jan 31, 2022
bccabad
Merge branch 'flake8_issue3' into check_flake8
LucyJimenez Jan 31, 2022
dd713e5
Merge branch 'flake8_issue4' into check_flake8
LucyJimenez Jan 31, 2022
c7fb513
Merge branch 'flake8_issue5' into check_flake8
LucyJimenez Jan 31, 2022
5d72e73
Merge branch 'flake8_issue6' into check_flake8
LucyJimenez Jan 31, 2022
edd129a
update ci config and fix pep8 issues
LucyJimenez Jan 31, 2022
0c72f25
update ci config
LucyJimenez Jan 31, 2022
c372067
update path on ci file
LucyJimenez Jan 31, 2022
972d51b
fix pep8 issues and include missing files on ci chek for flake8
LucyJimenez Jan 31, 2022
e1a1814
update util.py
LucyJimenez Feb 1, 2022
9a98e89
update step_detect.py
LucyJimenez Feb 1, 2022
8805d6c
reverse changes on step_detect.py and util.py
LucyJimenez Feb 2, 2022
c3d4f6e
update step_detect.py
LucyJimenez Feb 2, 2022
99e02b7
update step_detect.py
LucyJimenez Feb 2, 2022
76afcb9
update util.py
LucyJimenez Feb 2, 2022
3060432
update CI
LucyJimenez Feb 2, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ jobs:

- name: Install dependencies
run: pip install flake8

- name: flake8 all repo only show erros
run: flake8 . || true # preventing CI failing while flake8 issues exist

- name: flake8
run: flake8 . || true # preventing CI failing while flake8 issues exist
- name: flake8 validating correct file(s)
run: flake8 asv/main.py asv/repo.py asv/results.py asv/runner.py asv/statistics.py
2 changes: 0 additions & 2 deletions asv/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
import six

from . import commands
from .config import Config
from .console import log
from .plugin_manager import plugin_manager
from . import util


Expand Down
3 changes: 2 additions & 1 deletion asv/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def get_range_spec(self, commit_a, commit_b):

def get_new_range_spec(self, latest_result, branch=None):
"""
Returns a formatted string giving the results between the
Returns a formatted string giving the results between the
latest result and the newest hash in a given branch.
If no branch given, use the 'master' branch.
"""
Expand Down Expand Up @@ -288,6 +288,7 @@ def get_branch_commits(self, branch):
def get_new_branch_commits(self, branches, existing):
self._raise_error()


def get_repo(conf):
"""
Get a Repo subclass for the given configuration.
Expand Down
7 changes: 3 additions & 4 deletions asv/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import itertools
import hashlib
import datetime
import collections

import six
from six.moves import zip as izip
Expand Down Expand Up @@ -41,7 +40,7 @@ def iter_results_paths(results):
raise util.UserError("malformed {0}".format(machine_json))
except util.UserError as err:
machine_json_err = "Skipping results: {0}".format(six.text_type(err))
except IOError as err:
except IOError:
machine_json_err = "Skipping results: could not load {0}".format(
machine_json)
else:
Expand Down Expand Up @@ -990,7 +989,7 @@ def do_formatting(num_column_params):

for j, values in enumerate(itertools.product(*row_params)):
row_results = [util.human_value(x[0], benchmark['unit'], err=x[1])
for x in result[j*column_items:(j+1)*column_items]]
for x in result[j * column_items:(j + 1) * column_items]]
row = [_format_param_value(value) for value in values] + row_results
rows.append(row)

Expand All @@ -1005,7 +1004,7 @@ def do_formatting(num_column_params):

# Determine how many parameters can be fit to columns
if max_width is None:
max_width = util.get_terminal_width() * 3//4
max_width = util.get_terminal_width() * 3 // 4

text = do_formatting(0)
for j in range(1, len(benchmark['params'])):
Expand Down
9 changes: 4 additions & 5 deletions asv/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import json
import os
import sys
import re
import time
import tempfile
import itertools
Expand All @@ -23,7 +22,6 @@

from .console import log
from .results import Results, format_benchmark_result
from . import statistics
from . import util


Expand Down Expand Up @@ -206,7 +204,7 @@ def iter_run_items():

if run_round > rounds:
if (not append_samples and
run_round == run_rounds[-1] and
run_round == run_rounds[-1] and
name in existing_results):
# We need to remove samples here so that
# append_samples=False has an effect on all
Expand Down Expand Up @@ -314,7 +312,8 @@ def iter_run_items():
# Mark benchmark as failed
partial_info_time = None
log.warning('{0} skipped (setup_cache failed)'.format(name))
stderr = 'asv: setup_cache failed\n\n{}'.format(failed_setup_cache[setup_cache_key])
stderr = 'asv: setup_cache failed\n\n{}'.format(
failed_setup_cache[setup_cache_key])
res = fail_benchmark(benchmark, stderr=stderr)
results.add_result(benchmark, res,
selected_idx=selected_idx,
Expand Down Expand Up @@ -766,7 +765,7 @@ def _stdout_reader(self):
out = self.server_proc.stdout.read()
self.server_proc.stdout.close()
out = out.decode('utf-8', 'replace')
except Exception as exc:
except Exception:
import traceback
out = traceback.format_exc()

Expand Down
72 changes: 36 additions & 36 deletions asv/statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ def compute_stats(samples, number):
# Use the CI from that distribution to extend beyond sample
# bounds
if math.isinf(a):
a = min(c.ppf(0.01/2), min(Y))
a = min(c.ppf(0.01 / 2), min(Y))
if math.isinf(b):
b = max(c.ppf(1 - 0.01/2), max(Y))
b = max(c.ppf(1 - 0.01 / 2), max(Y))

ci_50 = (a, b)

Expand All @@ -78,7 +78,7 @@ def get_err(result, stats):
about the spread of the measurement results.
"""
a, b = stats['q_25'], stats['q_75']
return (b - a)/2
return (b - a) / 2


def get_weight(stats):
Expand Down Expand Up @@ -236,13 +236,14 @@ def quantile(x, q):
if j == n - 1:
m = y[-1]
else:
m = (1 - z)*y[j] + z*y[j+1]
m = (1 - z) * y[j] + z * y[j + 1]

return m


_mann_whitney_u_memo = {}


def mann_whitney_u(x, y, method='auto'):
"""
Mann-Whitney U test
Expand Down Expand Up @@ -287,11 +288,11 @@ def mann_whitney_u(x, y, method='auto'):
u, ties = mann_whitney_u_u(x, y)

# Conservative tie breaking
if u <= m*n//2 and u + ties >= m*n//2:
ties = m*n//2 - u
if u <= m * n // 2 and u + ties >= m * n // 2:
ties = m * n // 2 - u

ux1 = min(u, m*n - u)
ux2 = min(u + ties, m*n - (u + ties))
ux1 = min(u, m * n - u)
ux2 = min(u + ties, m * n - (u + ties))

if ux1 >= ux2:
ux = ux1
Expand All @@ -302,12 +303,12 @@ def mann_whitney_u(x, y, method='auto'):
# Get p-value
if method == 'exact':
p1 = mann_whitney_u_cdf(m, n, ux, memo)
p2 = 1.0 - mann_whitney_u_cdf(m, n, max(m*n//2, m*n - ux - 1), memo)
p2 = 1.0 - mann_whitney_u_cdf(m, n, max(m * n // 2, m * n - ux - 1), memo)
p = p1 + p2
elif method == 'normal':
N = m + n
var = m*n*(N + 1) / 12
z = (ux - m*n/2) / math.sqrt(var)
var = m * n * (N + 1) / 12
z = (ux - m * n / 2) / math.sqrt(var)
cdf = 0.5 * math.erfc(-z / math.sqrt(2))
p = 2 * cdf
else:
Expand All @@ -333,7 +334,7 @@ def mann_whitney_u_cdf(m, n, u, memo=None):
memo = {}
cdf = 0
for uu in range(u + 1):
cdf += mann_whitney_u_pmf(m, n, uu, memo)
cdf += mann_whitney_u_pmf(m, n, uu, memo)
return cdf


Expand Down Expand Up @@ -368,8 +369,8 @@ def mann_whitney_u_r(m, n, u, memo=None):
if value is not None:
return value

value = (mann_whitney_u_r(m, n - 1, u, memo)
+ mann_whitney_u_r(m - 1, n, u - n, memo))
value = (mann_whitney_u_r(m, n - 1, u, memo) +
mann_whitney_u_r(m - 1, n, u - n, memo))

memo[key] = value
return value
Expand All @@ -386,8 +387,8 @@ def binom_pmf(n, k, p):

logp = math.log(p)
log1mp = math.log(1 - p)
return math.exp(lgamma(1 + n) - lgamma(1 + n - k) - lgamma(1 + k)
+ k*logp + (n - k)*log1mp)
return math.exp(lgamma(1 + n) - lgamma(1 + n - k) - lgamma(1 + k) +
k * logp + (n - k) * log1mp)


_BERNOULLI = [1.0, -0.5, 0.166666666667, 0.0, -0.0333333333333, 0.0, 0.0238095238095]
Expand All @@ -403,9 +404,9 @@ def lgamma(x):

if x > 100:
# DLMF 5.11.1
r = 0.5 * math.log(2*math.pi) + (x - 0.5) * math.log(x) - x
for k in range(1, len(_BERNOULLI)//2 + 1):
r += _BERNOULLI[2*k] / (2*k*(2*k - 1) * x**(2*k - 1))
r = 0.5 * math.log(2 * math.pi) + (x - 0.5) * math.log(x) - x
for k in range(1, len(_BERNOULLI) // 2 + 1):
r += _BERNOULLI[2 * k] / (2 * k * (2 * k - 1) * x**(2 * k - 1))
return r

# Fall back to math.factorial
Expand Down Expand Up @@ -496,11 +497,11 @@ def __init__(self, y, nu=None):
# when computing the unnormalized CDF integrals below.
self.mle = quantile(y, 0.5)
self._y_scale = sum(abs(yp - self.mle) for yp in y)
self._y_scale *= self.nu**(1/(self.nu + 1))
self._y_scale *= self.nu**(1 / (self.nu + 1))

# Shift and scale
if self._y_scale != 0:
self.y = [(yp - self.mle)/self._y_scale for yp in y]
self.y = [(yp - self.mle) / self._y_scale for yp in y]
else:
self.y = [0 for yp in y]

Expand Down Expand Up @@ -538,23 +539,23 @@ def _cdf_unnorm(self, beta):

# Do the integral piecewise, resolving the absolute values
for k in range(k_start, k0 + 1):
c = 2*k - len(self.y)
c = 2 * k - len(self.y)
y = sum(self.y[k:]) - sum(self.y[:k])

if k == 0:
a = -inf
else:
a = self.y[k-1]
a = self.y[k - 1]

if k == k0:
b = beta
else:
b = self.y[k]

if c == 0:
term = (b - a) / y**(nu+1)
term = (b - a) / y**(nu + 1)
else:
term = 1/(nu*c) * ((a*c + y)**(-nu) - (b*c + y)**(-nu))
term = 1 / (nu * c) * ((a * c + y)**(-nu) - (b * c + y)**(-nu))

cdf += max(0, term) # avoid rounding error

Expand All @@ -576,27 +577,27 @@ def _ppf_unnorm(self, cdfx):
break

# Invert on interval
c = 2*k - len(self.y)
c = 2 * k - len(self.y)
y = sum(self.y[k:]) - sum(self.y[:k])
nu = self.nu
if k == 0:
term = cdfx
else:
a = self.y[k-1]
term = cdfx - self._cdf_memo[k-1]
a = self.y[k - 1]
term = cdfx - self._cdf_memo[k - 1]

if k == 0:
z = -nu*c*term
z = -nu * c * term
if z > 0:
beta = (z**(-1/nu) - y) / c
beta = (z**(-1 / nu) - y) / c
else:
beta = -inf
elif c == 0:
beta = a + term * y**(nu+1)
beta = a + term * y**(nu + 1)
else:
z = (a*c + y)**(-nu) - nu*c*term
z = (a * c + y)**(-nu) - nu * c * term
if z > 0:
beta = (z**(-1/nu) - y)/c
beta = (z**(-1 / nu) - y) / c
else:
beta = inf

Expand Down Expand Up @@ -625,14 +626,14 @@ def logpdf(self, beta):

ws = sum(abs(yp - beta) for yp in self.y)
m = self.nu
return -(m+1)*math.log(ws) - math.log(self._cdf_norm) - math.log(self._y_scale)
return -(m + 1) * math.log(ws) - math.log(self._cdf_norm) - math.log(self._y_scale)

def cdf(self, beta):
"""
Cumulative probability distribution function
"""
if self._y_scale == 0:
return 1.0*(beta > self.mle)
return 1.0 * (beta > self.mle)

beta = (beta - self.mle) / self._y_scale

Expand All @@ -656,4 +657,3 @@ def ppf(self, cdf):
cdfx = min(cdf * self._cdf_norm, self._cdf_norm)
beta = self._ppf_unnorm(cdfx)
return beta * self._y_scale + self.mle

2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[flake8]
max-line-length = 99
ignore = ""
ignore = W504