|
13 | 13 | check_random_state, column_or_1d, check_array,
|
14 | 14 | check_consistent_length, check_X_y, indexable,
|
15 | 15 | check_symmetric)
|
| 16 | +from .deprecation import deprecated |
16 | 17 | from .class_weight import compute_class_weight, compute_sample_weight
|
17 | 18 | from ..externals.joblib import cpu_count
|
18 |
| -from .exceptions import ConvergenceWarning |
19 |
| -from .exceptions import DataConversionWarning as DataConversionWarning_ |
20 |
| -from .utils import deprecated |
| 19 | +from ..exceptions import ConvergenceWarning |
| 20 | +from ..exceptions import DataConversionWarning as DataConversionWarning_ |
21 | 21 |
|
22 | 22 |
|
23 | 23 | ConvergenceWarning = deprecated("ConvergenceWarning has been moved "
|
|
39 | 39 | "check_symmetric"]
|
40 | 40 |
|
41 | 41 |
|
42 |
| -class deprecated(object): |
43 |
| - """Decorator to mark a function or class as deprecated. |
44 |
| -
|
45 |
| - Issue a warning when the function is called/the class is instantiated and |
46 |
| - adds a warning to the docstring. |
47 |
| -
|
48 |
| - The optional extra argument will be appended to the deprecation message |
49 |
| - and the docstring. Note: to use this with the default value for extra, put |
50 |
| - in an empty of parentheses: |
51 |
| -
|
52 |
| - >>> from sklearn.utils import deprecated |
53 |
| - >>> deprecated() # doctest: +ELLIPSIS |
54 |
| - <sklearn.utils.deprecated object at ...> |
55 |
| -
|
56 |
| - >>> @deprecated() |
57 |
| - ... def some_function(): pass |
58 |
| - """ |
59 |
| - |
60 |
| - # Adapted from http://wiki.python.org/moin/PythonDecoratorLibrary, |
61 |
| - # but with many changes. |
62 |
| - |
63 |
| - def __init__(self, extra=''): |
64 |
| - """ |
65 |
| - Parameters |
66 |
| - ---------- |
67 |
| - extra: string |
68 |
| - to be added to the deprecation messages |
69 |
| -
|
70 |
| - """ |
71 |
| - self.extra = extra |
72 |
| - |
73 |
| - def __call__(self, obj): |
74 |
| - if isinstance(obj, type): |
75 |
| - return self._decorate_class(obj) |
76 |
| - else: |
77 |
| - return self._decorate_fun(obj) |
78 |
| - |
79 |
| - def _decorate_class(self, cls): |
80 |
| - msg = "Class %s is deprecated" % cls.__name__ |
81 |
| - if self.extra: |
82 |
| - msg += "; %s" % self.extra |
83 |
| - |
84 |
| - # FIXME: we should probably reset __new__ for full generality |
85 |
| - init = cls.__init__ |
86 |
| - |
87 |
| - def wrapped(*args, **kwargs): |
88 |
| - warnings.warn(msg, category=DeprecationWarning) |
89 |
| - return init(*args, **kwargs) |
90 |
| - cls.__init__ = wrapped |
91 |
| - |
92 |
| - wrapped.__name__ = '__init__' |
93 |
| - wrapped.__doc__ = self._update_doc(init.__doc__) |
94 |
| - wrapped.deprecated_original = init |
95 |
| - |
96 |
| - return cls |
97 |
| - |
98 |
| - def _decorate_fun(self, fun): |
99 |
| - """Decorate function fun""" |
100 |
| - |
101 |
| - msg = "Function %s is deprecated" % fun.__name__ |
102 |
| - if self.extra: |
103 |
| - msg += "; %s" % self.extra |
104 |
| - |
105 |
| - def wrapped(*args, **kwargs): |
106 |
| - warnings.warn(msg, category=DeprecationWarning) |
107 |
| - return fun(*args, **kwargs) |
108 |
| - |
109 |
| - wrapped.__name__ = fun.__name__ |
110 |
| - wrapped.__dict__ = fun.__dict__ |
111 |
| - wrapped.__doc__ = self._update_doc(fun.__doc__) |
112 |
| - |
113 |
| - return wrapped |
114 |
| - |
115 |
| - def _update_doc(self, olddoc): |
116 |
| -
F438
newdoc = "DEPRECATED" |
117 |
| - if self.extra: |
118 |
| - newdoc = "%s: %s" % (newdoc, self.extra) |
119 |
| - if olddoc: |
120 |
| - newdoc = "%s\n\n%s" % (newdoc, olddoc) |
121 |
| - return newdoc |
122 |
| - |
123 |
| - |
124 | 42 | def safe_mask(X, mask):
|
125 | 43 | """Return a mask which is safe to use on X.
|
126 | 44 |
|
@@ -422,7 +340,8 @@ def gen_even_slices(n, n_packs, n_samples=None):
|
422 | 340 | """
|
423 | 341 | start = 0
|
424 | 342 | if n_packs < 1:
|
425 |
| - raise ValueError("gen_even_slices got n_packs=%s, must be >=1" % n_packs) |
| 343 | + raise ValueError("gen_even_slices got n_packs=%s, must be >=1" |
| 344 | + % n_packs) |
426 | 345 | for pack_num in range(n_packs):
|
427 | 346 | this_n = n // n_packs
|
428 | 347 | if pack_num < n % n_packs:
|
@@ -482,5 +401,3 @@ def tosequence(x):
|
482 | 401 | return x
|
483 | 402 | else:
|
484 | 403 | return list(x)
|
485 |
| - |
486 |
| - |
0 commit comments