Unverified Commit 4162485d authored by James Lamb's avatar James Lamb Committed by GitHub
Browse files

[python-package] fix mypy errors about callbacks (#5450)

* [python-package] fix mypy errors about callbacks

* revert unnecessary import
parent 18352475
...@@ -685,14 +685,14 @@ def cv( ...@@ -685,14 +685,14 @@ def cv(
# setup callbacks # setup callbacks
if callbacks is None: if callbacks is None:
callbacks = set() callbacks_set = set()
else: else:
for i, cb in enumerate(callbacks): for i, cb in enumerate(callbacks):
cb.__dict__.setdefault('order', i - len(callbacks)) cb.__dict__.setdefault('order', i - len(callbacks))
callbacks = set(callbacks) callbacks_set = set(callbacks)
if "early_stopping_round" in params: if "early_stopping_round" in params:
callbacks.add( callbacks_set.add(
callback.early_stopping( callback.early_stopping(
stopping_rounds=params["early_stopping_round"], stopping_rounds=params["early_stopping_round"],
first_metric_only=first_metric_only, first_metric_only=first_metric_only,
...@@ -704,10 +704,10 @@ def cv( ...@@ -704,10 +704,10 @@ def cv(
) )
) )
callbacks_before_iter = {cb for cb in callbacks if getattr(cb, 'before_iteration', False)} callbacks_before_iter_set = {cb for cb in callbacks_set if getattr(cb, 'before_iteration', False)}
callbacks_after_iter = callbacks - callbacks_before_iter callbacks_after_iter_set = callbacks_set - callbacks_before_iter_set
callbacks_before_iter = sorted(callbacks_before_iter, key=attrgetter('order')) callbacks_before_iter = sorted(callbacks_before_iter_set, key=attrgetter('order'))
callbacks_after_iter = sorted(callbacks_after_iter, key=attrgetter('order')) callbacks_after_iter = sorted(callbacks_after_iter_set, key=attrgetter('order'))
for i in range(num_boost_round): for i in range(num_boost_round):
for cb in callbacks_before_iter: for cb in callbacks_before_iter:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment