Skip to content

Commit d4e9d79

Browse files
committed
Merge pull request #4826 from rvraghav93/exceptions
[MRG + 1] move custom error/warning classes into sklearn.exceptions (and move `deprecated` away from `utils.__init__.py`)
2 parents d271708 + 857cb09 commit d4e9d79

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+810
-615
lines changed

doc/developers/performance.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ silently dispatched to ``numpy.dot``. If you want to be sure when the original
105105
activate the related warning::
106106

107107
>>> import warnings
108-
>>> from sklearn.utils.validation import NonBLASDotWarning
108+
>>> from sklearn.exceptions import NonBLASDotWarning
109109
>>> warnings.simplefilter('always', NonBLASDotWarning) # doctest: +SKIP
110110

111111
.. _profiling-python-code:

doc/developers/utilities.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,5 +293,5 @@ Warnings and Exceptions
293293

294294
- :class:`deprecated`: Decorator to mark a function or class as deprecated.
295295

296-
- :class:`ConvergenceWarning`: Custom warning to catch convergence problems.
297-
Used in ``sklearn.covariance.graph_lasso``.
296+
- :class:`sklearn.exceptions.ConvergenceWarning`: Custom warning to catch
297+
convergence problems. Used in ``sklearn.covariance.graph_lasso``.

doc/modules/classes.rst

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,31 @@ partial dependence
378378
ensemble.partial_dependence.plot_partial_dependence
379379

380380

381+
.. _exceptions_ref:
382+
383+
:mod:`sklearn.exceptions`: Exceptions and warnings
384+
==================================================
385+
386+
.. automodule:: sklearn.exceptions
387+
:no-members:
388+
:no-inherited-members:
389+
390+
.. currentmodule:: sklearn
391+
392+
.. autosummary::
393+
:toctree: generated/
394+
:template: class_without_init.rst
395+
396+
exceptions.NotFittedError
397+
exceptions.ChangedBehaviorWarning
398+
exceptions.ConvergenceWarning
399+
exceptions.DataConversionWarning
400+
exceptions.DataDimensionalityWarning
401+
exceptions.EfficiencyWarning
402+
exceptions.FitFailedWarning
403+
exceptions.NonBLASDotWarning
404+
exceptions.UndefinedMetricWarning
405+
381406
.. _feature_extraction_ref:
382407

383408
:mod:`sklearn.feature_extraction`: Feature Extraction

doc/templates/class_without_init.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
:mod:`{{module}}`.{{objname}}
2+
{{ underline }}==============
3+
4+
.. currentmodule:: {{ module }}
5+
6+
.. autoclass:: {{ objname }}
7+
8+
.. include:: {{module}}.{{objname}}.examples
9+
10+
.. raw:: html
11+
12+
<div class="clearer"></div>

examples/linear_model/plot_sparse_recovery.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
from sklearn.metrics import auc, precision_recall_curve
5757
from sklearn.ensemble import ExtraTreesRegressor
5858
from sklearn.utils.extmath import pinvh
59-
from sklearn.utils import ConvergenceWarning
59+
from sklearn.exceptions import ConvergenceWarning
6060

6161

6262
def mutual_incoherence(X_relevant, X_irelevant):

sklearn/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959

6060
__all__ = ['calibration', 'cluster', 'covariance', 'cross_decomposition',
6161
'cross_validation', 'datasets', 'decomposition', 'dummy',
62-
'ensemble', 'externals', 'feature_extraction',
62+
'ensemble', 'exceptions', 'externals', 'feature_extraction',
6363
'feature_selection', 'gaussian_process', 'grid_search',
6464
'isotonic', 'kernel_approximation', 'kernel_ridge',
6565
'lda', 'learning_curve',

sklearn/base.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,18 @@
99
from scipy import sparse
1010
from .externals import six
1111
from .utils.fixes import signature
12+
from .utils.deprecation import deprecated
13+
from .exceptions import ChangedBehaviorWarning as ChangedBehaviorWarning_
1214

1315

14-
class ChangedBehaviorWarning(UserWarning):
16+
class ChangedBehaviorWarning(ChangedBehaviorWarning_):
1517
pass
1618

19+
ChangedBehaviorWarning = deprecated("ChangedBehaviorWarning has been moved "
20+
"into the sklearn.exceptions module. "
21+
"It will not be available here from "
22+
"version 0.19")(ChangedBehaviorWarning)
23+
1724

1825
##############################################################################
1926
def clone(estimator, safe=True):

sklearn/cluster/birch.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
from ..externals.six.moves import xrange
1515
from ..utils import check_array
1616
from ..utils.extmath import row_norms, safe_sparse_dot
17-
from ..utils.validation import NotFittedError, check_is_fitted
17+
from ..utils.validation import check_is_fitted
18+
from ..exceptions import NotFittedError
1819
from .hierarchical import AgglomerativeClustering
1920

2021

sklearn/cluster/tests/test_k_means.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
from sklearn.utils.testing import assert_raise_message
2121

2222

23-
from sklearn.utils.validation import DataConversionWarning
2423
from sklearn.utils.extmath import row_norms
2524
from sklearn.metrics.cluster import v_measure_score
2625
from sklearn.cluster import KMeans, k_means
@@ -29,6 +28,7 @@
2928
from sklearn.cluster.k_means_ import _mini_batch_step
3029
from sklearn.datasets.samples_generator import make_blobs
3130
from sklearn.externals.six.moves import cStringIO as StringIO
31+
from sklearn.exceptions import DataConversionWarning
3232

3333

3434
# non centered, sparse centers to check the

sklearn/covariance/graph_lasso_.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from .empirical_covariance_ import (empirical_covariance, EmpiricalCovariance,
1717
log_likelihood)
1818

19-
from ..utils import ConvergenceWarning
19+
from ..exceptions import ConvergenceWarning
2020
from ..utils.extmath import pinvh
2121
from ..utils.validation import check_random_state, check_array
2222
from ..linear_model import lars_path

0 commit comments

Comments
 (0)