Skip to content

Commit 4c692e9

Browse files
jnothmanlarsmans
authored andcommitted
FIX update sklearn.__all__ to include all end-user submodules
Conflicts: sklearn/__init__.py sklearn/tests/test_common.py
1 parent 7658dd6 commit 4c692e9

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

sklearn/__init__.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
else:
3737
from . import __check_build
3838
from .base import clone
39+
__check_build # avoid flakes unused variable error
3940

4041
def test(*args, **kwargs):
4142
import warnings
@@ -60,14 +61,17 @@ def test(*args, **kwargs):
6061
# "test" as a test function
6162
test.__test__ = False
6263

63-
__all__ = ['cross_validation', 'cluster', 'covariance',
64-
'datasets', 'decomposition', 'feature_extraction',
65-
'feature_selection', 'semi_supervised',
66-
'gaussian_process', 'grid_search', 'hmm', 'lda', 'linear_model',
67-
'metrics', 'mixture', 'naive_bayes', 'neighbors', 'pipeline',
68-
'preprocessing', 'qda', 'svm', 'clone',
69-
'cross_decomposition',
70-
'isotonic', 'pls']
64+
__all__ = ['cluster', 'covariance', 'cross_decomposition',
65+
'cross_validation', 'datasets', 'decomposition', 'dummy',
66+
'ensemble', 'externals', 'feature_extraction',
67+
'feature_selection', 'gaussian_process', 'grid_search', 'hmm',
68+
'isotonic', 'kernel_approximation', 'lda', 'learning_curve',
69+
'linear_model', 'manifold', 'metrics', 'mixture', 'multiclass',
70+
'naive_bayes', 'neighbors', 'neural_network', 'pipeline', 'pls',
71+
'preprocessing', 'qda', 'random_projection', 'semi_supervised',
72+
'svm', 'tree',
73+
# Non-modules:
74+
'clone']
7175

7276

7377
def setup_module(module):

sklearn/tests/test_common.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@
3131
from sklearn.utils.testing import meta_estimators
3232
from sklearn.utils.testing import set_random_state
3333
from sklearn.utils.testing import assert_greater
34+
from sklearn.utils.testing import assert_in
3435
from sklearn.utils.testing import SkipTest
3536
from sklearn.utils.testing import check_skip_travis
37+
from sklearn.utils.testing import ignore_warnings
3638

3739
import sklearn
3840
from sklearn.base import (clone, ClassifierMixin, RegressorMixin,
@@ -1143,12 +1145,14 @@ def check_cluster_overwrite_params(name, Clustering, X, y):
11431145
% (name, k, v, new_params[k]))
11441146

11451147

1148+
@ignore_warnings
11461149
def test_import_all_consistency():
11471150
# Smoke test to check that any name in a __all__ list is actually defined
11481151
# in the namespace of the module or package.
11491152
pkgs = pkgutil.walk_packages(path=sklearn.__path__, prefix='sklearn.',
11501153
onerror=lambda _: None)
1151-
for importer, modname, ispkg in pkgs:
1154+
submods = [modname for _, modname, _ in pkgs]
1155+
for modname in submods + ['sklearn']:
11521156
if ".tests." in modname:
11531157
continue
11541158
package = __import__(modname, fromlist="dummy")
@@ -1159,6 +1163,15 @@ def test_import_all_consistency():
11591163
modname, name))
11601164

11611165

1166+
def test_root_import_all_completeness():
1167+
EXCEPTIONS = ('utils', 'tests', 'base', 'setup')
1168+
for _, modname, _ in pkgutil.walk_packages(path=sklearn.__path__,
1169+
onerror=lambda _: None):
1170+
if '.' in modname or modname.startswith('_') or modname in EXCEPTIONS:
1171+
continue
1172+
assert_in(modname, sklearn.__all__)
1173+
1174+
11621175
def test_sparsify_estimators():
11631176
"""Test if predict with sparsified estimators works.
11641177

0 commit comments

Comments
 (0)