Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Apr 8, 2024
1 parent f3b8a20 commit 2025c5e
Show file tree
Hide file tree
Showing 12 changed files with 61 additions and 121 deletions.
13 changes: 5 additions & 8 deletions openml/_api_calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,18 +366,15 @@ def _send_request( # noqa: C901
# -- Check if encoding is not UTF-8 perhaps
if __is_checksum_equal(response.content, md5_checksum):
raise OpenMLHashException(
"Checksum of downloaded file is unequal to the expected checksum {}"
"because the text encoding is not UTF-8 when downloading {}. "
f"Checksum of downloaded file is unequal to the expected checksum {md5_checksum}"
f"because the text encoding is not UTF-8 when downloading {url}. "
"There might be a sever-sided issue with the file, "
"see: https://github.com/openml/openml-python/issues/1180.".format(
md5_checksum,
url,
),
"see: https://github.com/openml/openml-python/issues/1180.",
)

raise OpenMLHashException(
"Checksum of downloaded file is unequal to the expected checksum {} "
"when downloading {}.".format(md5_checksum, url),
f"Checksum of downloaded file is unequal to the expected checksum {md5_checksum} "
f"when downloading {url}.",
)

return response
Expand Down
3 changes: 2 additions & 1 deletion openml/cli.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
""""Command Line Interface for `openml` to configure its settings."""
""" "Command Line Interface for `openml` to configure its settings."""

from __future__ import annotations

import argparse
Expand Down
4 changes: 2 additions & 2 deletions openml/datasets/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,14 @@ def find_invalid_characters(string: str, pattern: str) -> str:
)

if dataset_id is None:
pattern = "^[\x00-\x7F]*$"
pattern = "^[\x00-\x7f]*$"
if description and not re.match(pattern, description):
# not basiclatin (XSD complains)
invalid_characters = find_invalid_characters(description, pattern)
raise ValueError(
f"Invalid symbols {invalid_characters} in description: {description}",
)
pattern = "^[\x00-\x7F]*$"
pattern = "^[\x00-\x7f]*$"
if citation and not re.match(pattern, citation):
# not basiclatin (XSD complains)
invalid_characters = find_invalid_characters(citation, pattern)
Expand Down
26 changes: 8 additions & 18 deletions openml/datasets/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ def list_datasets(
*,
output_format: Literal["dataframe"],
**kwargs: Any,
) -> pd.DataFrame:
...
) -> pd.DataFrame: ...


@overload
Expand All @@ -98,8 +97,7 @@ def list_datasets(
tag: str | None,
output_format: Literal["dataframe"],
**kwargs: Any,
) -> pd.DataFrame:
...
) -> pd.DataFrame: ...


@overload
Expand All @@ -111,8 +109,7 @@ def list_datasets(
tag: str | None = ...,
output_format: Literal["dict"] = "dict",
**kwargs: Any,
) -> pd.DataFrame:
...
) -> pd.DataFrame: ...


def list_datasets(
Expand Down Expand Up @@ -207,17 +204,15 @@ def _list_datasets(
data_id: list | None = ...,
output_format: Literal["dict"] = "dict",
**kwargs: Any,
) -> dict:
...
) -> dict: ...


@overload
def _list_datasets(
data_id: list | None = ...,
output_format: Literal["dataframe"] = "dataframe",
**kwargs: Any,
) -> pd.DataFrame:
...
) -> pd.DataFrame: ...


