Skip to content

Commit

Permalink
MNT Fixes pytest by using deprecated_modules (scikit-learn#15291)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
thomasjpfan authored and adrinjalali committed Oct 18, 2019
1 parent feabb54 commit 56edce8
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 26 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@

import platform
from distutils.version import LooseVersion
import os

import pytest
from _pytest.doctest import DoctestItem

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'

Expand Down Expand Up @@ -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]
4 changes: 4 additions & 0 deletions sklearn/_build_utils/deprecated_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
2 changes: 1 addition & 1 deletion sklearn/cluster/_birch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
3 changes: 1 addition & 2 deletions sklearn/cluster/tests/test_hierarchical.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 0 additions & 9 deletions sklearn/neural_network/multilayer_perceptron.py

This file was deleted.

9 changes: 0 additions & 9 deletions sklearn/neural_network/rbm.py

This file was deleted.

6 changes: 1 addition & 5 deletions sklearn/utils/deprecation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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)

0 comments on commit 56edce8

Please sign in to comment.