diff --git a/sklearn/tests/test_common.py b/sklearn/tests/test_common.py index de5003687ca95..0ada8c5ef0a30 100644 --- a/sklearn/tests/test_common.py +++ b/sklearn/tests/test_common.py @@ -136,6 +136,10 @@ def test_check_estimator_generate_only_deprecation(): "ignore:Since version 1.0, it is not needed to import " "enable_hist_gradient_boosting anymore" ) +# TODO(1.8): remove this filter +@pytest.mark.filterwarnings( + "ignore:Importing from sklearn.utils._estimator_html_repr is deprecated." +) def test_import_all_consistency(): sklearn_path = [os.path.dirname(sklearn.__file__)] # Smoke test to check that any name in a __all__ list is actually defined diff --git a/sklearn/utils/_estimator_html_repr.py b/sklearn/utils/_estimator_html_repr.py new file mode 100644 index 0000000000000..f7898ae5e76cc --- /dev/null +++ b/sklearn/utils/_estimator_html_repr.py @@ -0,0 +1,34 @@ +# Authors: The scikit-learn developers +# SPDX-License-Identifier: BSD-3-Clause + +import warnings + +from ._repr_html.base import _HTMLDocumentationLinkMixin +from ._repr_html.estimator import ( + _get_visual_block, + _IDCounter, + _VisualBlock, + _write_estimator_html, + _write_label_html, + estimator_html_repr, +) + +__all__ = [ + "_HTMLDocumentationLinkMixin", + "_IDCounter", + "_VisualBlock", + "_get_visual_block", + "_write_estimator_html", + "_write_label_html", + "estimator_html_repr", +] + +# TODO(1.8): Remove the entire module +warnings.warn( + "Importing from sklearn.utils._estimator_html_repr is deprecated. The tools have " + "been moved to sklearn.utils._repr_html. Be aware that this module is private and " + "may be subject to change in the future. The module _estimator_html_repr will be " + "removed in 1.8.0.", + FutureWarning, + stacklevel=2, +) diff --git a/sklearn/utils/tests/test_estimator_html_repr.py b/sklearn/utils/tests/test_estimator_html_repr.py new file mode 100644 index 0000000000000..d24e357b74426 --- /dev/null +++ b/sklearn/utils/tests/test_estimator_html_repr.py @@ -0,0 +1,21 @@ +# Authors: The scikit-learn developers +# SPDX-License-Identifier: BSD-3-Clause + +import importlib +import sys + +import pytest + + +# TODO(1.8): Remove the entire file +def test_estimator_html_repr_warning(): + with pytest.warns(FutureWarning): + # Make sure that we check for the warning when loading the module (reloading it + # if needed). + module_name = "sklearn.utils._estimator_html_repr" + if module_name in sys.modules: + importlib.reload(sys.modules[module_name]) + else: + importlib.import_module(module_name) + + assert sys.modules[module_name] is not None