Skip to content

Commit b04e1cc

Browse files
author
Winter Deng
committed
reformat all codes
1 parent ff9003b commit b04e1cc

File tree

6 files changed

+77
-67
lines changed

6 files changed

+77
-67
lines changed

docs/cli/classifier.py

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,37 @@
1111

1212
import subprocess
1313

14+
1415
def load_exclude_authors(file_path):
1516
path = Path(file_path)
1617
if not path.exists():
1718
return []
1819
with open(path, "r", encoding="utf-8") as f:
1920
return [line.strip() for line in f if line.strip()]
2021

22+
2123
def get_last_commit_excluding(exclude_file):
2224
exclude_authors = set(load_exclude_authors(exclude_file))
23-
24-
logs = subprocess.check_output([
25-
"git", "log",
26-
"--pretty=format:%H|%ae", # commit hash | author email
27-
]).decode("utf-8").splitlines()
28-
25+
26+
logs = (
27+
subprocess.check_output(
28+
[
29+
"git",
30+
"log",
31+
"--pretty=format:%H|%ae", # commit hash | author email
32+
]
33+
)
34+
.decode("utf-8")
35+
.splitlines()
36+
)
37+
2938
for line in logs:
3039
commit, email = line.split("|", 1)
3140
if email not in exclude_authors:
3241
return commit
3342
return None
3443

44+
3545
def classify_file_category(path):
3646

3747
relative_path = Path(path).relative_to(lib_path)
@@ -52,12 +62,12 @@ def fetch_option_flags(flags):
5262

5363
for flag in flags:
5464
flag_list.append(
55-
{
56-
"name": flag["name"].replace("\\", ""),
57-
"instruction": flag["name"].split("-")[-1],
58-
"description": flag["description"]
59-
}
60-
)
65+
{
66+
"name": flag["name"].replace("\\", ""),
67+
"instruction": flag["name"].split("-")[-1],
68+
"description": flag["description"],
69+
}
70+
)
6171

6272
return flag_list
6373

@@ -66,15 +76,15 @@ def fetch_all_files():
6676
main_files = [
6777
os.path.join(lib_path, "main.py"),
6878
os.path.join(lib_path, "linear_trainer.py"),
69-
os.path.join(lib_path, "torch_trainer.py")
79+
os.path.join(lib_path, "torch_trainer.py"),
7080
]
7181
lib_files = glob.glob(os.path.join(lib_path, "libmultilabel/**/*.py"), recursive=True)
7282
file_set = set(map(os.path.abspath, main_files + lib_files))
7383
return file_set
7484

7585

7686
def find_config_usages_in_file(file_path, allowed_keys):
77-
pattern = re.compile(r'\bconfig\.([a-zA-Z_][a-zA-Z0-9_]*)')
87+
pattern = re.compile(r"\bconfig\.([a-zA-Z_][a-zA-Z0-9_]*)")
7888
detailed_results = {}
7989
try:
8090
with open(file_path, "r", encoding="utf-8") as f:
@@ -114,7 +124,7 @@ def move_duplicates_together(data, keep):
114124
duplicates = set()
115125

116126
for i, key1 in enumerate(all_keys):
117-
for key2 in all_keys[i+1:]:
127+
for key2 in all_keys[i + 1 :]:
118128
duplicates |= data[key1] & data[key2]
119129

120130
data[keep] |= duplicates
@@ -136,7 +146,7 @@ def classify(raw_flags):
136146
collected = {}
137147

138148
for file_path in file_set:
139-
detailed_results = find_config_usages_in_file(file_path, allowed_keys)
149+
detailed_results = find_config_usages_in_file(file_path, allowed_keys)
140150
if detailed_results:
141151
usage_map[file_path] = set(detailed_results.keys())
142152
for k, v in detailed_results.items():
@@ -163,7 +173,9 @@ def classify(raw_flags):
163173
if flag["category"] not in result:
164174
result[flag["category"]] = []
165175

166-
result[flag["category"]].append({"name": flag["name"].replace("--", r"\-\-"), "description": flag["description"]})
176+
result[flag["category"]].append(
177+
{"name": flag["name"].replace("--", r"\-\-"), "description": flag["description"]}
178+
)
167179

168180
result["details"] = []
169181
for k, v in collected.items():
@@ -172,4 +184,4 @@ def classify(raw_flags):
172184
for i in v[1:]:
173185
result["details"].append({"name": "", "file": i["file"], "location": ", ".join(i["lines"])})
174186

