From 9685cddff9d2ec1ff3fdbd3b3cfcbfbd54828f3d Mon Sep 17 00:00:00 2001 From: Roman Yurchak Date: Thu, 18 Apr 2019 16:48:56 +0200 Subject: [PATCH 1/3] Remove sklearn.utils._joblib imports --- sklearn/cluster/k_means_.py | 4 +--- sklearn/cluster/mean_shift_.py | 3 +-- sklearn/compose/_column_transformer.py | 2 +- sklearn/covariance/graph_lasso_.py | 2 +- sklearn/datasets/california_housing.py | 7 ++++--- sklearn/datasets/covtype.py | 10 +++++----- sklearn/datasets/kddcup99.py | 11 +++++------ sklearn/datasets/lfw.py | 8 ++++---- sklearn/datasets/olivetti_faces.py | 6 +++--- sklearn/datasets/rcv1.py | 18 +++++++++--------- sklearn/datasets/species_distributions.py | 2 +- sklearn/datasets/twenty_newsgroups.py | 6 +++--- sklearn/decomposition/dict_learning.py | 2 +- sklearn/decomposition/online_lda.py | 2 +- sklearn/decomposition/tests/test_sparse_pca.py | 8 ++++---- sklearn/ensemble/bagging.py | 3 ++- sklearn/ensemble/base.py | 3 ++- sklearn/ensemble/forest.py | 2 +- sklearn/ensemble/partial_dependence.py | 2 +- sklearn/ensemble/tests/test_bagging.py | 4 ++-- sklearn/ensemble/tests/test_forest.py | 13 +++++-------- sklearn/ensemble/voting.py | 3 ++- sklearn/feature_selection/rfe.py | 3 ++- sklearn/linear_model/base.py | 2 +- sklearn/linear_model/coordinate_descent.py | 2 +- sklearn/linear_model/least_angle.py | 2 +- sklearn/linear_model/logistic.py | 2 +- sklearn/linear_model/omp.py | 2 +- sklearn/linear_model/stochastic_gradient.py | 2 +- sklearn/linear_model/tests/test_sgd.py | 8 +++----- sklearn/linear_model/theil_sen.py | 2 +- sklearn/manifold/mds.py | 4 +--- sklearn/metrics/pairwise.py | 4 +--- sklearn/metrics/tests/test_score_objects.py | 6 +++--- sklearn/model_selection/_search.py | 2 +- sklearn/model_selection/_validation.py | 3 +-- sklearn/multiclass.py | 3 +-- sklearn/multioutput.py | 3 ++- sklearn/neighbors/base.py | 8 ++++---- sklearn/neighbors/tests/test_kde.py | 6 +++--- sklearn/neighbors/tests/test_neighbors.py | 5 ++--- sklearn/pipeline.py | 2 +- sklearn/tests/test_multioutput.py | 2 +- sklearn/tests/test_pipeline.py | 15 +++++++-------- sklearn/tests/test_site_joblib.py | 1 - sklearn/utils/estimator_checks.py | 6 +++--- sklearn/utils/fixes.py | 6 +++--- sklearn/utils/testing.py | 2 +- sklearn/utils/tests/test_estimator_checks.py | 10 +++++----- sklearn/utils/tests/test_fixes.py | 4 ++-- sklearn/utils/validation.py | 9 ++++----- 51 files changed, 117 insertions(+), 130 deletions(-) diff --git a/sklearn/cluster/k_means_.py b/sklearn/cluster/k_means_.py index 042e6990b5df1..8a77c701d759c 100644 --- a/sklearn/cluster/k_means_.py +++ b/sklearn/cluster/k_means_.py @@ -15,6 +15,7 @@ import numpy as np import scipy.sparse as sp +from joblib import Parallel, delayed, effective_n_jobs from ..base import BaseEstimator, ClusterMixin, TransformerMixin from ..metrics.pairwise import euclidean_distances @@ -28,9 +29,6 @@ from ..utils import check_random_state from ..utils.validation import check_is_fitted from ..utils.validation import FLOAT_DTYPES -from ..utils._joblib import Parallel -from ..utils._joblib import delayed -from ..utils._joblib import effective_n_jobs from ..exceptions import ConvergenceWarning from . import _k_means from ._k_means_elkan import k_means_elkan diff --git a/sklearn/cluster/mean_shift_.py b/sklearn/cluster/mean_shift_.py index ce5dac8b5a318..4fb631f9d8e2a 100644 --- a/sklearn/cluster/mean_shift_.py +++ b/sklearn/cluster/mean_shift_.py @@ -16,6 +16,7 @@ import numpy as np import warnings +from joblib import Parallel, delayed from collections import defaultdict from ..utils.validation import check_is_fitted @@ -23,8 +24,6 @@ from ..base import BaseEstimator, ClusterMixin from ..neighbors import NearestNeighbors from ..metrics.pairwise import pairwise_distances_argmin -from ..utils._joblib import Parallel -from ..utils._joblib import delayed def estimate_bandwidth(X, quantile=0.3, n_samples=None, random_state=0, diff --git a/sklearn/compose/_column_transformer.py b/sklearn/compose/_column_transformer.py index 466a88bee7b80..b26cb0466dd46 100644 --- a/sklearn/compose/_column_transformer.py +++ b/sklearn/compose/_column_transformer.py @@ -12,9 +12,9 @@ import numpy as np import warnings from scipy import sparse +from joblib import Parallel, delayed from ..base import clone, TransformerMixin -from ..utils._joblib import Parallel, delayed from ..pipeline import _fit_transform_one, _transform_one, _name_estimators from ..preprocessing import FunctionTransformer from ..utils import Bunch diff --git a/sklearn/covariance/graph_lasso_.py b/sklearn/covariance/graph_lasso_.py index 35ead3fcd8210..e751c634f33b3 100644 --- a/sklearn/covariance/graph_lasso_.py +++ b/sklearn/covariance/graph_lasso_.py @@ -13,6 +13,7 @@ import numpy as np from scipy import linalg +from joblib import Parallel, delayed from .empirical_covariance_ import (empirical_covariance, EmpiricalCovariance, log_likelihood) @@ -23,7 +24,6 @@ from ..linear_model import cd_fast from ..linear_model import lars_path_gram from ..model_selection import check_cv, cross_val_score -from ..utils._joblib import Parallel, delayed # Helper functions to compute the objective and dual objective functions diff --git a/sklearn/datasets/california_housing.py b/sklearn/datasets/california_housing.py index 372d6e44f1b92..ed50abf0086a0 100644 --- a/sklearn/datasets/california_housing.py +++ b/sklearn/datasets/california_housing.py @@ -28,12 +28,13 @@ import numpy as np import logging +import joblib + from .base import get_data_home from .base import _fetch_remote from .base import _pkl_filepath from .base import RemoteFileMetadata from ..utils import Bunch -from ..utils import _joblib # The original data can be found at: # https://www.dcc.fc.up.pt/~ltorgo/Regression/cal_housing.tgz @@ -124,11 +125,11 @@ def fetch_california_housing(data_home=None, download_if_missing=True, columns_index = [8, 7, 2, 3, 4, 5, 6, 1, 0] cal_housing = cal_housing[:, columns_index] - _joblib.dump(cal_housing, filepath, compress=6) + joblib.dump(cal_housing, filepath, compress=6) remove(archive_path) else: - cal_housing = _joblib.load(filepath) + cal_housing = joblib.load(filepath) feature_names = ["MedInc", "HouseAge", "AveRooms", "AveBedrms", "Population", "AveOccup", "Latitude", "Longitude"] diff --git a/sklearn/datasets/covtype.py b/sklearn/datasets/covtype.py index 817abe52c5de4..9d995810bee3f 100644 --- a/sklearn/datasets/covtype.py +++ b/sklearn/datasets/covtype.py @@ -20,13 +20,13 @@ from os import remove, makedirs import numpy as np +import joblib from .base import get_data_home from .base import _fetch_remote from .base import RemoteFileMetadata from ..utils import Bunch from .base import _pkl_filepath -from ..utils import _joblib from ..utils import check_random_state # The original data can be found in: @@ -117,16 +117,16 @@ def fetch_covtype(data_home=None, download_if_missing=True, X = Xy[:, :-1] y = Xy[:, -1].astype(np.int32, copy=False) - _joblib.dump(X, samples_path, compress=9) - _joblib.dump(y, targets_path, compress=9) + joblib.dump(X, samples_path, compress=9) + joblib.dump(y, targets_path, compress=9) elif not available and not download_if_missing: raise IOError("Data not found and `download_if_missing` is False") try: X, y except NameError: - X = _joblib.load(samples_path) - y = _joblib.load(targets_path) + X = joblib.load(samples_path) + y = joblib.load(targets_path) if shuffle: ind = np.arange(X.shape[0]) diff --git a/sklearn/datasets/kddcup99.py b/sklearn/datasets/kddcup99.py index ccdb7b3ee3309..837a489e7212c 100644 --- a/sklearn/datasets/kddcup99.py +++ b/sklearn/datasets/kddcup99.py @@ -15,13 +15,12 @@ from os.path import dirname, exists, join import numpy as np - +import joblib from .base import _fetch_remote from .base import get_data_home from .base import RemoteFileMetadata from ..utils import Bunch -from ..utils import _joblib from ..utils import check_random_state from ..utils import shuffle as shuffle_method @@ -284,8 +283,8 @@ def _fetch_brute_kddcup99(data_home=None, # (error: 'Incorrect data length while decompressing[...] the file # could be corrupted.') - _joblib.dump(X, samples_path, compress=0) - _joblib.dump(y, targets_path, compress=0) + joblib.dump(X, samples_path, compress=0) + joblib.dump(y, targets_path, compress=0) elif not available: if not download_if_missing: raise IOError("Data not found and `download_if_missing` is False") @@ -293,8 +292,8 @@ def _fetch_brute_kddcup99(data_home=None, try: X, y except NameError: - X = _joblib.load(samples_path) - y = _joblib.load(targets_path) + X = joblib.load(samples_path) + y = joblib.load(targets_path) return Bunch(data=X, target=y) diff --git a/sklearn/datasets/lfw.py b/sklearn/datasets/lfw.py index 52f69bdb23498..0ec7855a6c23e 100644 --- a/sklearn/datasets/lfw.py +++ b/sklearn/datasets/lfw.py @@ -15,12 +15,12 @@ from distutils.version import LooseVersion import numpy as np +import joblib +from joblib import Memory from .base import get_data_home, _fetch_remote, RemoteFileMetadata from ..utils import deprecated from ..utils import Bunch -from ..utils._joblib import Memory -from ..utils import _joblib logger = logging.getLogger(__name__) @@ -327,7 +327,7 @@ def fetch_lfw_people(data_home=None, funneled=True, resize=0.5, # wrap the loader in a memoizing function that will return memmaped data # arrays for optimal memory usage - if LooseVersion(_joblib.__version__) < LooseVersion('0.12'): + if LooseVersion(joblib.__version__) < LooseVersion('0.12'): # Deal with change of API in joblib m = Memory(cachedir=lfw_home, compress=6, verbose=0) else: @@ -498,7 +498,7 @@ def fetch_lfw_pairs(subset='train', data_home=None, funneled=True, resize=0.5, # wrap the loader in a memoizing function that will return memmaped data # arrays for optimal memory usage - if LooseVersion(_joblib.__version__) < LooseVersion('0.12'): + if LooseVersion(joblib.__version__) < LooseVersion('0.12'): # Deal with change of API in joblib m = Memory(cachedir=lfw_home, compress=6, verbose=0) else: diff --git a/sklearn/datasets/olivetti_faces.py b/sklearn/datasets/olivetti_faces.py index 56ad057cdd0dd..a52f90414e104 100644 --- a/sklearn/datasets/olivetti_faces.py +++ b/sklearn/datasets/olivetti_faces.py @@ -18,12 +18,12 @@ import numpy as np from scipy.io.matlab import loadmat +import joblib from .base import get_data_home from .base import _fetch_remote from .base import RemoteFileMetadata from .base import _pkl_filepath -from ..utils import _joblib from ..utils import check_random_state, Bunch # The original data can be found at: @@ -104,10 +104,10 @@ def fetch_olivetti_faces(data_home=None, shuffle=False, random_state=0, remove(mat_path) faces = mfile['faces'].T.copy() - _joblib.dump(faces, filepath, compress=6) + joblib.dump(faces, filepath, compress=6) del mfile else: - faces = _joblib.load(filepath) + faces = joblib.load(filepath) # We want floating point data, but float32 is enough (there is only # one byte of precision in the original uint8s anyway) diff --git a/sklearn/datasets/rcv1.py b/sklearn/datasets/rcv1.py index 8d29f7a40c9eb..c95cf1d1be75a 100644 --- a/sklearn/datasets/rcv1.py +++ b/sklearn/datasets/rcv1.py @@ -16,12 +16,12 @@ import numpy as np import scipy.sparse as sp +import joblib from .base import get_data_home from .base import _pkl_filepath from .base import _fetch_remote from .base import RemoteFileMetadata -from ..utils import _joblib from .svmlight_format import load_svmlight_files from ..utils import shuffle as shuffle_ from ..utils import Bunch @@ -181,16 +181,16 @@ def fetch_rcv1(data_home=None, subset='all', download_if_missing=True, sample_id = np.hstack((Xy[9], Xy[1], Xy[3], Xy[5], Xy[7])) sample_id = sample_id.astype(np.uint32, copy=False) - _joblib.dump(X, samples_path, compress=9) - _joblib.dump(sample_id, sample_id_path, compress=9) + joblib.dump(X, samples_path, compress=9) + joblib.dump(sample_id, sample_id_path, compress=9) # delete archives for f in files: f.close() remove(f.name) else: - X = _joblib.load(samples_path) - sample_id = _joblib.load(sample_id_path) + X = joblib.load(samples_path) + sample_id = joblib.load(sample_id_path) # load target (y), categories, and sample_id_bis if download_if_missing and (not exists(sample_topics_path) or @@ -240,11 +240,11 @@ def fetch_rcv1(data_home=None, subset='all', download_if_missing=True, categories = categories[order] y = sp.csr_matrix(y[:, order]) - _joblib.dump(y, sample_topics_path, compress=9) - _joblib.dump(categories, topics_path, compress=9) + joblib.dump(y, sample_topics_path, compress=9) + joblib.dump(categories, topics_path, compress=9) else: - y = _joblib.load(sample_topics_path) - categories = _joblib.load(topics_path) + y = joblib.load(sample_topics_path) + categories = joblib.load(topics_path) if subset == 'all': pass diff --git a/sklearn/datasets/species_distributions.py b/sklearn/datasets/species_distributions.py index 34e8251f9551f..3b318644dd498 100644 --- a/sklearn/datasets/species_distributions.py +++ b/sklearn/datasets/species_distributions.py @@ -44,13 +44,13 @@ import logging import numpy as np +import joblib from .base import get_data_home from .base import _fetch_remote from .base import RemoteFileMetadata from ..utils import Bunch from .base import _pkl_filepath -from ..utils import _joblib # The original data can be found at: # https://biodiversityinformatics.amnh.org/open_source/maxent/samples.zip diff --git a/sklearn/datasets/twenty_newsgroups.py b/sklearn/datasets/twenty_newsgroups.py index dd47d9962c42f..fe58e5c42e1dc 100644 --- a/sklearn/datasets/twenty_newsgroups.py +++ b/sklearn/datasets/twenty_newsgroups.py @@ -35,6 +35,7 @@ import numpy as np import scipy.sparse as sp +import joblib from .base import get_data_home from .base import load_files @@ -44,7 +45,6 @@ from ..feature_extraction.text import CountVectorizer from ..preprocessing import normalize from ..utils import deprecated -from ..utils import _joblib from ..utils import check_random_state, Bunch logger = logging.getLogger(__name__) @@ -406,12 +406,12 @@ def fetch_20newsgroups_vectorized(subset="train", remove=(), data_home=None, download_if_missing=download_if_missing) if os.path.exists(target_file): - X_train, X_test = _joblib.load(target_file) + X_train, X_test = joblib.load(target_file) else: vectorizer = CountVectorizer(dtype=np.int16) X_train = vectorizer.fit_transform(data_train.data).tocsr() X_test = vectorizer.transform(data_test.data).tocsr() - _joblib.dump((X_train, X_test), target_file, compress=9) + joblib.dump((X_train, X_test), target_file, compress=9) # the data is stored as int16 for compactness # but normalize needs floats diff --git a/sklearn/decomposition/dict_learning.py b/sklearn/decomposition/dict_learning.py index ef823272e0e8f..72f5a20fcd20d 100644 --- a/sklearn/decomposition/dict_learning.py +++ b/sklearn/decomposition/dict_learning.py @@ -11,9 +11,9 @@ import numpy as np from scipy import linalg +from joblib import Parallel, delayed, effective_n_jobs from ..base import BaseEstimator, TransformerMixin -from ..utils._joblib import Parallel, delayed, effective_n_jobs from ..utils import (check_array, check_random_state, gen_even_slices, gen_batches) from ..utils.extmath import randomized_svd, row_norms diff --git a/sklearn/decomposition/online_lda.py b/sklearn/decomposition/online_lda.py index 1c8933d2b719d..362cb12568ad5 100644 --- a/sklearn/decomposition/online_lda.py +++ b/sklearn/decomposition/online_lda.py @@ -14,13 +14,13 @@ import numpy as np import scipy.sparse as sp from scipy.special import gammaln +from joblib import Parallel, delayed, effective_n_jobs from ..base import BaseEstimator, TransformerMixin from ..utils import (check_random_state, check_array, gen_batches, gen_even_slices) from ..utils.fixes import logsumexp from ..utils.validation import check_non_negative -from ..utils._joblib import Parallel, delayed, effective_n_jobs from ..exceptions import NotFittedError from ._online_lda import (mean_change, _dirichlet_expectation_1d, diff --git a/sklearn/decomposition/tests/test_sparse_pca.py b/sklearn/decomposition/tests/test_sparse_pca.py index 019e2a32ee0c1..81477cdb8cc2a 100644 --- a/sklearn/decomposition/tests/test_sparse_pca.py +++ b/sklearn/decomposition/tests/test_sparse_pca.py @@ -169,16 +169,16 @@ def test_mini_batch_fit_transform(norm_comp): U1 = spca_lars.transform(Y) # Test multiple CPUs if sys.platform == 'win32': # fake parallelism for win32 - import sklearn.utils._joblib.parallel as joblib_par - _mp = joblib_par.multiprocessing - joblib_par.multiprocessing = None + import joblib + _mp = joblib.parallel.multiprocessing + joblib.parallel.multiprocessing = None try: spca = MiniBatchSparsePCA(n_components=3, n_jobs=2, alpha=alpha, random_state=0, normalize_components=norm_comp) U2 = spca.fit(Y).transform(Y) finally: - joblib_par.multiprocessing = _mp + joblib.parallel.multiprocessing = _mp else: # we can efficiently use parallelism spca = MiniBatchSparsePCA(n_components=3, n_jobs=2, alpha=alpha, random_state=0, diff --git a/sklearn/ensemble/bagging.py b/sklearn/ensemble/bagging.py index f21fbd81b9a8c..3ab06f38fec86 100644 --- a/sklearn/ensemble/bagging.py +++ b/sklearn/ensemble/bagging.py @@ -10,9 +10,10 @@ from abc import ABCMeta, abstractmethod from warnings import warn +from joblib import Parallel, delayed + from .base import BaseEnsemble, _partition_estimators from ..base import ClassifierMixin, RegressorMixin -from ..utils._joblib import Parallel, delayed from ..metrics import r2_score, accuracy_score from ..tree import DecisionTreeClassifier, DecisionTreeRegressor from ..utils import check_random_state, check_X_y, check_array, column_or_1d diff --git a/sklearn/ensemble/base.py b/sklearn/ensemble/base.py index 7ac1dd4f72613..7457b8b9e1f77 100644 --- a/sklearn/ensemble/base.py +++ b/sklearn/ensemble/base.py @@ -8,11 +8,12 @@ import numpy as np import numbers +from joblib import effective_n_jobs + from ..base import clone from ..base import BaseEstimator from ..base import MetaEstimatorMixin from ..utils import check_random_state -from ..utils._joblib import effective_n_jobs from abc import ABCMeta, abstractmethod MAX_RAND_SEED = np.iinfo(np.int32).max diff --git a/sklearn/ensemble/forest.py b/sklearn/ensemble/forest.py index 2767fefd177c3..628e39d87cee0 100644 --- a/sklearn/ensemble/forest.py +++ b/sklearn/ensemble/forest.py @@ -47,9 +47,9 @@ class calls the ``fit`` method of each sub-estimator on random samples import numpy as np from scipy.sparse import issparse from scipy.sparse import hstack as sparse_hstack +from joblib import Parallel, delayed from ..base import ClassifierMixin, RegressorMixin, MultiOutputMixin -from ..utils._joblib import Parallel, delayed from ..metrics import r2_score from ..preprocessing import OneHotEncoder from ..tree import (DecisionTreeClassifier, DecisionTreeRegressor, diff --git a/sklearn/ensemble/partial_dependence.py b/sklearn/ensemble/partial_dependence.py index 9460b29184df7..a24aabb20ca93 100644 --- a/sklearn/ensemble/partial_dependence.py +++ b/sklearn/ensemble/partial_dependence.py @@ -8,9 +8,9 @@ import numpy as np from scipy.stats.mstats import mquantiles +from joblib import Parallel, delayed from ..utils.extmath import cartesian -from ..utils._joblib import Parallel, delayed from ..utils import check_array from ..utils.validation import check_is_fitted from ..tree._tree import DTYPE diff --git a/sklearn/ensemble/tests/test_bagging.py b/sklearn/ensemble/tests/test_bagging.py index 66eb52e7ac930..34e77979477bd 100644 --- a/sklearn/ensemble/tests/test_bagging.py +++ b/sklearn/ensemble/tests/test_bagging.py @@ -7,6 +7,7 @@ import pytest import numpy as np +import joblib from sklearn.base import BaseEstimator @@ -33,7 +34,6 @@ from sklearn.model_selection import train_test_split from sklearn.datasets import load_boston, load_iris, make_hastie_10_2 from sklearn.utils import check_random_state -from sklearn.utils import _joblib from sklearn.preprocessing import FunctionTransformer from scipy.sparse import csc_matrix, csr_matrix @@ -226,7 +226,7 @@ class DummySizeEstimator(BaseEstimator): def fit(self, X, y): self.training_size_ = X.shape[0] - self.training_hash_ = _joblib.hash(X) + self.training_hash_ = joblib.hash(X) def test_bootstrap_samples(): diff --git a/sklearn/ensemble/tests/test_forest.py b/sklearn/ensemble/tests/test_forest.py index 5ea72374751b4..b6df74c3f658e 100644 --- a/sklearn/ensemble/tests/test_forest.py +++ b/sklearn/ensemble/tests/test_forest.py @@ -23,10 +23,7 @@ import pytest -from sklearn.utils._joblib import joblib -from sklearn.utils._joblib import parallel_backend -from sklearn.utils._joblib import register_parallel_backend -from sklearn.utils._joblib import __version__ as __joblib_version__ +import joblib from sklearn.utils.testing import assert_almost_equal from sklearn.utils.testing import assert_array_almost_equal @@ -1320,22 +1317,22 @@ def start_call(self): return super().start_call() -register_parallel_backend('testing', MyBackend) +joblib.register_parallel_backend('testing', MyBackend) -@pytest.mark.skipif(__joblib_version__ < LooseVersion('0.12'), +@pytest.mark.skipif(joblib.__version__ < LooseVersion('0.12'), reason='tests not yet supported in joblib <0.12') @skip_if_no_parallel def test_backend_respected(): clf = RandomForestClassifier(n_estimators=10, n_jobs=2) - with parallel_backend("testing") as (ba, n_jobs): + with joblib.parallel_backend("testing") as (ba, n_jobs): clf.fit(X, y) assert ba.count > 0 # predict_proba requires shared memory. Ensure that's honored. - with parallel_backend("testing") as (ba, _): + with joblib.parallel_backend("testing") as (ba, _): clf.predict_proba(X) assert ba.count == 0 diff --git a/sklearn/ensemble/voting.py b/sklearn/ensemble/voting.py index 35821201b6617..44b99c19ac860 100644 --- a/sklearn/ensemble/voting.py +++ b/sklearn/ensemble/voting.py @@ -16,12 +16,13 @@ import numpy as np from abc import abstractmethod +from joblib import Parallel, delayed + from ..base import ClassifierMixin from ..base import RegressorMixin from ..base import TransformerMixin from ..base import clone from ..preprocessing import LabelEncoder -from ..utils._joblib import Parallel, delayed from ..utils.validation import has_fit_parameter, check_is_fitted from ..utils.metaestimators import _BaseComposition from ..utils import Bunch diff --git a/sklearn/feature_selection/rfe.py b/sklearn/feature_selection/rfe.py index 89a23bbb6cd16..eda3ecf916f89 100644 --- a/sklearn/feature_selection/rfe.py +++ b/sklearn/feature_selection/rfe.py @@ -7,6 +7,8 @@ """Recursive feature elimination for feature ranking""" import numpy as np +from joblib import Parallel, delayed, effective_n_jobs + from ..utils import check_X_y, safe_sqr from ..utils.metaestimators import if_delegate_has_method from ..utils.metaestimators import _safe_split @@ -15,7 +17,6 @@ from ..base import MetaEstimatorMixin from ..base import clone from ..base import is_classifier -from ..utils._joblib import Parallel, delayed, effective_n_jobs from ..model_selection import check_cv from ..model_selection._validation import _score from ..metrics.scorer import check_scoring diff --git a/sklearn/linear_model/base.py b/sklearn/linear_model/base.py index 54083fee1e904..06f16f2522c86 100644 --- a/sklearn/linear_model/base.py +++ b/sklearn/linear_model/base.py @@ -22,8 +22,8 @@ from scipy import linalg from scipy import sparse from scipy.special import expit +from joblib import Parallel, delayed -from ..utils._joblib import Parallel, delayed from ..base import (BaseEstimator, ClassifierMixin, RegressorMixin, MultiOutputMixin) from ..utils import check_array, check_X_y diff --git a/sklearn/linear_model/coordinate_descent.py b/sklearn/linear_model/coordinate_descent.py index ceccafd706101..a0b2513595061 100644 --- a/sklearn/linear_model/coordinate_descent.py +++ b/sklearn/linear_model/coordinate_descent.py @@ -11,6 +11,7 @@ import numpy as np from scipy import sparse +from joblib import Parallel, delayed, effective_n_jobs from .base import LinearModel, _pre_fit from ..base import RegressorMixin, MultiOutputMixin @@ -18,7 +19,6 @@ from ..utils import check_array, check_X_y from ..utils.validation import check_random_state from ..model_selection import check_cv -from ..utils._joblib import Parallel, delayed, effective_n_jobs from ..utils.extmath import safe_sparse_dot from ..utils.fixes import _joblib_parallel_args from ..utils.validation import check_is_fitted diff --git a/sklearn/linear_model/least_angle.py b/sklearn/linear_model/least_angle.py index 5df45535db462..e529508a9b423 100644 --- a/sklearn/linear_model/least_angle.py +++ b/sklearn/linear_model/least_angle.py @@ -15,13 +15,13 @@ import numpy as np from scipy import linalg, interpolate from scipy.linalg.lapack import get_lapack_funcs +from joblib import Parallel, delayed from .base import LinearModel from ..base import RegressorMixin, MultiOutputMixin from ..utils import arrayfuncs, as_float_array, check_X_y from ..model_selection import check_cv from ..exceptions import ConvergenceWarning -from ..utils._joblib import Parallel, delayed SOLVE_TRIANGULAR_ARGS = {'check_finite': False} diff --git a/sklearn/linear_model/logistic.py b/sklearn/linear_model/logistic.py index be664d5b5c087..a332f97296304 100644 --- a/sklearn/linear_model/logistic.py +++ b/sklearn/linear_model/logistic.py @@ -16,6 +16,7 @@ import numpy as np from scipy import optimize, sparse from scipy.special import expit +from joblib import Parallel, delayed, effective_n_jobs from .base import LinearClassifierMixin, SparseCoefMixin, BaseEstimator from .sag import sag_solver @@ -33,7 +34,6 @@ from ..exceptions import (NotFittedError, ConvergenceWarning, ChangedBehaviorWarning) from ..utils.multiclass import check_classification_targets -from ..utils._joblib import Parallel, delayed, effective_n_jobs from ..utils.fixes import _joblib_parallel_args from ..model_selection import check_cv from ..metrics import get_scorer diff --git a/sklearn/linear_model/omp.py b/sklearn/linear_model/omp.py index d9ee49cd37698..6ad3b922a26ce 100644 --- a/sklearn/linear_model/omp.py +++ b/sklearn/linear_model/omp.py @@ -11,12 +11,12 @@ import numpy as np from scipy import linalg from scipy.linalg.lapack import get_lapack_funcs +from joblib import Parallel, delayed from .base import LinearModel, _pre_fit from ..base import RegressorMixin, MultiOutputMixin from ..utils import as_float_array, check_array, check_X_y from ..model_selection import check_cv -from ..utils._joblib import Parallel, delayed premature = """ Orthogonal matching pursuit ended prematurely due to linear dependence in the dictionary. The requested precision might not have been met. diff --git a/sklearn/linear_model/stochastic_gradient.py b/sklearn/linear_model/stochastic_gradient.py index e7aa203b7f7d2..d8f43af764b90 100644 --- a/sklearn/linear_model/stochastic_gradient.py +++ b/sklearn/linear_model/stochastic_gradient.py @@ -9,7 +9,7 @@ from abc import ABCMeta, abstractmethod -from ..utils._joblib import Parallel, delayed +from joblib import Parallel, delayed from ..base import clone, is_classifier from .base import LinearClassifierMixin, SparseCoefMixin diff --git a/sklearn/linear_model/tests/test_sgd.py b/sklearn/linear_model/tests/test_sgd.py index 29a2218e5942f..b5bf59bda87b0 100644 --- a/sklearn/linear_model/tests/test_sgd.py +++ b/sklearn/linear_model/tests/test_sgd.py @@ -4,6 +4,7 @@ import numpy as np import scipy.sparse as sp +import joblib from sklearn.utils.testing import assert_array_equal from sklearn.utils.testing import assert_almost_equal @@ -27,9 +28,6 @@ from sklearn.linear_model import sgd_fast from sklearn.model_selection import RandomizedSearchCV -from sklearn.utils import _joblib -from sklearn.utils._joblib import parallel_backend - # 0.23. warning about tol not having its correct default value. pytestmark = pytest.mark.filterwarnings( @@ -1596,7 +1594,7 @@ def test_SGDClassifier_fit_for_all_backends(backend): # a segmentation fault when trying to write in a readonly memory mapped # buffer. - if _joblib.__version__ < LooseVersion('0.12') and backend == 'loky': + if joblib.__version__ < LooseVersion('0.12') and backend == 'loky': pytest.skip('loky backend does not exist in joblib <0.12') random_state = np.random.RandomState(42) @@ -1617,6 +1615,6 @@ def test_SGDClassifier_fit_for_all_backends(backend): # coefficients are equal to those obtained using a sequential fit clf_parallel = SGDClassifier(tol=1e-3, max_iter=1000, n_jobs=4, random_state=42) - with parallel_backend(backend=backend): + with joblib.parallel_backend(backend=backend): clf_parallel.fit(X, y) assert_array_almost_equal(clf_sequential.coef_, clf_parallel.coef_) diff --git a/sklearn/linear_model/theil_sen.py b/sklearn/linear_model/theil_sen.py index b1842eba06640..5d45cad61d673 100644 --- a/sklearn/linear_model/theil_sen.py +++ b/sklearn/linear_model/theil_sen.py @@ -15,12 +15,12 @@ from scipy import linalg from scipy.special import binom from scipy.linalg.lapack import get_lapack_funcs +from joblib import Parallel, delayed, effective_n_jobs from .base import LinearModel from ..base import RegressorMixin from ..utils import check_random_state from ..utils import check_X_y -from ..utils._joblib import Parallel, delayed, effective_n_jobs from ..exceptions import ConvergenceWarning _EPSILON = np.finfo(np.double).eps diff --git a/sklearn/manifold/mds.py b/sklearn/manifold/mds.py index afe8aecfc4f59..5238c67e93dfd 100644 --- a/sklearn/manifold/mds.py +++ b/sklearn/manifold/mds.py @@ -6,15 +6,13 @@ # License: BSD import numpy as np +from joblib import Parallel, delayed, effective_n_jobs import warnings from ..base import BaseEstimator from ..metrics import euclidean_distances from ..utils import check_random_state, check_array, check_symmetric -from ..utils._joblib import Parallel -from ..utils._joblib import delayed -from ..utils._joblib import effective_n_jobs from ..isotonic import IsotonicRegression diff --git a/sklearn/metrics/pairwise.py b/sklearn/metrics/pairwise.py index 315e3c8460b06..6539aa1d89ba2 100644 --- a/sklearn/metrics/pairwise.py +++ b/sklearn/metrics/pairwise.py @@ -17,6 +17,7 @@ from scipy.spatial import distance from scipy.sparse import csr_matrix from scipy.sparse import issparse +from joblib import Parallel, delayed, effective_n_jobs from ..utils.validation import _num_samples from ..utils.validation import check_non_negative @@ -25,9 +26,6 @@ from ..utils import gen_batches, get_chunk_n_rows from ..utils.extmath import row_norms, safe_sparse_dot from ..preprocessing import normalize -from ..utils._joblib import Parallel -from ..utils._joblib import delayed -from ..utils._joblib import effective_n_jobs from .pairwise_fast import _chi2_kernel_fast, _sparse_manhattan diff --git a/sklearn/metrics/tests/test_score_objects.py b/sklearn/metrics/tests/test_score_objects.py index ab99ec0c163c7..40ff5f6494c85 100644 --- a/sklearn/metrics/tests/test_score_objects.py +++ b/sklearn/metrics/tests/test_score_objects.py @@ -6,6 +6,7 @@ import numpy as np import pytest +import joblib from sklearn.utils.testing import assert_almost_equal from sklearn.utils.testing import assert_array_equal @@ -37,7 +38,6 @@ from sklearn.model_selection import train_test_split, cross_val_score from sklearn.model_selection import GridSearchCV from sklearn.multiclass import OneVsRestClassifier -from sklearn.utils import _joblib REGRESSION_SCORERS = ['explained_variance', 'r2', @@ -99,8 +99,8 @@ def setup_module(): _, y_ml = make_multilabel_classification(n_samples=X.shape[0], random_state=0) filename = os.path.join(TEMP_FOLDER, 'test_data.pkl') - _joblib.dump((X, y, y_ml), filename) - X_mm, y_mm, y_ml_mm = _joblib.load(filename, mmap_mode='r') + joblib.dump((X, y, y_ml), filename) + X_mm, y_mm, y_ml_mm = joblib.load(filename, mmap_mode='r') ESTIMATORS = _make_estimators(X_mm, y_mm, y_ml_mm) diff --git a/sklearn/model_selection/_search.py b/sklearn/model_selection/_search.py index 68f0e296b077c..9a5924b4f4326 100644 --- a/sklearn/model_selection/_search.py +++ b/sklearn/model_selection/_search.py @@ -28,7 +28,7 @@ from ._validation import _fit_and_score from ._validation import _aggregate_score_dicts from ..exceptions import NotFittedError -from ..utils._joblib import Parallel, delayed +from joblib import Parallel, delayed from ..utils import check_random_state from ..utils.fixes import MaskedArray from ..utils.random import sample_without_replacement diff --git a/sklearn/model_selection/_validation.py b/sklearn/model_selection/_validation.py index 77c8d651296a9..a2a5d32284fa0 100644 --- a/sklearn/model_selection/_validation.py +++ b/sklearn/model_selection/_validation.py @@ -22,8 +22,7 @@ from ..utils import indexable, check_random_state, safe_indexing from ..utils.validation import _is_arraylike, _num_samples from ..utils.metaestimators import _safe_split -from ..utils._joblib import Parallel, delayed -from ..utils._joblib import logger +from joblib import Parallel, delayed, logger from ..metrics.scorer import check_scoring, _check_multimetric_scoring from ..exceptions import FitFailedWarning from ._split import check_cv diff --git a/sklearn/multiclass.py b/sklearn/multiclass.py index 1cf80f8142f29..1c387f9634509 100644 --- a/sklearn/multiclass.py +++ b/sklearn/multiclass.py @@ -53,8 +53,7 @@ _ovr_decision_function) from .utils.metaestimators import _safe_split, if_delegate_has_method -from .utils._joblib import Parallel -from .utils._joblib import delayed +from joblib import Parallel, delayed __all__ = [ "OneVsRestClassifier", diff --git a/sklearn/multioutput.py b/sklearn/multioutput.py index 0da22e5e570d7..fc09ac7a25571 100644 --- a/sklearn/multioutput.py +++ b/sklearn/multioutput.py @@ -16,6 +16,8 @@ import numpy as np import scipy.sparse as sp +from joblib import Parallel, delayed + from abc import ABCMeta, abstractmethod from .base import BaseEstimator, clone, MetaEstimatorMixin from .base import RegressorMixin, ClassifierMixin, is_classifier @@ -25,7 +27,6 @@ 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 -from .utils._joblib import Parallel, delayed __all__ = ["MultiOutputRegressor", "MultiOutputClassifier", "ClassifierChain", "RegressorChain"] diff --git a/sklearn/neighbors/base.py b/sklearn/neighbors/base.py index f3d2e352a4a09..3e75ae88a6a49 100644 --- a/sklearn/neighbors/base.py +++ b/sklearn/neighbors/base.py @@ -14,6 +14,8 @@ import numpy as np from scipy.sparse import csr_matrix, issparse +import joblib +from joblib import Parallel, delayed, effective_n_jobs from .ball_tree import BallTree from .kd_tree import KDTree @@ -24,8 +26,6 @@ from ..utils.multiclass import check_classification_targets from ..utils.validation import check_is_fitted from ..exceptions import DataConversionWarning -from ..utils._joblib import Parallel, delayed, effective_n_jobs -from ..utils._joblib import __version__ as joblib_version VALID_METRICS = dict(ball_tree=BallTree.valid_metrics, kd_tree=KDTree.valid_metrics, @@ -437,7 +437,7 @@ class from an array representing our data set and ask who's raise ValueError( "%s does not work with sparse matrices. Densify the data, " "or set algorithm='brute'" % self._fit_method) - old_joblib = LooseVersion(joblib_version) < LooseVersion('0.12') + old_joblib = LooseVersion(joblib.__version__) < LooseVersion('0.12') if old_joblib: # Deal with change of API in joblib check_pickle = False if old_joblib else None @@ -733,7 +733,7 @@ class from an array representing our data set and ask who's "or set algorithm='brute'" % self._fit_method) n_jobs = effective_n_jobs(self.n_jobs) - if LooseVersion(joblib_version) < LooseVersion('0.12'): + if LooseVersion(joblib.__version__) < LooseVersion('0.12'): # Deal with change of API in joblib delayed_query = delayed(_tree_query_radius_parallel_helper, check_pickle=False) diff --git a/sklearn/neighbors/tests/test_kde.py b/sklearn/neighbors/tests/test_kde.py index 7d72c9f2cb8f2..e9a6c31bd1d5a 100644 --- a/sklearn/neighbors/tests/test_kde.py +++ b/sklearn/neighbors/tests/test_kde.py @@ -10,7 +10,7 @@ from sklearn.datasets import make_blobs from sklearn.model_selection import GridSearchCV from sklearn.preprocessing import StandardScaler -from sklearn.utils import _joblib +import joblib def compute_kernel_slow(Y, X, kernel, h): @@ -218,8 +218,8 @@ def test_pickling(tmpdir): scores = kde.score_samples(X) file_path = str(tmpdir.join('dump.pkl')) - _joblib.dump(kde, file_path) - kde = _joblib.load(file_path) + joblib.dump(kde, file_path) + kde = joblib.load(file_path) scores_pickled = kde.score_samples(X) assert_allclose(scores, scores_pickled) diff --git a/sklearn/neighbors/tests/test_neighbors.py b/sklearn/neighbors/tests/test_neighbors.py index 7072631fbea8a..9f51226490499 100644 --- a/sklearn/neighbors/tests/test_neighbors.py +++ b/sklearn/neighbors/tests/test_neighbors.py @@ -26,8 +26,7 @@ from sklearn.utils.testing import ignore_warnings from sklearn.utils.validation import check_random_state -from sklearn.utils._joblib import joblib -from sklearn.utils._joblib import parallel_backend +import joblib rng = np.random.RandomState(0) # load and shuffle iris dataset @@ -1327,7 +1326,7 @@ def test_same_radius_neighbors_parallel(algorithm): def test_knn_forcing_backend(backend, algorithm): # Non-regression test which ensure the knn methods are properly working # even when forcing the global joblib backend. - with parallel_backend(backend): + with joblib.parallel_backend(backend): X, y = datasets.make_classification(n_samples=30, n_features=5, n_redundant=0, random_state=0) X_train, X_test, y_train, y_test = train_test_split(X, y) diff --git a/sklearn/pipeline.py b/sklearn/pipeline.py index 6d046f8dda12e..988b79cfef99a 100644 --- a/sklearn/pipeline.py +++ b/sklearn/pipeline.py @@ -14,9 +14,9 @@ import numpy as np from scipy import sparse +from joblib import Parallel, delayed from .base import clone, TransformerMixin -from .utils._joblib import Parallel, delayed from .utils.metaestimators import if_delegate_has_method from .utils import Bunch from .utils.validation import check_memory diff --git a/sklearn/tests/test_multioutput.py b/sklearn/tests/test_multioutput.py index 05da5185deb54..ecf7f0aef0259 100644 --- a/sklearn/tests/test_multioutput.py +++ b/sklearn/tests/test_multioutput.py @@ -2,6 +2,7 @@ import pytest import numpy as np import scipy.sparse as sp +from joblib import cpu_count from sklearn.utils.testing import assert_almost_equal from sklearn.utils.testing import assert_raises @@ -17,7 +18,6 @@ from sklearn.datasets import make_classification from sklearn.ensemble import GradientBoostingRegressor, RandomForestClassifier from sklearn.exceptions import NotFittedError -from sklearn.utils._joblib import cpu_count from sklearn.linear_model import Lasso from sklearn.linear_model import LogisticRegression from sklearn.linear_model import Ridge diff --git a/sklearn/tests/test_pipeline.py b/sklearn/tests/test_pipeline.py index 3d76fb2b843c7..a670699243540 100644 --- a/sklearn/tests/test_pipeline.py +++ b/sklearn/tests/test_pipeline.py @@ -9,6 +9,7 @@ import pytest import numpy as np from scipy import sparse +import joblib from sklearn.utils.testing import assert_raises from sklearn.utils.testing import assert_raises_regex @@ -31,8 +32,6 @@ from sklearn.datasets import load_iris from sklearn.preprocessing import StandardScaler from sklearn.feature_extraction.text import CountVectorizer -from sklearn.utils._joblib import Memory -from sklearn.utils._joblib import __version__ as joblib_version JUNK_FOOD_DOCS = ( @@ -998,11 +997,11 @@ def test_pipeline_memory(): y = iris.target cachedir = mkdtemp() try: - if LooseVersion(joblib_version) < LooseVersion('0.12'): + if LooseVersion(joblib.__version__) < LooseVersion('0.12'): # Deal with change of API in joblib - memory = Memory(cachedir=cachedir, verbose=10) + memory = joblib.Memory(cachedir=cachedir, verbose=10) else: - memory = Memory(location=cachedir, verbose=10) + memory = joblib.Memory(location=cachedir, verbose=10) # Test with Transformer + SVC clf = SVC(gamma='scale', probability=True, random_state=0) transf = DummyTransf() @@ -1060,11 +1059,11 @@ def test_pipeline_memory(): def test_make_pipeline_memory(): cachedir = mkdtemp() - if LooseVersion(joblib_version) < LooseVersion('0.12'): + if LooseVersion(joblib.__version__) < LooseVersion('0.12'): # Deal with change of API in joblib - memory = Memory(cachedir=cachedir, verbose=10) + memory = joblib.Memory(cachedir=cachedir, verbose=10) else: - memory = Memory(location=cachedir, verbose=10) + memory = joblib.Memory(location=cachedir, verbose=10) pipeline = make_pipeline(DummyTransf(), SVC(), memory=memory) assert pipeline.memory is memory pipeline = make_pipeline(DummyTransf(), SVC()) diff --git a/sklearn/tests/test_site_joblib.py b/sklearn/tests/test_site_joblib.py index d2cd677a4b163..ef3506894ee42 100644 --- a/sklearn/tests/test_site_joblib.py +++ b/sklearn/tests/test_site_joblib.py @@ -1,6 +1,5 @@ import os import pytest -from sklearn.utils._joblib import Parallel, delayed, Memory, parallel_backend def test_old_pickle(tmpdir): diff --git a/sklearn/utils/estimator_checks.py b/sklearn/utils/estimator_checks.py index 26360c1ef07c1..28081836ec909 100644 --- a/sklearn/utils/estimator_checks.py +++ b/sklearn/utils/estimator_checks.py @@ -10,9 +10,9 @@ import numpy as np from scipy import sparse from scipy.stats import rankdata +import joblib from . import IS_PYPY -from . import _joblib from .testing import assert_raises, _get_args from .testing import assert_raises_regex from .testing import assert_raise_message @@ -2027,7 +2027,7 @@ def check_estimators_overwrite_params(name, estimator_orig): # The only exception to this rule of immutable constructor parameters # is possible RandomState instance but in this check we explicitly # fixed the random_state params recursively to be integer seeds. - assert_equal(_joblib.hash(new_value), _joblib.hash(original_value), + assert_equal(joblib.hash(new_value), joblib.hash(original_value), "Estimator %s should not change or mutate " " the parameter %s from %s to %s during fit." % (name, param_name, original_value, new_value)) @@ -2191,7 +2191,7 @@ def param_filter(p): else: assert_in(type(init_param.default), [str, int, float, bool, tuple, type(None), - np.float64, types.FunctionType, _joblib.Memory]) + np.float64, types.FunctionType, joblib.Memory]) if init_param.name not in params.keys(): # deprecated parameter, not in get_params assert init_param.default is None diff --git a/sklearn/utils/fixes.py b/sklearn/utils/fixes.py index 157f3fd8a9ebb..712b6826a2b75 100644 --- a/sklearn/utils/fixes.py +++ b/sklearn/utils/fixes.py @@ -218,15 +218,15 @@ def _joblib_parallel_args(**kwargs): See joblib.Parallel documentation for more details """ - from . import _joblib + import joblib - if _joblib.__version__ >= LooseVersion('0.12'): + if joblib.__version__ >= LooseVersion('0.12'): return kwargs extra_args = set(kwargs.keys()).difference({'prefer', 'require'}) if extra_args: raise NotImplementedError('unhandled arguments %s with joblib %s' - % (list(extra_args), _joblib.__version__)) + % (list(extra_args), joblib.__version__)) args = {} if 'prefer' in kwargs: prefer = kwargs['prefer'] diff --git a/sklearn/utils/testing.py b/sklearn/utils/testing.py index 1662294189690..42cbf9a9fad49 100644 --- a/sklearn/utils/testing.py +++ b/sklearn/utils/testing.py @@ -44,12 +44,12 @@ from numpy.testing import assert_array_almost_equal from numpy.testing import assert_array_less import numpy as np +import joblib import sklearn from sklearn.base import (BaseEstimator, ClassifierMixin, ClusterMixin, RegressorMixin, TransformerMixin) from sklearn.utils import deprecated, IS_PYPY, _IS_32BIT -from sklearn.utils._joblib import joblib from sklearn.utils._unittest_backport import TestCase additional_names_in_all = [] diff --git a/sklearn/utils/tests/test_estimator_checks.py b/sklearn/utils/tests/test_estimator_checks.py index 3db00c58f2077..c4a9d0bfa3fa2 100644 --- a/sklearn/utils/tests/test_estimator_checks.py +++ b/sklearn/utils/tests/test_estimator_checks.py @@ -3,12 +3,12 @@ import numpy as np import scipy.sparse as sp +import joblib from io import StringIO from sklearn.base import BaseEstimator, ClassifierMixin from sklearn.utils import deprecated -from sklearn.utils import _joblib from sklearn.utils.testing import (assert_raises_regex, assert_equal, ignore_warnings, assert_warns, assert_raises) @@ -415,9 +415,9 @@ def test_check_estimator_clones(): set_checking_parameters(est) set_random_state(est) # without fitting - old_hash = _joblib.hash(est) + old_hash = joblib.hash(est) check_estimator(est) - assert_equal(old_hash, _joblib.hash(est)) + assert_equal(old_hash, joblib.hash(est)) with ignore_warnings(category=(FutureWarning, DeprecationWarning)): # when 'est = SGDClassifier()' @@ -426,9 +426,9 @@ def test_check_estimator_clones(): set_random_state(est) # with fitting est.fit(iris.data + 10, iris.target) - old_hash = _joblib.hash(est) + old_hash = joblib.hash(est) check_estimator(est) - assert_equal(old_hash, _joblib.hash(est)) + assert_equal(old_hash, joblib.hash(est)) def test_check_estimators_unfitted(): diff --git a/sklearn/utils/tests/test_fixes.py b/sklearn/utils/tests/test_fixes.py index b4e49aaddf2ad..2a10197fc53b7 100644 --- a/sklearn/utils/tests/test_fixes.py +++ b/sklearn/utils/tests/test_fixes.py @@ -28,8 +28,8 @@ def test_masked_array_obj_dtype_pickleable(): @pytest.mark.parametrize('joblib_version', ('0.11', '0.12.0')) def test_joblib_parallel_args(monkeypatch, joblib_version): - import sklearn.utils._joblib - monkeypatch.setattr(sklearn.utils._joblib, '__version__', joblib_version) + import joblib + monkeypatch.setattr(joblib, '__version__', joblib_version) if joblib_version == '0.12.0': # arguments are simply passed through diff --git a/sklearn/utils/validation.py b/sklearn/utils/validation.py index f2b298dcba5b2..625c15dd3ac1f 100644 --- a/sklearn/utils/validation.py +++ b/sklearn/utils/validation.py @@ -17,14 +17,13 @@ from inspect import signature from numpy.core.numeric import ComplexWarning +import joblib from .fixes import _object_dtype_isnan from .. import get_config as _get_config from ..exceptions import NonBLASDotWarning from ..exceptions import NotFittedError from ..exceptions import DataConversionWarning -from ._joblib import Memory -from ._joblib import __version__ as joblib_version FLOAT_DTYPES = (np.float64, np.float32, np.float16) @@ -176,10 +175,10 @@ def check_memory(memory): """ if memory is None or isinstance(memory, str): - if LooseVersion(joblib_version) < '0.12': - memory = Memory(cachedir=memory, verbose=0) + if LooseVersion(joblib.__version__) < '0.12': + memory = joblib.Memory(cachedir=memory, verbose=0) else: - memory = Memory(location=memory, verbose=0) + memory = joblib.Memory(location=memory, verbose=0) elif not hasattr(memory, 'cache'): raise ValueError("'memory' should be None, a string or have the same" " interface as joblib.Memory." From a7c89f6671e366c260eeb0f4b1a02c071b52ab48 Mon Sep 17 00:00:00 2001 From: Roman Yurchak Date: Thu, 13 Jun 2019 16:16:32 +0200 Subject: [PATCH 2/3] Lint --- sklearn/datasets/species_distributions.py | 2 -- sklearn/model_selection/_validation.py | 2 +- sklearn/neighbors/base.py | 3 ++- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/sklearn/datasets/species_distributions.py b/sklearn/datasets/species_distributions.py index 74de41f5d5114..52ea9ec782178 100644 --- a/sklearn/datasets/species_distributions.py +++ b/sklearn/datasets/species_distributions.py @@ -41,10 +41,8 @@ from os import makedirs, remove from os.path import exists - import logging import numpy as np -import joblib from .base import get_data_home from .base import _fetch_remote diff --git a/sklearn/model_selection/_validation.py b/sklearn/model_selection/_validation.py index 4333f6133db12..383e35e54e835 100644 --- a/sklearn/model_selection/_validation.py +++ b/sklearn/model_selection/_validation.py @@ -17,7 +17,7 @@ import numpy as np import scipy.sparse as sp -from joblib import Parallel, delayed, logger +from joblib import Parallel, delayed from ..base import is_classifier, clone from ..utils import (indexable, check_random_state, safe_indexing, diff --git a/sklearn/neighbors/base.py b/sklearn/neighbors/base.py index fa5028339b724..44dcc326a489c 100644 --- a/sklearn/neighbors/base.py +++ b/sklearn/neighbors/base.py @@ -439,7 +439,8 @@ class from an array representing our data set and ask who's raise ValueError( "%s does not work with sparse matrices. Densify the data, " "or set algorithm='brute'" % self._fit_method) - old_joblib = LooseVersion(joblib.__version__) < LooseVersion('0.12') + old_joblib = ( + LooseVersion(joblib.__version__) < LooseVersion('0.12')) if old_joblib: # Deal with change of API in joblib check_pickle = False if old_joblib else None From 8d28a5e6653f843032135d55cb3422d26325e6bb Mon Sep 17 00:00:00 2001 From: Roman Yurchak Date: Thu, 13 Jun 2019 16:20:44 +0200 Subject: [PATCH 3/3] More fixes --- sklearn/datasets/species_distributions.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sklearn/datasets/species_distributions.py b/sklearn/datasets/species_distributions.py index 52ea9ec782178..f9a04f92b8486 100644 --- a/sklearn/datasets/species_distributions.py +++ b/sklearn/datasets/species_distributions.py @@ -44,6 +44,8 @@ import logging import numpy as np +import joblib + from .base import get_data_home from .base import _fetch_remote from .base import RemoteFileMetadata @@ -255,8 +257,8 @@ def fetch_species_distributions(data_home=None, test=test, train=train, **extra_params) - _joblib.dump(bunch, archive_path, compress=9) + joblib.dump(bunch, archive_path, compress=9) else: - bunch = _joblib.load(archive_path) + bunch = joblib.load(archive_path) return bunch