def _list_datasets(
Expand Down Expand Up @@ -261,13 +256,11 @@ def _list_datasets(


@overload
def __list_datasets(api_call: str, output_format: Literal["dict"] = "dict") -> dict:
...
def __list_datasets(api_call: str, output_format: Literal["dict"] = "dict") -> dict: ...


@overload
def __list_datasets(api_call: str, output_format: Literal["dataframe"]) -> pd.DataFrame:
...
def __list_datasets(api_call: str, output_format: Literal["dataframe"]) -> pd.DataFrame: ...


def __list_datasets(
Expand Down Expand Up @@ -804,10 +797,7 @@ def create_dataset( # noqa: C901, PLR0912, PLR0915
if not is_row_id_an_attribute:
raise ValueError(
"'row_id_attribute' should be one of the data attribute. "
" Got '{}' while candidates are {}.".format(
row_id_attribute,
[attr[0] for attr in attributes_],
),
f" Got '{row_id_attribute}' while candidates are {[attr[0] for attr in attributes_]}.",
)

if isinstance(data, pd.DataFrame):
Expand Down
6 changes: 2 additions & 4 deletions openml/evaluations/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ def list_evaluations(
per_fold: bool | None = ...,
sort_order: str | None = ...,
output_format: Literal["dict", "object"] = "dict",
) -> dict:
...
) -> dict: ...


@overload
Expand All @@ -51,8 +50,7 @@ def list_evaluations(
per_fold: bool | None = ...,
sort_order: str | None = ...,
output_format: Literal["dataframe"] = ...,
) -> pd.DataFrame:
...
) -> pd.DataFrame: ...


def list_evaluations(
Expand Down
25 changes: 9 additions & 16 deletions openml/extensions/sklearn/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -979,9 +979,7 @@ def flatten_all(list_):
# length 2 is for {VotingClassifier.estimators,
# Pipeline.steps, FeatureUnion.transformer_list}
# length 3 is for ColumnTransformer
msg = "Length of tuple of type {} does not match assumptions".format(
sub_component_type,
)
msg = f"Length of tuple of type {sub_component_type} does not match assumptions"
raise ValueError(msg)

if isinstance(sub_component, str):
Expand All @@ -1008,9 +1006,9 @@ def flatten_all(list_):

if identifier in reserved_keywords:
parent_model = f"{model.__module__}.{model.__class__.__name__}"
msg = "Found element shadowing official " "parameter for {}: {}".format(
parent_model,
identifier,
msg = (
"Found element shadowing official "
f"parameter for {parent_model}: {identifier}"
)
raise PyOpenMLError(msg)

Expand All @@ -1035,9 +1033,9 @@ def flatten_all(list_):
model=None,
)
component_reference: OrderedDict[str, str | dict] = OrderedDict()
component_reference[
"oml-python:serialized_object"
] = COMPOSITION_STEP_CONSTANT
component_reference["oml-python:serialized_object"] = (
COMPOSITION_STEP_CONSTANT
)
cr_value: dict[str, Any] = OrderedDict()
cr_value["key"] = identifier
cr_value["step_name"] = identifier
Expand Down Expand Up @@ -1812,10 +1810,7 @@ def _prediction_to_probabilities(
# then we need to add a column full of zeros into the probabilities
# for class 3 because the rest of the library expects that the
# probabilities are ordered the same way as the classes are ordered).
message = "Estimator only predicted for {}/{} classes!".format(
proba_y.shape[1],
len(task.class_labels),
)
message = f"Estimator only predicted for {proba_y.shape[1]}/{len(task.class_labels)} classes!"
warnings.warn(message, stacklevel=2)
openml.config.logger.warning(message)

Expand Down Expand Up @@ -2008,9 +2003,7 @@ def is_subcomponent_specification(values):
pass
else:
raise TypeError(
"Subcomponent flow should be of type flow, but is {}".format(
type(subcomponent_flow),
),
f"Subcomponent flow should be of type flow, but is {type(subcomponent_flow)}",
)

current = {
Expand Down
24 changes: 8 additions & 16 deletions openml/flows/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,7 @@ def list_flows(
tag: str | None = ...,
output_format: Literal["dict"] = "dict",
**kwargs: Any,
) -> dict:
...
) -> dict: ...


@overload
Expand All @@ -152,8 +151,7 @@ def list_flows(
*,
output_format: Literal["dataframe"],
**kwargs: Any,
) -> pd.DataFrame:
...
) -> pd.DataFrame: ...


@overload
Expand All @@ -163,8 +161,7 @@ def list_flows(
tag: str | None,
output_format: Literal["dataframe"],
**kwargs: Any,
) -> pd.DataFrame:
...
) -> pd.DataFrame: ...


def list_flows(
Expand Down Expand Up @@ -243,18 +240,15 @@ def list_flows(


@overload
def _list_flows(output_format: Literal["dict"] = ..., **kwargs: Any) -> dict:
...
def _list_flows(output_format: Literal["dict"] = ..., **kwargs: Any) -> dict: ...


@overload
def _list_flows(*, output_format: Literal["dataframe"], **kwargs: Any) -> pd.DataFrame:
...
def _list_flows(*, output_format: Literal["dataframe"], **kwargs: Any) -> pd.DataFrame: ...


@overload
def _list_flows(output_format: Literal["dataframe"], **kwargs: Any) -> pd.DataFrame:
...
def _list_flows(output_format: Literal["dataframe"], **kwargs: Any) -> pd.DataFrame: ...


def _list_flows(
Expand Down Expand Up @@ -391,13 +385,11 @@ def get_flow_id(


@overload
def __list_flows(api_call: str, output_format: Literal["dict"] = "dict") -> dict:
...
def __list_flows(api_call: str, output_format: Literal["dict"] = "dict") -> dict: ...


@overload
def __list_flows(api_call: str, output_format: Literal["dataframe"]) -> pd.DataFrame:
...
def __list_flows(api_call: str, output_format: Literal["dataframe"]) -> pd.DataFrame: ...


def __list_flows(
Expand Down
14 changes: 4 additions & 10 deletions openml/runs/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,9 +680,9 @@ def _calculate_local_measure( # type: ignore
user_defined_measures_per_fold[measure][rep_no][fold_no] = user_defined_measures_fold[
measure
]
user_defined_measures_per_sample[measure][rep_no][fold_no][
sample_no
] = user_defined_measures_fold[measure]
user_defined_measures_per_sample[measure][rep_no][fold_no][sample_no] = (
user_defined_measures_fold[measure]
)

trace: OpenMLRunTrace | None = None
if len(traces) > 0:
Expand Down Expand Up @@ -784,13 +784,7 @@ def _run_task_get_arffcontent_parallel_helper( # noqa: PLR0913
raise NotImplementedError(task.task_type)

config.logger.info(
"Going to run model {} on dataset {} for repeat {} fold {} sample {}".format(
str(model),
openml.datasets.get_dataset(task.dataset_id).name,
rep_no,
fold_no,
sample_no,
),
f"Going to run model {model!s} on dataset {openml.datasets.get_dataset(task.dataset_id).name} for repeat {rep_no} fold {fold_no} sample {sample_no}",
)
(
pred_y,
Expand Down
10 changes: 2 additions & 8 deletions openml/runs/trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,10 +504,7 @@ def merge_traces(cls, traces: list[OpenMLRunTrace]) -> OpenMLRunTrace:
if list(param_keys) != list(trace_itr_keys):
raise ValueError(
"Cannot merge traces because the parameters are not equal: "
"{} vs {}".format(
list(trace_itr.parameters.keys()),
list(iteration.parameters.keys()),
),
f"{list(trace_itr.parameters.keys())} vs {list(iteration.parameters.keys())}",
)

if key in merged_trace:
Expand All @@ -521,10 +518,7 @@ def merge_traces(cls, traces: list[OpenMLRunTrace]) -> OpenMLRunTrace:
return cls(None, merged_trace)

def __repr__(self) -> str:
return "[Run id: {}, {} trace iterations]".format(
-1 if self.run_id is None else self.run_id,
len(self.trace_iterations),
)
return f"[Run id: {-1 if self.run_id is None else self.run_id}, {len(self.trace_iterations)} trace iterations]"

def __iter__(self) -> Iterator[OpenMLTraceIteration]:
yield from self.trace_iterations.values()
Loading

0 comments on commit 2025c5e

Please sign in to comment.