175-
return result
187+
return result

docs/cli/genflags.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import main
77
from classifier import classify
88

9+
910
class FakeParser(dict):
1011
def __init__(self):
1112
self.flags = []
@@ -32,9 +33,11 @@ def add_argument(
3233

3334
classified = classify(parser.flags)
3435

36+
3537
def width_title(key, title):
3638
return max(map(lambda f: len(f[key]), classified[title]))
3739

40+
3841
def print_table(title, flags, intro):
3942
print()
4043
print(intro)
@@ -51,21 +54,22 @@ def print_table(title, flags, intro):
5154
print("=" * wn, "=" * wd)
5255
print()
5356

57+
5458
print_table(
5559
"general",
5660
classified["general"],
5761
intro="**General options**:\n\
58-
Common configurations shared across both linear and neural network trainers."
62+
Common configurations shared across both linear and neural network trainers.",
5963
)
6064
print_table(
6165
"linear",
6266
classified["linear"],
6367
intro="**Linear options**:\n\
64-
Configurations specific to linear trainer."
68+
Configurations specific to linear trainer.",
6569
)
6670
print_table(
6771
"nn",
6872
classified["nn"],
6973
intro="**Neural network options**:\n\
70-
Configurations specific to torch (neural networks) trainer."
74+
Configurations specific to torch (neural networks) trainer.",
7175
)

docs/examples/plot_linear_feature_gen.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,7 @@
1313
from libmultilabel import linear
1414

1515
datasets = linear.load_dataset("txt", "data/rcv1/train.txt", "data/rcv1/test.txt")
16-
tfidf_params = {
17-
"max_features": 20000,
18-
"min_df": 3,
19-
"ngram_range": (1, 3)
20-
}
16+
tfidf_params = {"max_features": 20000, "min_df": 3, "ngram_range": (1, 3)}
2117
preprocessor = linear.Preprocessor(tfidf_params=tfidf_params)
2218
preprocessor.fit(datasets)
2319
datasets = preprocessor.transform(datasets)
@@ -30,4 +26,4 @@
3026
#
3127
# Finally, we use the generated numerical features to train and evaluate the model.
3228
# The rest of the steps is the same in the quickstarts.
33-
# Please refer to them for details.
29+
# Please refer to them for details.

docs/examples/plot_linear_gridsearch_tutorial.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,13 @@
6161
######################################################################
6262
# The best parameters are::
6363
#
64-
# clf__options: -s 2 -c 0.5 -m 1
65-
# tfidf__max_features: 10000
64+
# clf__options: -s 2 -c 0.5 -m 1
65+
# tfidf__max_features: 10000
6666
# tfidf__min_df: 5
6767
#
6868
# Note that in the above code, the ``refit`` argument of ``GridSearchCV`` is enabled by default, meaning that the best configuration will be trained on the whole dataset after hyperparameter search.
6969
# We refer to this as the retrain strategy.
70-
# After fitting ``GridSearchCV``, the retrained model is stored in ``clf``.
70+
# After fitting ``GridSearchCV``, the retrained model is stored in ``clf``.
7171
#
7272
# We can apply the ``predict`` function of ``GridSearchCV`` object to use the estimator trained under the best hyperparameters for prediction.
7373
# Then use ``linear.compute_metrics`` to calculate the test performance.

docs/examples/plot_linear_tree_tutorial.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,7 @@ def metrics_in_batches(model):
129129
# We have already trained a single tree model as a baseline.
130130
# Now, let's train an ensemble of 3 tree models.
131131
training_start = time.time()
132-
ensemble_model = linear.train_ensemble_tree(
133-
datasets["train"]["y"], datasets["train"]["x"], n_trees=3
134-
)
132+
ensemble_model = linear.train_ensemble_tree(datasets["train"]["y"], datasets["train"]["x"], n_trees=3)
135133
training_end = time.time()
136134
print("Training time of ensemble tree: {:10.2f}".format(training_end - training_start))
137135

@@ -179,4 +177,3 @@ def metrics_in_batches(model):
179177
# | +-----------------+-------+-------+-------+
180178
# | | Ensemble-15 | 91.25 | 81.31 | 68.34 |
181179
# +---------------+-----------------+-------+-------+-------+
182-

0 commit comments

Comments
 (0)