Skip to content

Commit

Permalink
Merge pull request #87 from Alnusjaponica/update-black
Browse files Browse the repository at this point in the history
Apply Black 2024 to codebase
  • Loading branch information
HideakiImamura committed Feb 16, 2024
2 parents cc3d920 + 388140f commit 27e4e05
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 43 deletions.
22 changes: 12 additions & 10 deletions optuna_integration/_lightgbm_tuner/optimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ def _get_metric_for_objective(self) -> str:

def _get_booster_best_score(self, booster: "lgb.Booster") -> float:
metric = self._get_metric_for_objective()
valid_sets: list["lgb.Dataset"] | tuple[
"lgb.Dataset", ...
] | "lgb.Dataset" | None = self.lgbm_kwargs.get("valid_sets")
valid_sets: list["lgb.Dataset"] | tuple["lgb.Dataset", ...] | "lgb.Dataset" | None = (
self.lgbm_kwargs.get("valid_sets")
)

if self.lgbm_kwargs.get("valid_names") is not None:
if isinstance(self.lgbm_kwargs["valid_names"], str):
Expand Down Expand Up @@ -172,9 +172,9 @@ def __init__(

self.trial_count = 0
self.best_score = best_score
self.best_booster_with_trial_number: tuple[
"lgb.Booster" | "lgb.CVBooster", int
] | None = None
self.best_booster_with_trial_number: tuple["lgb.Booster" | "lgb.CVBooster", int] | None = (
None
)
self.step_name = step_name
self.model_dir = model_dir

Expand Down Expand Up @@ -945,10 +945,12 @@ def __init__(
params: dict[str, Any],
train_set: "lgb.Dataset",
num_boost_round: int = 1000,
folds: Generator[tuple[int, int], None, None]
| Iterator[tuple[int, int]]
| "BaseCrossValidator"
| None = None,
folds: (
Generator[tuple[int, int], None, None]
| Iterator[tuple[int, int]]
| "BaseCrossValidator"
| None
) = None,
nfold: int = 5,
stratified: bool = True,
shuffle: bool = True,
Expand Down
20 changes: 7 additions & 13 deletions optuna_integration/chainermn.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,30 +199,24 @@ def func() -> int:
return self._call_with_mpi(func)

@overload
def suggest_categorical(self, name: str, choices: Sequence[None]) -> None:
...
def suggest_categorical(self, name: str, choices: Sequence[None]) -> None: ... # noqa: E704

@overload
def suggest_categorical(self, name: str, choices: Sequence[bool]) -> bool:
...
def suggest_categorical(self, name: str, choices: Sequence[bool]) -> bool: ... # noqa: E704

@overload
def suggest_categorical(self, name: str, choices: Sequence[int]) -> int:
...
def suggest_categorical(self, name: str, choices: Sequence[int]) -> int: ... # noqa: E704

@overload
def suggest_categorical(self, name: str, choices: Sequence[float]) -> float:
...
def suggest_categorical(self, name: str, choices: Sequence[float]) -> float: ... # noqa: E704

@overload
def suggest_categorical(self, name: str, choices: Sequence[str]) -> str:
...
def suggest_categorical(self, name: str, choices: Sequence[str]) -> str: ... # noqa: E704

@overload
def suggest_categorical(
def suggest_categorical( # noqa: E704
self, name: str, choices: Sequence[CategoricalChoiceType]
) -> CategoricalChoiceType:
...
) -> CategoricalChoiceType: ...

def suggest_categorical(
self, name: str, choices: Sequence[CategoricalChoiceType]
Expand Down
14 changes: 8 additions & 6 deletions optuna_integration/dask.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,14 @@ def _serialize_frozenstudy(study: FrozenStudy) -> dict:
"directions": [d.name for d in study._directions],
"study_id": study._study_id,
"study_name": study.study_name,
"user_attrs": dumps(study.user_attrs) # type: ignore[no-untyped-call]
if study.user_attrs
else {},
"system_attrs": dumps(study.system_attrs) # type: ignore[no-untyped-call]
if study.system_attrs
else {},
"user_attrs": (
dumps(study.user_attrs) if study.user_attrs else {} # type: ignore[no-untyped-call]
),
"system_attrs": (
dumps(study.system_attrs) # type: ignore[no-untyped-call]
if study.system_attrs
else {}
),
}
return data

Expand Down
20 changes: 7 additions & 13 deletions optuna_integration/pytorch_distributed.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,30 +191,24 @@ def func() -> float:
return self._call_and_communicate(func, torch.int)

@overload
def suggest_categorical(self, name: str, choices: Sequence[None]) -> None:
...
def suggest_categorical(self, name: str, choices: Sequence[None]) -> None: ... # noqa: E704

@overload
def suggest_categorical(self, name: str, choices: Sequence[bool]) -> bool:
...
def suggest_categorical(self, name: str, choices: Sequence[bool]) -> bool: ... # noqa: E704

@overload
def suggest_categorical(self, name: str, choices: Sequence[int]) -> int:
...
def suggest_categorical(self, name: str, choices: Sequence[int]) -> int: ... # noqa: E704

@overload
def suggest_categorical(self, name: str, choices: Sequence[float]) -> float:
...
def suggest_categorical(self, name: str, choices: Sequence[float]) -> float: ... # noqa: E704

@overload
def suggest_categorical(self, name: str, choices: Sequence[str]) -> str:
...
def suggest_categorical(self, name: str, choices: Sequence[str]) -> str: ... # noqa: E704

@overload
def suggest_categorical(
def suggest_categorical( # noqa: E704
self, name: str, choices: Sequence[CategoricalChoiceType]
) -> CategoricalChoiceType:
...
) -> CategoricalChoiceType: ...

@broadcast_properties
def suggest_categorical(
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ test = [
"fakeredis[lua]",
]
checking = [
"black<24.0.0",
"black",
"blackdoc",
"hacking",
"isort",
Expand Down

0 comments on commit 27e4e05

Please sign in to comment.