Skip to content

Commit 0156bc4

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 821d9ef commit 0156bc4

File tree

19 files changed

+124
-189
lines changed

19 files changed

+124
-189
lines changed

openml/_api_calls.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -366,18 +366,15 @@ def _send_request( # noqa: C901
366366
# -- Check if encoding is not UTF-8 perhaps
367367
if __is_checksum_equal(response.content, md5_checksum):
368368
raise OpenMLHashException(
369-
"Checksum of downloaded file is unequal to the expected checksum {}"
370-
"because the text encoding is not UTF-8 when downloading {}. "
369+
f"Checksum of downloaded file is unequal to the expected checksum {md5_checksum}"
370+
f"because the text encoding is not UTF-8 when downloading {url}. "
371371
"There might be a sever-sided issue with the file, "
372-
"see: https://github.com/openml/openml-python/issues/1180.".format(
373-
md5_checksum,
374-
url,
375-
),
372+
"see: https://github.com/openml/openml-python/issues/1180.",
376373
)
377374

378375
raise OpenMLHashException(
379-
"Checksum of downloaded file is unequal to the expected checksum {} "
380-
"when downloading {}.".format(md5_checksum, url),
376+
f"Checksum of downloaded file is unequal to the expected checksum {md5_checksum} "
377+
f"when downloading {url}.",
381378
)
382379

383380
return response
@@ -443,7 +440,7 @@ def __parse_server_exception(
443440
server_exception = xmltodict.parse(response.text)
444441
except xml.parsers.expat.ExpatError as e:
445442
raise e
446-
except Exception as e: # noqa: BLE001
443+
except Exception as e:
447444
# OpenML has a sophisticated error system
448445
# where information about failures is provided. try to parse this
449446
raise OpenMLServerError(

openml/cli.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
""""Command Line Interface for `openml` to configure its settings."""
1+
""" "Command Line Interface for `openml` to configure its settings."""
2+
23
from __future__ import annotations
34

45
import argparse

openml/config.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -273,17 +273,17 @@ def _setup(config: _Config | None = None) -> None:
273273
_root_cache_directory.mkdir(exist_ok=True, parents=True)
274274
except PermissionError:
275275
openml_logger.warning(
276-
"No permission to create openml cache directory at %s! This can result in "
277-
"OpenML-Python not working properly." % _root_cache_directory,
276+
f"No permission to create openml cache directory at {_root_cache_directory}! This can result in "
277+
"OpenML-Python not working properly.",
278278
)
279279

280280
if cache_exists:
281281
_create_log_handlers()
282282
else:
283283
_create_log_handlers(create_file_handler=False)
284284
openml_logger.warning(
285-
"No permission to create OpenML directory at %s! This can result in OpenML-Python "
286-
"not working properly." % config_dir,
285+
f"No permission to create OpenML directory at {config_dir}! This can result in OpenML-Python "
286+
"not working properly.",
287287
)
288288

289289

openml/datasets/dataset.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,14 @@ def find_invalid_characters(string: str, pattern: str) -> str:
156156
)
157157

158158
if dataset_id is None:
159-
pattern = "^[\x00-\x7F]*$"
159+
pattern = "^[\x00-\x7f]*$"
160160
if description and not re.match(pattern, description):
161161
# not basiclatin (XSD complains)
162162
invalid_characters = find_invalid_characters(description, pattern)
163163
raise ValueError(
164164
f"Invalid symbols {invalid_characters} in description: {description}",
165165
)
166-
pattern = "^[\x00-\x7F]*$"
166+
pattern = "^[\x00-\x7f]*$"
167167
if citation and not re.match(pattern, citation):
168168
# not basiclatin (XSD complains)
169169
invalid_characters = find_invalid_characters(citation, pattern)
@@ -540,7 +540,7 @@ def _cache_compressed_file_from_file(
540540
elif data_file.suffix == ".pq":
541541
try:
542542
data = pd.read_parquet(data_file)
543-
except Exception as e: # noqa: BLE001
543+
except Exception as e:
544544
raise Exception(f"File: {data_file}") from e
545545

546546
categorical = [data[c].dtype.name == "category" for c in data.columns]
@@ -806,7 +806,7 @@ def get_data( # noqa: C901, PLR0912, PLR0915
806806
to_exclude.extend(self.ignore_attribute)
807807

808808
if len(to_exclude) > 0:
809-
logger.info("Going to remove the following attributes: %s" % to_exclude)
809+
logger.info(f"Going to remove the following attributes: {to_exclude}")
810810
keep = np.array([column not in to_exclude for column in attribute_names])
811811
data = data.loc[:, keep] if isinstance(data, pd.DataFrame) else data[:, keep]
812812

openml/datasets/functions.py

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ def list_datasets(
8585
*,
8686
output_format: Literal["dataframe"],
8787
**kwargs: Any,
88-
) -> pd.DataFrame:
89-
...
88+
) -> pd.DataFrame: ...
9089

9190

9291
@overload
@@ -98,8 +97,7 @@ def list_datasets(
9897
tag: str | None,
9998
output_format: Literal["dataframe"],
10099
**kwargs: Any,
101-
) -> pd.DataFrame:
102-
...
100+
) -> pd.DataFrame: ...
103101

104102

105103
@overload
@@ -111,8 +109,7 @@ def list_datasets(
111109
tag: str | None = ...,
112110
output_format: Literal["dict"] = "dict",
113111
**kwargs: Any,
114-
) -> pd.DataFrame:
115-
...
112+
) -> pd.DataFrame: ...
116113

117114

118115
def list_datasets(
@@ -207,17 +204,15 @@ def _list_datasets(
207204
data_id: list | None = ...,
208205
output_format: Literal["dict"] = "dict",
209206
**kwargs: Any,
210-
) -> dict:
211-
...
207+
) -> dict: ...
212208

213209

214210
@overload
215211
def _list_datasets(
216212
data_id: list | None = ...,
217213
output_format: Literal["dataframe"] = "dataframe",
218214
**kwargs: Any,
219-
) -> pd.DataFrame:
220-
...
215+
) -> pd.DataFrame: ...
221216

