From 56edce84caf6f3c8ef96376e1b684c45311130f3 Mon Sep 17 00:00:00 2001 From: Thomas J Fan Date: Fri, 18 Oct 2019 12:09:46 -0400 Subject: [PATCH] MNT Fixes pytest by using deprecated_modules (#15291) * MNT Uses gitignore to filter pytest * MNT Uses collect_ignore_glob to configure collect_ignore_glob * CLN Restrict to py file * DOC Remove comments * ENH Adds neural network * CLN Proper import * CLN Proper import * DOC Adds comments --- .gitignore | 3 +++ conftest.py | 9 +++++++++ sklearn/_build_utils/deprecated_modules.py | 4 ++++ sklearn/cluster/_birch.py | 2 +- sklearn/cluster/tests/test_hierarchical.py | 3 +-- sklearn/neural_network/multilayer_perceptron.py | 9 --------- sklearn/neural_network/rbm.py | 9 --------- sklearn/utils/deprecation.py | 6 +----- 8 files changed, 19 insertions(+), 26 deletions(-) delete mode 100644 sklearn/neural_network/multilayer_perceptron.py delete mode 100644 sklearn/neural_network/rbm.py diff --git a/.gitignore b/.gitignore index ad35460f795f8..76744692f22f2 100644 --- a/.gitignore +++ b/.gitignore @@ -93,6 +93,9 @@ sklearn/ensemble/weight_boosting.py sklearn/tree/export.py sklearn/tree/tree.py +sklearn/neural_network/rbm.py +sklearn/neural_network/multilayer_perceptron.py + sklearn/utils/weight_vector.py sklearn/utils/seq_dataset.py sklearn/utils/fast_dict.py diff --git a/conftest.py b/conftest.py index 0c0e21b69b505..886a25cb1d566 100644 --- a/conftest.py +++ b/conftest.py @@ -7,6 +7,7 @@ import platform from distutils.version import LooseVersion +import os import pytest from _pytest.doctest import DoctestItem @@ -14,6 +15,7 @@ from sklearn import set_config from sklearn.utils import _IS_32BIT from sklearn.externals import _pilutil +from sklearn._build_utils.deprecated_modules import _DEPRECATED_MODULES PYTEST_MIN_VERSION = '3.3.0' @@ -96,3 +98,10 @@ def pytest_runtest_setup(item): def pytest_runtest_teardown(item, nextitem): if isinstance(item, DoctestItem): set_config(print_changed_only=False) + + +# TODO: Remove when modules are deprecated in 0.24 +# Configures pytest to ignore deprecated modules. +collect_ignore_glob = [ + os.path.join(*deprecated_path.split(".")) + ".py" + for _, deprecated_path, _ in _DEPRECATED_MODULES] diff --git a/sklearn/_build_utils/deprecated_modules.py b/sklearn/_build_utils/deprecated_modules.py index 241fa41e76e1b..ff55d89973cb6 100644 --- a/sklearn/_build_utils/deprecated_modules.py +++ b/sklearn/_build_utils/deprecated_modules.py @@ -20,6 +20,10 @@ ('_classes', 'sklearn.tree.tree', 'sklearn.tree'), ('_export', 'sklearn.tree.export', 'sklearn.tree'), + ('_rbm', 'sklearn.neural_network.rbm', 'sklearn.neural_network'), + ('_multilayer_perceptron', + 'sklearn.neural_network.multilayer_perceptron', 'sklearn.neural_network'), + ('_weight_vector', 'sklearn.utils.weight_vector', 'sklearn.utils'), ('_seq_dataset', 'sklearn.utils.seq_dataset', 'sklearn.utils'), ('_fast_dict', 'sklearn.utils.fast_dict', 'sklearn.utils'), diff --git a/sklearn/cluster/_birch.py b/sklearn/cluster/_birch.py index 78a440ca5bb39..e63abf9772520 100644 --- a/sklearn/cluster/_birch.py +++ b/sklearn/cluster/_birch.py @@ -14,7 +14,7 @@ from ..utils.extmath import row_norms, safe_sparse_dot from ..utils.validation import check_is_fitted from ..exceptions import ConvergenceWarning -from ._hierarchical import AgglomerativeClustering +from . import AgglomerativeClustering def _iterate_sparse_X(X): diff --git a/sklearn/cluster/tests/test_hierarchical.py b/sklearn/cluster/tests/test_hierarchical.py index d89d948b70270..26d489d0ded22 100644 --- a/sklearn/cluster/tests/test_hierarchical.py +++ b/sklearn/cluster/tests/test_hierarchical.py @@ -23,8 +23,7 @@ from sklearn.cluster import ward_tree from sklearn.cluster import AgglomerativeClustering, FeatureAgglomeration from sklearn.cluster._hierarchical import (_hc_cut, _TREE_BUILDERS, - _fix_connectivity) -from sklearn.cluster.hierarchical import linkage_tree + linkage_tree, _fix_connectivity) from sklearn.feature_extraction.image import grid_to_graph from sklearn.metrics.pairwise import PAIRED_DISTANCES, cosine_distances,\ manhattan_distances, pairwise_distances diff --git a/sklearn/neural_network/multilayer_perceptron.py b/sklearn/neural_network/multilayer_perceptron.py deleted file mode 100644 index f84632c8fd595..0000000000000 --- a/sklearn/neural_network/multilayer_perceptron.py +++ /dev/null @@ -1,9 +0,0 @@ -from ._multilayer_perceptron import * # noqa -from ..utils.deprecation import _raise_dep_warning_if_not_pytest - - -# TODO: remove entire file in 0.24 -deprecated_path = 'sklearn.neural_network.multilayer_perceptron' -correct_path = 'sklearn.neural_network' - -_raise_dep_warning_if_not_pytest(deprecated_path, correct_path) diff --git a/sklearn/neural_network/rbm.py b/sklearn/neural_network/rbm.py deleted file mode 100644 index 23439f8fc07ed..0000000000000 --- a/sklearn/neural_network/rbm.py +++ /dev/null @@ -1,9 +0,0 @@ -from ._rbm import * # noqa -from ..utils.deprecation import _raise_dep_warning_if_not_pytest - - -# TODO: remove entire file in 0.24 -deprecated_path = 'sklearn.neural_network.rbm' -correct_path = 'sklearn.neural_network' - -_raise_dep_warning_if_not_pytest(deprecated_path, correct_path) diff --git a/sklearn/utils/deprecation.py b/sklearn/utils/deprecation.py index 1e7a512c4c63f..bc06816438d24 100644 --- a/sklearn/utils/deprecation.py +++ b/sklearn/utils/deprecation.py @@ -128,9 +128,6 @@ def _raise_dep_warning_if_not_pytest(deprecated_path, correct_path): # Raise a deprecation warning with standardized deprecation message. # Useful because we are now deprecating # anything that isn't explicitly # in an __init__ file. - # We don't want to raise a dep warning if we are in a pytest session else - # the CIs with -Werror::DeprecationWarning would fail. The deprecations are - # still properly tested in sklearn/tests/test_import_deprecations.py # TODO: remove in 0.24 since this shouldn't be needed anymore. @@ -143,5 +140,4 @@ def _raise_dep_warning_if_not_pytest(deprecated_path, correct_path): "part of the private API." ).format(deprecated_path=deprecated_path, correct_path=correct_path) - if not getattr(sys, '_is_pytest_session', False): - warnings.warn(message, DeprecationWarning) + warnings.warn(message, DeprecationWarning)