Use nonlocal instead of container
@@ -643,7 +643,7 @@ class BaseSearchCV(BaseEstimator, MetaEstimatorMixin, metaclass=ABCMeta):
return_parameters=False,
error_score=self.error_score,
verbose=self.verbose)
- results_container = [{}]
+ results = {}
with parallel:
all_candidate_params = []
all_out = []
@@ -680,16 +680,13 @@ class BaseSearchCV(BaseEstimator, MetaEstimatorMixin, metaclass=ABCMeta):
all_candidate_params.extend(candidate_params)
all_out.extend(out)
- # XXX: When we drop Python 2 support, we can use nonlocal
- # instead of results_container
- results_container[0] = self._format_results(
+ nonlocal results
+ results = self._format_results(
all_candidate_params, scorers, n_splits, all_out)
- return results_container[0]
+ return results
self._run_search(evaluate_candidates)
- results = results_container[0]
-
# For multi-metric evaluation, store the best_index_, best_params_ and
# best_score_ iff refit is one of the scorer names
# In single metric evaluation, refit_metric is "score"
