Skip to content

Commit d88f885

Browse files
SubhadityaMukherjeepre-commit-ci[bot]PGijsbers
authored
f-string guidelines using Flynt (#1406)
* f strings guidelines * f strings guidelines * Update CONTRIBUTING.md minor readme changes for better readability * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update CONTRIBUTING.md Co-authored-by: Pieter Gijsbers <p.gijsbers@tue.nl> * Update openml/datasets/functions.py Co-authored-by: Pieter Gijsbers <p.gijsbers@tue.nl> * Update openml/setups/functions.py * f string issue in test * Update tests/test_extensions/test_sklearn_extension/test_sklearn_extension.py --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Pieter Gijsbers <p.gijsbers@tue.nl>
1 parent d5d405d commit d88f885

24 files changed

Lines changed: 91 additions & 95 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,4 @@ dmypy.sock
9494

9595
# Tests
9696
.pytest_cache
97+
.venv

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ to create a pull request from your fork.
168168
(If any of the above seems like magic to you, please look up the
169169
[Git documentation](https://git-scm.com/documentation) on the web, or ask a friend or another contributor for help.)
170170
171+
171172
## Pre-commit Details
172173
[Pre-commit](https://pre-commit.com/) is used for various style checking and code formatting.
173174
Before each commit, it will automatically run:

examples/30_extended/fetch_runtimes_tutorial.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def print_compare_runtimes(measures):
119119
)
120120
for repeat, val1 in measures["predictive_accuracy"].items():
121121
for fold, val2 in val1.items():
122-
print("Repeat #{}-Fold #{}: {:.4f}".format(repeat, fold, val2))
122+
print(f"Repeat #{repeat}-Fold #{fold}: {val2:.4f}")
123123
print()
124124

125125
################################################################################
@@ -242,7 +242,7 @@ def print_compare_runtimes(measures):
242242
# the 2-fold (inner) CV search performed.
243243

244244
# We earlier extracted the number of repeats and folds for this task:
245-
print("# repeats: {}\n# folds: {}".format(n_repeats, n_folds))
245+
print(f"# repeats: {n_repeats}\n# folds: {n_folds}")
246246

247247
# To extract the training runtime of the first repeat, first fold:
248248
print(run4.fold_evaluations["wall_clock_time_millis_training"][0][0])

openml/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def _apply_repr_template(
7878
self.__class__.__name__[len("OpenML") :],
7979
)
8080
header_text = f"OpenML {name_with_spaces}"
81-
header = "{}\n{}\n".format(header_text, "=" * len(header_text))
81+
header = f"{header_text}\n{'=' * len(header_text)}\n"
8282

8383
_body_fields: list[tuple[str, str | int | list[str]]] = [
8484
(k, "None" if v is None else v) for k, v in body_fields

openml/datasets/functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ def _list_datasets(
191191
if value is not None:
192192
api_call += f"/{operator}/{value}"
193193
if data_id is not None:
194-
api_call += "/data_id/{}".format(",".join([str(int(i)) for i in data_id]))
194+
api_call += f"/data_id/{','.join([str(int(i)) for i in data_id])}"
195195
return __list_datasets(api_call=api_call)
196196

197197

openml/evaluations/evaluation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def _to_dict(self) -> dict:
100100

101101
def __repr__(self) -> str:
102102
header = "OpenML Evaluation"
103-
header = "{}\n{}\n".format(header, "=" * len(header))
103+
header = f"{header}\n{'=' * len(header)}\n"
104104

105105
fields = {
106106
"Upload Date": self.upload_time,

openml/evaluations/functions.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,15 +204,15 @@ def _list_evaluations( # noqa: C901
204204
if value is not None:
205205
api_call += f"/{operator}/{value}"
206206
if tasks is not None:
207-
api_call += "/task/{}".format(",".join([str(int(i)) for i in tasks]))
207+
api_call += f"/task/{','.join([str(int(i)) for i in tasks])}"
208208
if setups is not None:
209-
api_call += "/setup/{}".format(",".join([str(int(i)) for i in setups]))
209+
api_call += f"/setup/{','.join([str(int(i)) for i in setups])}"
210210
if flows is not None:
211-
api_call += "/flow/{}".format(",".join([str(int(i)) for i in flows]))
211+
api_call += f"/flow/{','.join([str(int(i)) for i in flows])}"
212212
if runs is not None:
213-
api_call += "/run/{}".format(",".join([str(int(i)) for i in runs]))
213+
api_call += f"/run/{','.join([str(int(i)) for i in runs])}"
214214
if uploaders is not None:
215-
api_call += "/uploader/{}".format(",".join([str(int(i)) for i in uploaders]))
215+
api_call += f"/uploader/{','.join([str(int(i)) for i in uploaders])}"
216216
if study is not None:
217217
api_call += f"/study/{study}"
218218
if sort_order is not None:

openml/extensions/sklearn/extension.py

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ def remove_all_in_parentheses(string: str) -> str:
223223
# then the pipeline steps are formatted e.g.:
224224
# step1name=sklearn.submodule.ClassName,step2name...
225225
components = [component.split(".")[-1] for component in pipeline.split(",")]
226-
pipeline = "{}({})".format(pipeline_class, ",".join(components))
226+
pipeline = f"{pipeline_class}({','.join(components)})"
227227
if len(short_name.format(pipeline)) > extra_trim_length:
228228
pipeline = f"{pipeline_class}(...,{components[-1]})"
229229
else:
@@ -482,9 +482,7 @@ def _deserialize_sklearn( # noqa: PLR0915, C901, PLR0912
482482
)
483483
else:
484484
raise TypeError(o)
485-
logger.info(
486-
"-{} flow_to_sklearn END o={}, rval={}".format("-" * recursion_depth, o, rval)
487-
)
485+
logger.info(f"-{'-' * recursion_depth} flow_to_sklearn END o={o}, rval={rval}")
488486
return rval
489487

490488
def model_to_flow(self, model: Any) -> OpenMLFlow:
@@ -574,7 +572,7 @@ def get_version_information(self) -> list[str]:
574572
import sklearn
575573

576574
major, minor, micro, _, _ = sys.version_info
577-
python_version = "Python_{}.".format(".".join([str(major), str(minor), str(micro)]))
575+
python_version = f"Python_{'.'.join([str(major), str(minor), str(micro)])}."
578576
sklearn_version = f"Sklearn_{sklearn.__version__}."
579577
numpy_version = f"NumPy_{numpy.__version__}." # type: ignore
580578
scipy_version = f"SciPy_{scipy.__version__}."
@@ -628,7 +626,7 @@ def _get_sklearn_description(self, model: Any, char_lim: int = 1024) -> str:
628626
"""
629627

630628
def match_format(s):
631-
return "{}\n{}\n".format(s, len(s) * "-")
629+
return f"{s}\n{len(s) * '-'}\n"
632630

633631
s = inspect.getdoc(model)
634632
if s is None:
@@ -680,7 +678,7 @@ def _extract_sklearn_parameter_docstring(self, model) -> None | str:
680678
"""
681679

682680
def match_format(s):
683-
return "{}\n{}\n".format(s, len(s) * "-")
681+
return f"{s}\n{len(s) * '-'}\n"
684682

685683
s = inspect.getdoc(model)
686684
if s is None:
@@ -689,7 +687,7 @@ def match_format(s):
689687
index1 = s.index(match_format("Parameters"))
690688
except ValueError as e:
691689
# when sklearn docstring has no 'Parameters' section
692-
logger.warning("{} {}".format(match_format("Parameters"), e))
690+
logger.warning(f"{match_format('Parameters')} {e}")
693691
return None
694692

695693
headings = ["Attributes", "Notes", "See also", "Note", "References"]
@@ -1151,7 +1149,7 @@ def _deserialize_model( # noqa: C901
11511149
recursion_depth: int,
11521150
strict_version: bool = True, # noqa: FBT002, FBT001
11531151
) -> Any:
1154-
logger.info("-{} deserialize {}".format("-" * recursion_depth, flow.name))
1152+
logger.info(f"-{'-' * recursion_depth} deserialize {flow.name}")
11551153
model_name = flow.class_name
11561154
self._check_dependencies(flow.dependencies, strict_version=strict_version)
11571155

@@ -1168,9 +1166,7 @@ def _deserialize_model( # noqa: C901
11681166

11691167
for name in parameters:
11701168
value = parameters.get(name)
1171-
logger.info(
1172-
"--{} flow_parameter={}, value={}".format("-" * recursion_depth, name, value)
1173-
)
1169+
logger.info(f"--{'-' * recursion_depth} flow_parameter={name}, value={value}")
11741170
rval = self._deserialize_sklearn(
11751171
value,
11761172
components=components_,
@@ -1186,9 +1182,7 @@ def _deserialize_model( # noqa: C901
11861182
if name not in components_:
11871183
continue
11881184
value = components[name]
1189-
logger.info(
1190-
"--{} flow_component={}, value={}".format("-" * recursion_depth, name, value)
1191-
)
1185+
logger.info(f"--{'-' * recursion_depth} flow_component={name}, value={value}")
11921186
rval = self._deserialize_sklearn(
11931187
value,
11941188
recursion_depth=recursion_depth + 1,

openml/runs/functions.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,15 +1154,15 @@ def _list_runs( # noqa: PLR0913, C901
11541154
if offset is not None:
11551155
api_call += f"/offset/{offset}"
11561156
if id is not None:
1157-
api_call += "/run/{}".format(",".join([str(int(i)) for i in id]))
1157+
api_call += f"/run/{','.join([str(int(i)) for i in id])}"
11581158
if task is not None:
1159-
api_call += "/task/{}".format(",".join([str(int(i)) for i in task]))
1159+
api_call += f"/task/{','.join([str(int(i)) for i in task])}"
11601160
if setup is not None:
1161-
api_call += "/setup/{}".format(",".join([str(int(i)) for i in setup]))
1161+
api_call += f"/setup/{','.join([str(int(i)) for i in setup])}"
11621162
if flow is not None:
1163-
api_call += "/flow/{}".format(",".join([str(int(i)) for i in flow]))
1163+
api_call += f"/flow/{','.join([str(int(i)) for i in flow])}"
11641164
if uploader is not None:
1165-
api_call += "/uploader/{}".format(",".join([str(int(i)) for i in uploader]))
1165+
api_call += f"/uploader/{','.join([str(int(i)) for i in uploader])}"
11661166
if study is not None:
11671167
api_call += "/study/%d" % study
11681168
if display_errors:

openml/setups/functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ def _list_setups(
207207
if offset is not None:
208208
api_call += f"/offset/{offset}"
209209
if setup is not None:
210-
api_call += "/setup/{}".format(",".join([str(int(i)) for i in setup]))
210+
api_call += f"/setup/{','.join([str(int(i)) for i in setup])}"
211211
if flow is not None:
212212
api_call += f"/flow/{flow}"
213213
if tag is not None:

0 commit comments

Comments
 (0)