Skip to content
Merged
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
38 changes: 26 additions & 12 deletions sklearn/decomposition/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,33 @@
this module can be regarded as dimensionality reduction techniques.
"""

from ._nmf import NMF, non_negative_factorization
from ._pca import PCA
from ._incremental_pca import IncrementalPCA
from ._kernel_pca import KernelPCA
from ._sparse_pca import SparsePCA, MiniBatchSparsePCA
from ._truncated_svd import TruncatedSVD
from ._fastica import FastICA, fastica
from ._dict_learning import (dict_learning, dict_learning_online,
# TODO: remove me in 0.24 (as well as the noqa markers) and
# import the dict_learning func directly from the ._dict_learning
# module instead.
# Pre-cache the import of the deprecated module so that import
# sklearn.decomposition.dict_learning returns the function as in
# 0.21, instead of the module.
# https://github.com/scikit-learn/scikit-learn/issues/15842
import warnings
with warnings.catch_warnings():
warnings.simplefilter("ignore", category=FutureWarning)
from .dict_learning import dict_learning


from ._nmf import NMF, non_negative_factorization # noqa
from ._pca import PCA # noqa
from ._incremental_pca import IncrementalPCA # noqa
from ._kernel_pca import KernelPCA # noqa
from ._sparse_pca import SparsePCA, MiniBatchSparsePCA # noqa
from ._truncated_svd import TruncatedSVD # noqa
from ._fastica import FastICA, fastica # noqa
from ._dict_learning import (dict_learning_online,
sparse_encode, DictionaryLearning,
MiniBatchDictionaryLearning, SparseCoder)
from ._factor_analysis import FactorAnalysis
from ..utils.extmath import randomized_svd
from ._lda import LatentDirichletAllocation
MiniBatchDictionaryLearning, SparseCoder) # noqa
from ._factor_analysis import FactorAnalysis # noqa
from ..utils.extmath import randomized_svd # noqa
from ._lda import LatentDirichletAllocation # noqa


__all__ = ['DictionaryLearning',
'FastICA',
Expand Down
21 changes: 17 additions & 4 deletions sklearn/inspection/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
"""The :mod:`sklearn.inspection` module includes tools for model inspection."""
from ._partial_dependence import partial_dependence
from ._partial_dependence import plot_partial_dependence
from ._partial_dependence import PartialDependenceDisplay
from ._permutation_importance import permutation_importance

# TODO: remove me in 0.24 (as well as the noqa markers) and
# import the partial_dependence func directly from the
# ._partial_dependence module instead.
# Pre-cache the import of the deprecated module so that import
# sklearn.inspection.partial_dependence returns the function as in
# 0.21, instead of the module
# https://github.com/scikit-learn/scikit-learn/issues/15842
import warnings
with warnings.catch_warnings():
warnings.simplefilter("ignore", category=FutureWarning)
from .partial_dependence import partial_dependence

from ._partial_dependence import plot_partial_dependence # noqa
from ._partial_dependence import PartialDependenceDisplay # noqa
from ._permutation_importance import permutation_importance # noqa


__all__ = [
'partial_dependence',
Expand Down
6 changes: 6 additions & 0 deletions sklearn/tests/test_import_deprecations.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ def test_import_is_deprecated(deprecated_path, importee):

# TODO: remove in 0.24

# Special case for:
# https://github.com/scikit-learn/scikit-learn/issues/15842
if deprecated_path in ("sklearn.decomposition.dict_learning",
"sklearn.inspection.partial_dependence"):
pytest.skip("No warning can be raised for " + deprecated_path)

expected_message = (
"The {deprecated_path} module is deprecated in version "
"0.22 and will be removed in version 0.24. "
Expand Down
35 changes: 35 additions & 0 deletions sklearn/utils/tests/test_deprecated_utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import pytest
import types
import numpy as np
import warnings

from sklearn.dummy import DummyClassifier
from sklearn.utils import all_estimators
from sklearn.utils.estimator_checks import choose_check_classifiers_labels
from sklearn.utils.estimator_checks import NotAnArray
from sklearn.utils.estimator_checks import enforce_estimator_tags_y
Expand Down Expand Up @@ -94,3 +97,35 @@ def test_safe_indexing():
with pytest.warns(FutureWarning,
match="removed in version 0.24"):
safe_indexing([1, 2], 0)


# TODO: remove in 0.24
def test_partial_dependence_no_shadowing():
# Non-regression test for:
# https://github.com/scikit-learn/scikit-learn/issues/15842
with warnings.catch_warnings():
warnings.simplefilter("ignore", category=FutureWarning)
from sklearn.inspection.partial_dependence import partial_dependence as _ # noqa

# Calling all_estimators() also triggers a recursive import of all
# submodules, including deprecated ones.
all_estimators()

from sklearn.inspection import partial_dependence
assert isinstance(partial_dependence, types.FunctionType)


# TODO: remove in 0.24
def test_dict_learning_no_shadowing():
# Non-regression test for:
# https://github.com/scikit-learn/scikit-learn/issues/15842
with warnings.catch_warnings():
warnings.simplefilter("ignore", category=FutureWarning)
from sklearn.decomposition.dict_learning import dict_learning as _ # noqa

# Calling all_estimators() also triggers a recursive import of all
# submodules, including deprecated ones.
all_estimators()

from sklearn.decomposition import dict_learning
assert isinstance(dict_learning, types.FunctionType)