8000 [MRG] Deprecate utils.fixes.parallel_helper by NicolasHug · Pull Request #15224 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

[MRG] Deprecate utils.fixes.parallel_helper #15224

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions sklearn/ensemble/forest.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class calls the ``fit`` method of each sub-estimator on random samples
from ..utils import check_random_state, check_array, compute_sample_weight
from ..exceptions import DataConversionWarning
from .base import BaseEnsemble, _partition_estimators
from ..utils.fixes import parallel_helper, _joblib_parallel_args
from ..utils.fixes import _joblib_parallel_args
from ..utils.multiclass import check_classification_targets
from ..utils.validation import check_is_fitted

Expand Down Expand Up @@ -218,7 +218,7 @@ def apply(self, X):
X = self._validate_X_predict(X)
results = Parallel(n_jobs=self.n_jobs, verbose=self.verbose,
**_joblib_parallel_args(prefer="threads"))(
delayed(parallel_helper)(tree, 'apply', X, check_input=False)
delayed(tree.apply)(X, check_input=False)
for tree in self.estimators_)

return np.array(results).T
Expand Down Expand Up @@ -249,8 +249,7 @@ def decision_path(self, X):
X = self._validate_X_predict(X)
indicators = Parallel(n_jobs=self.n_jobs, verbose=self.verbose,
**_joblib_parallel_args(prefer='threads'))(
delayed(parallel_helper)(tree, 'decision_path', X,
check_input=False)
delayed(tree.decision_path)(X, check_input=False)
for tree in self.estimators_)

n_nodes = [0]
Expand Down
3 changes: 1 addition & 2 deletions sklearn/multioutput.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
from .base import RegressorMixin, ClassifierMixin, is_classifier
from .model_selection import cross_val_predict
from .utils import check_array, check_X_y, check_random_state
from .utils.fixes import parallel_helper
from .utils.metaestimators import if_delegate_has_method
from .utils.validation import check_is_fitted, has_fit_parameter
from .utils.multiclass import check_classification_targets
Expand Down Expand Up @@ -193,7 +192,7 @@ def predict(self, X):
X = check_array(X, accept_sparse=True)

y = Parallel(n_jobs=self.n_jobs)(
delayed(parallel_helper)(e, 'predict', X)
delayed(e.predict)(X)
for e in self.estimators_)

return np.asarray(y).T
Expand Down
10 changes: 10 additions & 0 deletions sklearn/utils/fixes.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import scipy.stats
from scipy.sparse.linalg import lsqr as sparse_lsqr # noqa

from . import deprecated


def _parse_version(version_string):
version = []
Expand Down Expand Up @@ -155,7 +157,15 @@ def _argmax(arr_or_matrix, axis=None):
return arr_or_matrix.argmax(axis=axis)


# TODO: remove in 0.24
@deprecated("parallel_helper is deprecated in version "
"0.22 and will be removed in version 0.24.")
def parallel_helper(obj, methodname, *args, **kwargs):
return _parallel_helper(obj, methodname, *args, **kwargs)


# TODO: remove in 0.24. It isn't used anywhere
def _parallel_helper(obj, methodname, *args, **kwargs):
"""Workaround for Python 2 limitations of pickling instance methods

Parameters
Expand Down
7 changes: 7 additions & 0 deletions sklearn/utils/tests/test_deprecated_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from sklearn.utils.optimize import newton_cg
from sklearn.utils.random import random_choice_csc
from sklearn.utils import safe_indexing
from sklearn.utils.fixes import parallel_helper


# This file tests the utils that are deprecated
Expand Down Expand Up @@ -85,3 +86,9 @@ def test_random_choice_csc():
def test_safe_indexing():
with pytest.warns(DeprecationWarning, match="removed in version 0.24"):
safe_indexing([1, 2], 0)


# TODO: remove in 0.24
def test_parallel_helper():
with pytest.warns(DeprecationWarning, match="removed in version 0.24"):
parallel_helper(list(), 'append', 2)
0