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

refactor: python lint (new black version) #4480

Merged
merged 2 commits into from Feb 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion demo/cats/code_submission/sanitize.py
Expand Up @@ -4,7 +4,6 @@


class Sanitize:

S_CODE = 0
S_COMMENT = 1
SANITIZE_WORDS = [
Expand Down
3 changes: 1 addition & 2 deletions demo/cats/utility/acp_regression_data_join.py
Expand Up @@ -4,11 +4,10 @@

class PredictDataJoiner_acp:
def join(self, data_file_name, predict_file_name):

data_file = open(data_file_name, "r")
predict_file = open(predict_file_name, "r")

for (data_line, predict_line) in zip(data_file, predict_file):
for data_line, predict_line in zip(data_file, predict_file):
data_line = self.strip_label(data_line)
print("ca", predict_line.strip(), "|", data_line.strip())

Expand Down
3 changes: 1 addition & 2 deletions demo/cats/utility/ap_regression_data_join.py
Expand Up @@ -21,7 +21,6 @@ def __init__(
self.loss_type_return = loss_type_return

def join(self):

data_file = open(self.data_file_name, "r")
predict_file = open(self.predict_file_name, "r")

Expand All @@ -35,7 +34,7 @@ def join(self):
sqr_loss_max = float("-inf")
max_found = float("-inf")
min_found = float("inf")
for (data_line, predict_line) in zip(data_file, predict_file):
for data_line, predict_line in zip(data_file, predict_file):
# Get data
act = self.get_action(predict_line)
reg = self.get_regression_val(data_line)
Expand Down
1 change: 0 additions & 1 deletion demo/cats/utility/get_offline_results.py
Expand Up @@ -47,7 +47,6 @@ def __init__(self, srm_file_name, test_file_name, delta, alpha, quiet):
self.pmin = 0.05 # epsilon = 5%

def eval(self):

data_file = open(self.srm_file_name, "r")
line = data_file.readline()

Expand Down
1 change: 0 additions & 1 deletion demo/cats/utility/get_online_results.py
Expand Up @@ -40,7 +40,6 @@ def __init__(self, file_name, alpha, quiet):
self.quiet = quiet

def eval(self):

data_file = open(self.file_name, "r")
line = data_file.readline()

Expand Down
3 changes: 1 addition & 2 deletions demo/cats/utility/srm.py
Expand Up @@ -12,14 +12,13 @@ def __init__(self, data_file_name, predict_file_name, min_val, max_val, k, h):
self.hh = h * (max_val - min_val) / k

def calc(self):

data_file = open(self.data_file_name, "r")
predict_file = open(self.predict_file_name, "r")

N = 0
_loss_acc = 0.0

for (data_line, predict_line) in zip(data_file, predict_file):
for data_line, predict_line in zip(data_file, predict_file):
# Get data
pred = self.get_predict_action(predict_line)
logd, L_s, P_s = self.get_logged_data(data_line)
Expand Down
3 changes: 1 addition & 2 deletions demo/recall_tree/wikipara/WikiExtractor.py
Expand Up @@ -2163,7 +2163,6 @@ def compact(text):
listLevel = "" # nesting of lists

for line in text.split("\n"):

if not line:
continue
# Handle section titles
Expand Down Expand Up @@ -2235,7 +2234,7 @@ def compact(text):
if not Extractor.keepSections:
items = headers.items()
items.sort()
for (i, v) in items:
for i, v in items:
page.append(v)
headers.clear()
page.append(line) # first line
Expand Down
1 change: 0 additions & 1 deletion python/docs/source/conf.py
Expand Up @@ -149,7 +149,6 @@ def add_binder_url_for_page(
context,
doctree,
):

# First decide if we'll insert any links
path = app.env.doc2path(pagename)
extension = Path(path).suffix
Expand Down
2 changes: 0 additions & 2 deletions python/docs/source/tutorials/python_cats.ipynb
Expand Up @@ -229,7 +229,6 @@
" max_value,\n",
" do_learn=True,\n",
"):\n",
"\n",
" reward_rate = []\n",
" hits = 0\n",
" cost_sum = 0.0\n",
Expand Down Expand Up @@ -616,7 +615,6 @@
" max_value,\n",
" do_learn=True,\n",
"):\n",
"\n",
" reward_rate = []\n",
" hits = 0\n",
" cost_sum = 0.0\n",
Expand Down
1 change: 1 addition & 0 deletions python/tests/test_ccb.py
@@ -1,5 +1,6 @@
import vowpalwabbit


# Named specifically as the delimiter used is specific for the number of actions
# used in this test case.
def count_weights_from_readable_model_file_for_equiv_test(file_name):
Expand Down
6 changes: 3 additions & 3 deletions python/tests/test_distributionally_robust.py
Expand Up @@ -26,7 +26,7 @@ def test_recompute_duals_lower():

np.testing.assert_almost_equal(list(zip(ws, rs)), ws_rs, 5)

for (w, r) in zip(ws, rs):
for w, r in zip(ws, rs):
ocrl.update(1, w, r)
ocrl.recomputeduals()
if ocrl.duals[1][0] is None:
Expand Down Expand Up @@ -105,7 +105,7 @@ def test_recompute_duals_upper():
duals = []
bounds = []

for (w, r) in zip(ws, rs):
for w, r in zip(ws, rs):
ocrl.update(1, w, r)
ocrl.recomputeduals(is_upper=True)
if ocrl.duals[1][0] is None:
Expand Down Expand Up @@ -159,7 +159,7 @@ def test_qlb():

np.testing.assert_almost_equal(list(zip(ws, rs)), ws_rs, 5)

for (w, r) in zip(ws, rs):
for w, r in zip(ws, rs):
ocrl.update(1, w, r)
qlbs.append(ocrl.qlb(w, r))

Expand Down
2 changes: 1 addition & 1 deletion python/tests/test_pyvw.py
Expand Up @@ -9,14 +9,14 @@

BIT_SIZE = 18


# Since these tests still run with Python 2, this is required.
# Otherwise we could use math.isclose
def isclose(a, b, rel_tol=1e-05, abs_tol=0.0):
return abs(a - b) <= max(rel_tol * max(abs(a), abs(b)), abs_tol)


class TestVW:

model = Workspace(quiet=True, b=BIT_SIZE)

def test_constructor(self):
Expand Down
1 change: 0 additions & 1 deletion python/tests/test_sklearn_vw.py
Expand Up @@ -303,7 +303,6 @@ def test_repr(self):


class TestVWMultiClassifier(BaseVWTest):

estimator = VWMultiClassifier

def test_predict_proba(self, data):
Expand Down
2 changes: 1 addition & 1 deletion python/tests/test_vwconfig.py
Expand Up @@ -6,7 +6,7 @@ def helper_options_to_list_strings(config):
cmd_str_list = []

for name, config_group in config.items():
for (group_name, options) in config_group:
for group_name, options in config_group:
for option in options:
temp_str = str(option)
if temp_str:
Expand Down
8 changes: 3 additions & 5 deletions python/vowpalwabbit/dftovw.py
Expand Up @@ -302,7 +302,7 @@ def process(self, df: pd.DataFrame) -> pd.Series:
The MultiLabel string representation.
"""
labels = self.label if isinstance(self.label, list) else [self.label]
for (i, label) in enumerate(labels):
for i, label in enumerate(labels):
label_col = label.get_col(df)
if i == 0:
out = label_col
Expand Down Expand Up @@ -542,7 +542,6 @@ class _ListLabel(object):
sep_by_label = dict(ContextualbanditLabel=" ", MultiLabel=",")

def __init__(self, label_list: List[Union[ContextualbanditLabel, MultiLabel]]):

instance_classes = set(
[type(label_instance).__name__ for label_instance in label_list]
)
Expand Down Expand Up @@ -605,7 +604,7 @@ def process(self, df: pd.DataFrame) -> pd.Series:
Returns:
The _ListLabel string representation.
"""
for (i, label) in enumerate(self):
for i, label in enumerate(self):
if i == 0:
out = label.process(df)
else:
Expand Down Expand Up @@ -988,7 +987,6 @@ def check_instance_columns(self, instance):
class_name = type(instance).__name__

for attribute_name, attribute_value in vars(instance).items():

if not isinstance(attribute_value, list):
attribute_value = [attribute_value]

Expand Down Expand Up @@ -1032,7 +1030,7 @@ def convert_df(self) -> List[str]:
if not all([x is None for x in [self.label, self.tag]]):
self.out += self.process_label_and_tag()

for (i, namespace) in enumerate(self.namespaces):
for i, namespace in enumerate(self.namespaces):
to_add = namespace.process() + self.process_features(namespace.features)
self.out += (to_add + " ") if (i < len(self.namespaces) - 1) else to_add

Expand Down
1 change: 0 additions & 1 deletion python/vowpalwabbit/pyvw.py
Expand Up @@ -1931,7 +1931,6 @@ def get_prediction(
Tuple[int, List[int]],
None,
]:

"""Get prediction object from this example.

Args:
Expand Down
1 change: 0 additions & 1 deletion setup.py
Expand Up @@ -63,7 +63,6 @@ def run(self):
_build_ext.run(self)

def build_cmake(self, ext):

# Make build directory
distutils.dir_util.mkpath(self.build_temp)

Expand Down
1 change: 0 additions & 1 deletion test/run_tests.py
Expand Up @@ -385,7 +385,6 @@ def run_command_line_test(
valgrind=False,
timeout=100,
) -> TestOutcome:

if test.skip:
completed_tests.report_completion(test.id, False)
return TestOutcome(test.id, Result.SKIPPED, {}, skip_reason=test.skip_reason)
Expand Down
8 changes: 4 additions & 4 deletions test/runtest_coverage.py
Expand Up @@ -21,7 +21,7 @@ def get_all_options():
def to_json():
config = get_all_options()
for name, config_group in config.items():
for (group_name, options) in config_group:
for group_name, options in config_group:
for option in options:
option._type = str(type(option._default_value).__name__)

Expand All @@ -40,7 +40,7 @@ def get_config_of_vw_cmd(test):


def update_option(config, name, group_name, option_name):
for (g_n, options) in config[name]:
for g_n, options in config[name]:
if g_n == group_name:
for option in options:
if option.name == option_name:
Expand All @@ -51,7 +51,7 @@ def update_option(config, name, group_name, option_name):

def merge_config(tracker, b):
for name, config_group in b.items():
for (group_name, options) in config_group:
for group_name, options in config_group:
for option in options:
if option.value_supplied:
tracker = update_option(tracker, name, group_name, option.name)
Expand All @@ -64,7 +64,7 @@ def print_non_supplied(config):
without_default = []

for name, config_group in config.items():
for (group_name, options) in config_group:
for group_name, options in config_group:
for option in options:
if not option.value_supplied:
default_val_str = ""
Expand Down
2 changes: 1 addition & 1 deletion test/tools/fuzzing/fuzz.py
Expand Up @@ -11,6 +11,7 @@

# Python 3.8+ required


# The code used to find the test binaries are taken from run_tests.py. If any changes occur
# in one, make sure to update the other
def find_in_path(paths, file_matcher, debug_file_name):
Expand Down Expand Up @@ -71,7 +72,6 @@ def is_test_binary(file_path):


def main():

parser = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter
)
Expand Down
1 change: 0 additions & 1 deletion utl/active_interactor.py
Expand Up @@ -63,7 +63,6 @@ def _getch():
# The MacOS Carbon API was removed in 10.15, however the
# standard unix approach should work and so should be tried first.
def _get_getch_impl_macos() -> Optional[Callable[[], str]]:

try:
# try OS/X API
import Carbon # type: ignore
Expand Down
1 change: 0 additions & 1 deletion utl/vw-hyperopt.py
Expand Up @@ -318,7 +318,6 @@ def _configure_logger(self):
return logger

def get_hyperparam_string(self, **kwargs):

# print 'KWARGS: ', kwargs
flags = [key for key in kwargs if key.startswith("-")]
for flag in flags:
Expand Down