Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0d2ce43

Browse files
glemaitrejeremiedbb
authored andcommitted
FIX change FutureWarnings to DeprecationWarnings for the tags (#30573)
1 parent 400e718 commit 0d2ce43

File tree

4 files changed

+33
-21
lines changed

4 files changed

+33
-21
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
- `_more_tags`, `_get_tags`, and `_safe_tags` are now raising a
2+
:class:`DeprecationWarning` instead of a :class:`FutureWarning` to only notify
3+
developers instead of end-users.
4+
By :user:`Guillaume Lemaitre <glemaitre>` in

sklearn/base.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ def _more_tags(self):
400400
warnings.warn(
401401
"The `_more_tags` method is deprecated in 1.6 and will be removed in "
402402
"1.7. Please implement the `__sklearn_tags__` method.",
403-
category=FutureWarning,
403+
category=DeprecationWarning,
404404
)
405405
return _to_old_tags(default_tags(self))
406406

@@ -411,7 +411,7 @@ def _get_tags(self):
411411
warnings.warn(
412412
"The `_get_tags` method is deprecated in 1.6 and will be removed in "
413413
"1.7. Please implement the `__sklearn_tags__` method.",
414-
category=FutureWarning,
414+
category=DeprecationWarning,
415415
)
416416

417417
return _to_old_tags(get_tags(self))

sklearn/utils/_tags.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ def _find_tags_provider(estimator, warn=True):
359359
"`sklearn.base.ClassifierMixin`, `sklearn.base.RegressorMixin`, and "
360360
"`sklearn.base.OutlierMixin`. From scikit-learn 1.7, not defining "
361361
"`__sklearn_tags__` will raise an error.",
362-
category=FutureWarning,
362+
category=DeprecationWarning,
363363
)
364364
return tag_provider
365365

@@ -446,7 +446,7 @@ def _safe_tags(estimator, key=None):
446446
"The `_safe_tags` function is deprecated in 1.6 and will be removed in "
447447
"1.7. Use the public `get_tags` function instead and make sure to implement "
448448
"the `__sklearn_tags__` method.",
449-
category=FutureWarning,
449+
category=DeprecationWarning,
450450
)
451451
tags = _to_old_tags(get_tags(estimator))
452452

sklearn/utils/tests/test_tags.py

+25-17
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ class EmptyRegressor(RegressorMixin, BaseEstimator):
4040
pass
4141

4242

43-
@pytest.mark.filterwarnings("ignore:.*no __sklearn_tags__ attribute.*:FutureWarning")
43+
@pytest.mark.filterwarnings(
44+
"ignore:.*no __sklearn_tags__ attribute.*:DeprecationWarning"
45+
)
4446
@pytest.mark.parametrize(
4547
"estimator, value",
4648
[
@@ -169,7 +171,7 @@ def test_get_tags_backward_compatibility():
169171
predictor_classes = [PredictorNewTags, PredictorOldNewTags, PredictorOldTags]
170172
for predictor_cls in predictor_classes:
171173
if predictor_cls.__name__.endswith("OldTags"):
172-
with pytest.warns(FutureWarning, match=warn_msg):
174+
with pytest.warns(DeprecationWarning, match=warn_msg):
173175
tags = get_tags(predictor_cls())
174176
else:
175177
tags = get_tags(predictor_cls())
@@ -194,7 +196,7 @@ class ChildClass(allow_nan_cls, predictor_cls):
194196
base_cls.__name__.endswith("OldTags")
195197
for base_cls in (predictor_cls, allow_nan_cls)
196198
):
197-
with pytest.warns(FutureWarning, match=warn_msg):
199+
with pytest.warns(DeprecationWarning, match=warn_msg):
198200
tags = get_tags(ChildClass())
199201
else:
200202
tags = get_tags(ChildClass())
@@ -227,7 +229,7 @@ class ChildClass(allow_nan_cls, array_api_cls, predictor_cls):
227229
base_cls.__name__.endswith("OldTags")
228230
for base_cls in (predictor_cls, array_api_cls, allow_nan_cls)
229231
):
230-
with pytest.warns(FutureWarning, match=warn_msg):
232+
with pytest.warns(DeprecationWarning, match=warn_msg):
231233
tags = get_tags(ChildClass())
232234
else:
233235
tags = get_tags(ChildClass())
@@ -238,7 +240,7 @@ class ChildClass(allow_nan_cls, array_api_cls, predictor_cls):
238240

239241

240242
@pytest.mark.filterwarnings(
241-
"ignore:.*Please define the `__sklearn_tags__` method.*:FutureWarning"
243+
"ignore:.*Please define the `__sklearn_tags__` method.*:DeprecationWarning"
242244
)
243245
def test_safe_tags_backward_compatibility():
244246
warn_msg = "The `_safe_tags` function is deprecated in 1.6"
@@ -247,7 +249,7 @@ def test_safe_tags_backward_compatibility():
247249
# only predictor inheriting from BaseEstimator
248250
predictor_classes = [PredictorNewTags, PredictorOldNewTags, PredictorOldTags]
249251
for predictor_cls in predictor_classes:
250-
with pytest.warns(FutureWarning, match=warn_msg):
252+
with pytest.warns(DeprecationWarning, match=warn_msg):
251253
tags = _safe_tags(predictor_cls())
252254
assert tags["requires_fit"]
253255

