Skip to content

Commit

Permalink
[python] added f-strings to python-package/lightgbm/engine.py (#4258)
Browse files Browse the repository at this point in the history
  • Loading branch information
kantajitshaw authored May 5, 2021
1 parent fcd2453 commit 11b7747
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions python-package/lightgbm/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,12 @@ def train(params, train_set, num_boost_round=100,
for alias in _ConfigAliases.get("num_iterations"):
if alias in params:
num_boost_round = params.pop(alias)
_log_warning("Found `{}` in params. Will use it instead of argument".format(alias))
_log_warning(f"Found `{alias}` in params. Will use it instead of argument")
params["num_iterations"] = num_boost_round
for alias in _ConfigAliases.get("early_stopping_round"):
if alias in params:
early_stopping_rounds = params.pop(alias)
_log_warning("Found `{}` in params. Will use it instead of argument".format(alias))
_log_warning(f"Found `{alias}` in params. Will use it instead of argument")
params["early_stopping_round"] = early_stopping_rounds
first_metric_only = params.get('first_metric_only', False)

Expand Down Expand Up @@ -198,7 +198,7 @@ def train(params, train_set, num_boost_round=100,
if valid_names is not None and len(valid_names) > i:
name_valid_sets.append(valid_names[i])
else:
name_valid_sets.append('valid_' + str(i))
name_valid_sets.append(f'valid_{i}')
# process callbacks
if callbacks is None:
callbacks = set()
Expand Down Expand Up @@ -383,7 +383,7 @@ def _agg_cv_result(raw_results, eval_train_metric=False):
for one_result in raw_results:
for one_line in one_result:
if eval_train_metric:
key = "{} {}".format(one_line[0], one_line[1])
key = f"{one_line[0]} {one_line[1]}"
else:
key = one_line[1]
metric_type[key] = one_line[3]
Expand Down Expand Up @@ -532,12 +532,12 @@ def cv(params, train_set, num_boost_round=100,
params['objective'] = 'none'
for alias in _ConfigAliases.get("num_iterations"):
if alias in params:
_log_warning("Found `{}` in params. Will use it instead of argument".format(alias))
_log_warning(f"Found `{alias}` in params. Will use it instead of argument")
num_boost_round = params.pop(alias)
params["num_iterations"] = num_boost_round
for alias in _ConfigAliases.get("early_stopping_round"):
if alias in params:
_log_warning("Found `{}` in params. Will use it instead of argument".format(alias))
_log_warning(f"Found `{alias}` in params. Will use it instead of argument")
early_stopping_rounds = params.pop(alias)
params["early_stopping_round"] = early_stopping_rounds
first_metric_only = params.get('first_metric_only', False)
Expand Down Expand Up @@ -597,8 +597,8 @@ def cv(params, train_set, num_boost_round=100,
cvfolds.update(fobj=fobj)
res = _agg_cv_result(cvfolds.eval_valid(feval), eval_train_metric)
for _, key, mean, _, std in res:
results[key + '-mean'].append(mean)
results[key + '-stdv'].append(std)
results[f'{key}-mean'].append(mean)
results[f'{key}-stdv'].append(std)
try:
for cb in callbacks_after_iter:
cb(callback.CallbackEnv(model=cvfolds,
Expand Down

0 comments on commit 11b7747

Please sign in to comment.