8000 FIX/ENH Make the moved class resilient to the deprecation patching · scikit-learn/scikit-learn@857cb09 · GitHub
[go: up one dir, main page]

Skip to content

Commit 857cb09

Browse files
committed
FIX/ENH Make the moved class resilient to the deprecation patching
1 parent 61ae8d5 commit 857cb09

File tree

5 files changed

+35
-13
lines changed

5 files changed

+35
-13
lines changed

sklearn/base.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@
1010
from .externals import six
1111
from .utils.fixes import signature
1212
from .utils.deprecation import deprecated
13-
from .exceptions import ChangedBehaviorWarning
13+
from .exceptions import ChangedBehaviorWarning as ChangedBehaviorWarning_
1414

1515

16+
class ChangedBehaviorWarning(ChangedBehaviorWarning_):
17+
pass
18+
1619
ChangedBehaviorWarning = deprecated("ChangedBehaviorWarning has been moved "
1720
"into the sklearn.exceptions module. "
1821
"It will not be available here from "

sklearn/metrics/base.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,20 @@
2020
from ..utils import check_array, check_consistent_length
2121
from ..utils.multiclass import type_of_target
2222

23-
from ..exceptions import UndefinedMetricWarning
23+
from ..exceptions import UndefinedMetricWarning as UndefinedMetricWarning_
2424
from ..utils import deprecated
2525

26+
27+
class UndefinedMetricWarning(UndefinedMetricWarning_):
28+
pass
29+
30+
2631
UndefinedMetricWarning = deprecated("UndefinedMetricWarning has been moved "
2732
"into the sklearn.exceptions module. "
2833
"It will not be available here from "
2934
"version 0.19")(UndefinedMetricWarning)
3035

36+
3137
def _average_binary_score(binary_metric, y_true, y_score, average,
3238
sample_weight=None):
3339
"""Average a binary metric for multilabel classification

sklearn/utils/__init__.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,18 @@
1616
from .deprecation import deprecated
1717
from .class_weight import compute_class_weight, compute_sample_weight
1818
from ..externals.joblib import cpu_count
19-
from ..exceptions import ConvergenceWarning
19+
from ..exceptions import ConvergenceWarning as ConvergenceWarning_
2020
from ..exceptions import DataConversionWarning as DataConversionWarning_
2121

2222

23+
class ConvergenceWarning(ConvergenceWarning_):
24+
pass
25+
2326
ConvergenceWarning = deprecated("ConvergenceWarning has been moved "
2427
"into the sklearn.exceptions module. "
2528
"It will not be available here from "
2629
"version 0.19")(ConvergenceWarning)
2730

28-
DataConversionWarning = deprecated("DataConversionWarning has been moved "
29-
"into the sklearn.exceptions module. "
30-
"It will not be available here from "
31-
"version 0.19")(DataConversionWarning_)
3231

3332
__all__ = ["murmurhash3_32", "as_float_array",
3433
"assert_all_finite", "check_array",

sklearn/utils/tests/test_validation.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,14 @@
2626
from sklearn.svm import SVR
2727
from sklearn.datasets import make_blobs
2828
from sklearn.utils.validation import (
29-
NotFittedError,
3029
has_fit_parameter,
3130
check_is_fitted,
3231
check_consistent_length,
33-
DataConversionWarning,
3432
)
3533

34+
from sklearn.exceptions import NotFittedError
35+
from sklearn.exceptions import DataConversionWarning
36+
3637
from sklearn.utils.testing import assert_raise_message
3738

3839

sklearn/utils/validation.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,41 @@
1616
from ..utils.fixes import signature
1717
from .deprecation import deprecated
1818
from ..exceptions import DataConversionWarning as DataConversionWarning_
19-
from ..exceptions import NonBLASDotWarning
19+
from ..exceptions import NonBLASDotWarning as NonBLASDotWarning_
2020
from ..exceptions import NotFittedError as NotFittedError_
2121

2222

23+
class DataConversionWarning(DataConversionWarning_):
24+
pass
25+
2326
DataConversionWarning = deprecated("DataConversionWarning has been moved "
2427
"into the sklearn.exceptions module. "
2528
"It will not be available here from "
26-
"version 0.19")(DataConversionWarning_)
29+
"version 0.19")(DataConversionWarning)
30+
31+
32+
class NonBLASDotWarning(NonBLASDotWarning_):
33+
pass
2734

2835
NonBLASDotWarning = deprecated("NonBLASDotWarning has been moved "
2936
"into the sklearn.exceptions module. "
3037
"It will not be available here from "
3138
"version 0.19")(NonBLASDotWarning)
3239

40+
41+
class NotFittedError(NotFittedError_):
42+
pass
43+
3344
NotFittedError = deprecated("NotFittedError has been moved into the "
3445
"sklearn.exceptions module. It will not be "
35-
"available here from version 0.19")(NotFittedError_)
46+
"available here from version 0.19")(NotFittedError)
47+
3648

3749
FLOAT_DTYPES = (np.float64, np.float32, np.float16)
3850

3951
# Silenced by default to reduce verbosity. Turn on at runtime for
4052
# performance profiling.
41-
warnings.simplefilter('ignore', NonBLASDotWarning)
53+
warnings.simplefilter('ignore', NonBLASDotWarning_)
4254

4355

4456
def _assert_all_finite(X):
@@ -674,6 +686,7 @@ def check_is_fitted(estimator, attributes, msg=None, all_or_any=all):
674686
attributes = [attributes]
675687

676688
if not all_or_any([hasattr(estimator, attr) for attr in attributes]):
689+
# FIXME NotFittedError_ --> NotFittedError in 0.19
677690
raise NotFittedError_(msg % {'name': type(estimator).__name__})
678691

679692

0 commit comments

Comments
 (0)
0