222217

223218
def _list_datasets(
@@ -256,18 +251,16 @@ def _list_datasets(
256251
for operator, value in kwargs.items():
257252
api_call += f"/{operator}/{value}"
258253
if data_id is not None:
259-
api_call += "/data_id/%s" % ",".join([str(int(i)) for i in data_id])
254+
api_call += "/data_id/{}".format(",".join([str(int(i)) for i in data_id]))
260255
return __list_datasets(api_call=api_call, output_format=output_format)
261256

262257

263258
@overload
264-
def __list_datasets(api_call: str, output_format: Literal["dict"] = "dict") -> dict:
265-
...
259+
def __list_datasets(api_call: str, output_format: Literal["dict"] = "dict") -> dict: ...
266260

267261

268262
@overload
269-
def __list_datasets(api_call: str, output_format: Literal["dataframe"]) -> pd.DataFrame:
270-
...
263+
def __list_datasets(api_call: str, output_format: Literal["dataframe"]) -> pd.DataFrame: ...
271264

272265

273266
def __list_datasets(
@@ -804,10 +797,7 @@ def create_dataset( # noqa: C901, PLR0912, PLR0915
804797
if not is_row_id_an_attribute:
805798
raise ValueError(
806799
"'row_id_attribute' should be one of the data attribute. "
807-
" Got '{}' while candidates are {}.".format(
808-
row_id_attribute,
809-
[attr[0] for attr in attributes_],
810-
),
800+
f" Got '{row_id_attribute}' while candidates are {[attr[0] for attr in attributes_]}.",
811801
)
812802

813803
if isinstance(data, pd.DataFrame):

openml/evaluations/functions.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ def list_evaluations(
3232
per_fold: bool | None = ...,
3333
sort_order: str | None = ...,
3434
output_format: Literal["dict", "object"] = "dict",
35-
) -> dict:
36-
...
35+
) -> dict: ...
3736

3837

3938
@overload
@@ -51,8 +50,7 @@ def list_evaluations(
5150
per_fold: bool | None = ...,
5251
sort_order: str | None = ...,
5352
output_format: Literal["dataframe"] = ...,
54-
) -> pd.DataFrame:
55-
...
53+
) -> pd.DataFrame: ...
5654

5755

5856
def list_evaluations(
@@ -204,24 +202,24 @@ def _list_evaluations(
204202
-------
205203
dict of objects, or dataframe
206204
"""
207-
api_call = "evaluation/list/function/%s" % function
205+
api_call = f"evaluation/list/function/{function}"
208206
if kwargs is not None:
209207
for operator, value in kwargs.items():
210208
api_call += f"/{operator}/{value}"
211209
if tasks is not None:
212-
api_call += "/task/%s" % ",".join([str(int(i)) for i in tasks])
210+
api_call += "/task/{}".format(",".join([str(int(i)) for i in tasks]))
213211
if setups is not None:
214-
api_call += "/setup/%s" % ",".join([str(int(i)) for i in setups])
212+
api_call += "/setup/{}".format(",".join([str(int(i)) for i in setups]))
215213
if flows is not None:
216-
api_call += "/flow/%s" % ",".join([str(int(i)) for i in flows])
214+
api_call += "/flow/{}".format(",".join([str(int(i)) for i in flows]))
217215
if runs is not None:
218-
api_call += "/run/%s" % ",".join([str(int(i)) for i in runs])
216+
api_call += "/run/{}".format(",".join([str(int(i)) for i in runs]))
219217
if uploaders is not None:
220-
api_call += "/uploader/%s" % ",".join([str(int(i)) for i in uploaders])
218+
api_call += "/uploader/{}".format(",".join([str(int(i)) for i in uploaders]))
221219
if study is not None:
222220
api_call += "/study/%d" % study
223221
if sort_order is not None:
224-
api_call += "/sort_order/%s" % sort_order
222+
api_call += f"/sort_order/{sort_order}"
225223

226224
return __list_evaluations(api_call, output_format=output_format)
227225

@@ -236,7 +234,7 @@ def __list_evaluations(
236234
# Minimalistic check if the XML is useful
237235
if "oml:evaluations" not in evals_dict:
238236
raise ValueError(
239-
"Error in return XML, does not contain " '"oml:evaluations": %s' % str(evals_dict),
237+
"Error in return XML, does not contain " f'"oml:evaluations": {evals_dict!s}',
240238
)
241239

242240
assert isinstance(evals_dict["oml:evaluations"]["oml:evaluation"], list), type(

openml/extensions/sklearn/extension.py

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ def _deserialize_sklearn( # noqa: PLR0915, C901, PLR0913, PLR0912
419419
strict_version=strict_version,
420420
)
421421
else:
422-
raise ValueError("Cannot flow_to_sklearn %s" % serialized_type)
422+
raise ValueError(f"Cannot flow_to_sklearn {serialized_type}")
423423

424424
else:
425425
rval = OrderedDict(
@@ -979,17 +979,15 @@ def flatten_all(list_):
979979
# length 2 is for {VotingClassifier.estimators,
980980
# Pipeline.steps, FeatureUnion.transformer_list}
981981
# length 3 is for ColumnTransformer
982-
msg = "Length of tuple of type {} does not match assumptions".format(
983-
sub_component_type,
984-
)
982+
msg = f"Length of tuple of type {sub_component_type} does not match assumptions"
985983
raise ValueError(msg)
986984

987985
if isinstance(sub_component, str):
988986
if sub_component not in SKLEARN_PIPELINE_STRING_COMPONENTS:
989987
msg = (
990988
"Second item of tuple does not match assumptions. "
991989
"If string, can be only 'drop' or 'passthrough' but"
992-
"got %s" % sub_component
990+
f"got {sub_component}"
993991
)
994992
raise ValueError(msg)
995993
elif sub_component is None:
@@ -1002,15 +1000,15 @@ def flatten_all(list_):
10021000
elif not isinstance(sub_component, OpenMLFlow):
10031001
msg = (
10041002
"Second item of tuple does not match assumptions. "
1005-
"Expected OpenMLFlow, got %s" % type(sub_component)
1003+
f"Expected OpenMLFlow, got {type(sub_component)}"
10061004
)
10071005
raise TypeError(msg)
10081006

10091007
if identifier in reserved_keywords:
10101008
parent_model = f"{model.__module__}.{model.__class__.__name__}"
1011-
msg = "Found element shadowing official " "parameter for {}: {}".format(
1012-
parent_model,
1013-
identifier,
1009+
msg = (
1010+
"Found element shadowing official "
1011+
f"parameter for {parent_model}: {identifier}"
10141012
)
10151013
raise PyOpenMLError(msg)
10161014

@@ -1035,9 +1033,9 @@ def flatten_all(list_):
10351033
model=None,
10361034
)
10371035
component_reference: OrderedDict[str, str | dict] = OrderedDict()
1038-
component_reference[
1039-
"oml-python:serialized_object"
1040-
] = COMPOSITION_STEP_CONSTANT
1036+
component_reference["oml-python:serialized_object"] = (
1037+
COMPOSITION_STEP_CONSTANT
1038+
)
10411039
cr_value: dict[str, Any] = OrderedDict()
10421040
cr_value["key"] = identifier
10431041
cr_value["step_name"] = identifier
@@ -1218,7 +1216,7 @@ def _check_dependencies(
12181216
for dependency_string in dependencies_list:
12191217
match = DEPENDENCIES_PATTERN.match(dependency_string)
12201218
if not match:
1221-
raise ValueError("Cannot parse dependency %s" % dependency_string)
1219+
raise ValueError(f"Cannot parse dependency {dependency_string}")
12221220

12231221
dependency_name = match.group("name")
12241222
operation = match.group("operation")
@@ -1237,7 +1235,7 @@ def _check_dependencies(
12371235
installed_version > required_version or installed_version == required_version
12381236
)
12391237
else:
1240-
raise NotImplementedError("operation '%s' is not supported" % operation)
1238+
raise NotImplementedError(f"operation '{operation}' is not supported")
12411239
message = (
12421240
"Trying to deserialize a model with dependency "
12431241
f"{dependency_string} not satisfied."
@@ -1812,10 +1810,7 @@ def _prediction_to_probabilities(
18121810
# then we need to add a column full of zeros into the probabilities
18131811
# for class 3 because the rest of the library expects that the
18141812
# probabilities are ordered the same way as the classes are ordered).
1815-
message = "Estimator only predicted for {}/{} classes!".format(
1816-
proba_y.shape[1],
1817-
len(task.class_labels),
1818-
)
1813+
message = f"Estimator only predicted for {proba_y.shape[1]}/{len(task.class_labels)} classes!"
18191814
warnings.warn(message, stacklevel=2)
18201815
openml.config.logger.warning(message)
18211816

@@ -2008,9 +2003,7 @@ def is_subcomponent_specification(values):
20082003
pass
20092004
else:
20102005
raise TypeError(
2011-
"Subcomponent flow should be of type flow, but is {}".format(
2012-
type(subcomponent_flow),
2013-
),
2006+
f"Subcomponent flow should be of type flow, but is {type(subcomponent_flow)}",
20142007
)
20152008

20162009
current = {
@@ -2129,8 +2122,7 @@ def instantiate_model_from_hpo_class(
21292122
"""
21302123
if not self._is_hpo_class(model):
21312124
raise AssertionError(
2132-
"Flow model %s is not an instance of sklearn.model_selection._search.BaseSearchCV"
2133-
% model,
2125+
f"Flow model {model} is not an instance of sklearn.model_selection._search.BaseSearchCV",
21342126
)
21352127
base_estimator = model.estimator
21362128
base_estimator.set_params(**trace_iteration.get_parameters())
@@ -2192,8 +2184,7 @@ def _obtain_arff_trace(
21922184
"""
21932185
if not self._is_hpo_class(model):
21942186
raise AssertionError(
2195-
"Flow model %s is not an instance of sklearn.model_selection._search.BaseSearchCV"
2196-
% model,
2187+
f"Flow model {model} is not an instance of sklearn.model_selection._search.BaseSearchCV",
21972188
)
21982189
if not hasattr(model, "cv_results_"):
21992190
raise ValueError("model should contain `cv_results_`")
@@ -2228,7 +2219,7 @@ def _obtain_arff_trace(
22282219
# hyperparameter layer_sizes of MLPClassifier
22292220
type = "STRING" # noqa: A001
22302221
else:
2231-
raise TypeError("Unsupported param type in param grid: %s" % key)
2222+
raise TypeError(f"Unsupported param type in param grid: {key}")
22322223

22332224
# renamed the attribute param to parameter, as this is a required
22342225
# OpenML convention - this also guards against name collisions

openml/flows/flow.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,13 @@ def __init__( # noqa: PLR0913
135135
keys_parameters_meta_info = set(parameters_meta_info.keys())
136136
if len(keys_parameters.difference(keys_parameters_meta_info)) > 0:
137137
raise ValueError(
138-
"Parameter %s only in parameters, but not in "
139-
"parameters_meta_info."
140-
% str(keys_parameters.difference(keys_parameters_meta_info)),
138+
f"Parameter {keys_parameters.difference(keys_parameters_meta_info)!s} only in parameters, but not in "
139+
"parameters_meta_info.",
141140
)
142141
if len(keys_parameters_meta_info.difference(keys_parameters)) > 0:
143142
raise ValueError(
144-
"Parameter %s only in parameters_meta_info, "
145-
"but not in parameters."
146-
% str(keys_parameters_meta_info.difference(keys_parameters)),
143+
f"Parameter {keys_parameters_meta_info.difference(keys_parameters)!s} only in parameters_meta_info, "
144+
"but not in parameters.",
147145
)
148146

149147
self.external_version = external_version

0 commit comments

Comments
 (0)