@@ -266,7 +268,7 @@ def test_safe_tags_backward_compatibility():
266268
class ChildClass(allow_nan_cls, predictor_cls):
267269
pass
268270

269-
with pytest.warns(FutureWarning, match=warn_msg):
271+
with pytest.warns(DeprecationWarning, match=warn_msg):
270272
tags = _safe_tags(ChildClass())
271273

272274
assert tags["allow_nan"]
@@ -293,7 +295,7 @@ class ChildClass(allow_nan_cls, predictor_cls):
293295
class ChildClass(allow_nan_cls, array_api_cls, predictor_cls):
294296
pass
295297

296-
with pytest.warns(FutureWarning, match=warn_msg):
298+
with pytest.warns(DeprecationWarning, match=warn_msg):
297299
tags = _safe_tags(ChildClass())
298300

299301
assert tags["allow_nan"]
@@ -302,7 +304,7 @@ class ChildClass(allow_nan_cls, array_api_cls, predictor_cls):
302304

303305

304306
@pytest.mark.filterwarnings(
305-
"ignore:.*Please define the `__sklearn_tags__` method.*:FutureWarning"
307+
"ignore:.*Please define the `__sklearn_tags__` method.*:DeprecationWarning"
306308
)
307309
def test__get_tags_backward_compatibility():
308310
warn_msg = "The `_get_tags` method is deprecated in 1.6"
@@ -311,7 +313,7 @@ def test__get_tags_backward_compatibility():
311313
# only predictor inheriting from BaseEstimator
312314
predictor_classes = [PredictorNewTags, PredictorOldNewTags, PredictorOldTags]
313315
for predictor_cls in predictor_classes:
314-
with pytest.warns(FutureWarning, match=warn_msg):
316+
with pytest.warns(DeprecationWarning, match=warn_msg):
315317
tags = predictor_cls()._get_tags()
316318
assert tags["requires_fit"]
317319

@@ -330,7 +332,7 @@ def test__get_tags_backward_compatibility():
330332
class ChildClass(allow_nan_cls, predictor_cls):
331333
pass
332334

333-
with pytest.warns(FutureWarning, match=warn_msg):
335+
with pytest.warns(DeprecationWarning, match=warn_msg):
334336
tags = ChildClass()._get_tags()
335337

336338
assert tags["allow_nan"]
@@ -357,7 +359,7 @@ class ChildClass(allow_nan_cls, predictor_cls):
357359
class ChildClass(allow_nan_cls, array_api_cls, predictor_cls):
358360
pass
359361

360-
with pytest.warns(FutureWarning, match=warn_msg):
362+
with pytest.warns(DeprecationWarning, match=warn_msg):
361363
tags = ChildClass()._get_tags()
362364

363365
assert tags["allow_nan"]
@@ -376,29 +378,35 @@ def test_base_estimator_more_tags():
376378
`BaseEstimator`.
377379
"""
378380
estimator = BaseEstimator()
379-
with pytest.warns(FutureWarning, match="The `_more_tags` method is deprecated"):
381+
with pytest.warns(
382+
DeprecationWarning, match="The `_more_tags` method is deprecated"
383+
):
380384
more_tags = BaseEstimator._more_tags(estimator)
381385

382-
with pytest.warns(FutureWarning, match="The `_get_tags` method is deprecated"):
386+
with pytest.warns(DeprecationWarning, match="The `_get_tags` method is deprecated"):
383387
get_tags = BaseEstimator._get_tags(estimator)
384388

385389
assert more_tags == get_tags
386390

387391

388392
def test_safe_tags():
389393
estimator = PredictorNewTags()
390-
with pytest.warns(FutureWarning, match="The `_safe_tags` function is deprecated"):
394+
with pytest.warns(
395+
DeprecationWarning, match="The `_safe_tags` function is deprecated"
396+
):
391397
tags = _safe_tags(estimator)
392398

393-
with pytest.warns(FutureWarning, match="The `_safe_tags` function is deprecated"):
399+
with pytest.warns(
400+
DeprecationWarning, match="The `_safe_tags` function is deprecated"
401+
):
394402
tags_requires_fit = _safe_tags(estimator, key="requires_fit")
395403

396404
assert tags_requires_fit == tags["requires_fit"]
397405

398406
err_msg = "The key unknown_key is not defined"
399407
with pytest.raises(ValueError, match=err_msg):
400408
with pytest.warns(
401-
FutureWarning, match="The `_safe_tags` function is deprecated"
409+
DeprecationWarning, match="The `_safe_tags` function is deprecated"
402410
):
403411
_safe_tags(estimator, key="unknown_key")
404412

0 commit comments

Comments
 (0)