From 56f73b419f11ee2ebeba5076688acab45d886260 Mon Sep 17 00:00:00 2001 From: James Lamb Date: Tue, 3 Oct 2023 21:48:33 -0500 Subject: [PATCH] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: José Morales --- python-package/lightgbm/callback.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/python-package/lightgbm/callback.py b/python-package/lightgbm/callback.py index 555822a40131..dcbb51cd2af2 100644 --- a/python-package/lightgbm/callback.py +++ b/python-package/lightgbm/callback.py @@ -233,8 +233,8 @@ def __call__(self, env: CallbackEnv) -> None: env.model.reset_parameter(new_parameters) else: # CVBooster holds a list of Booster objects, each needs to be updated - for i in range(len(env.model.boosters)): - env.model.boosters[i].reset_parameter(new_parameters) + for booster in env.model.boosters: + booster.reset_parameter(new_parameters) env.params.update(new_parameters) @@ -304,9 +304,8 @@ def _is_train_set(self, ds_name: str, eval_name: str, env: CallbackEnv) -> bool: return True # for lgb.train(), it's possible to pass the training data via valid_sets with any eval_name - if isinstance(env.model, Booster): - if ds_name == env.model._train_data_name: - return True + if isinstance(env.model, Booster) and ds_name == env.model._train_data_name: + return True return False