Implementation:Scikit learn Scikit learn Deprecation
| Knowledge Sources | |
|---|---|
| Domains | Machine Learning, API Design |
| Last Updated | 2026-02-08 15:00 GMT |
Overview
Concrete tool for marking functions, classes, and properties as deprecated with warning messages, provided by scikit-learn.
Description
The deprecated class is a decorator that marks a function, class, or property as deprecated. When the decorated object is used, it issues a FutureWarning and appends a deprecation notice to the docstring. It supports decorating classes (wrapping __init__), properties, and regular functions, with an optional extra message.
Usage
Use this decorator when you need to deprecate a function, class, or property in scikit-learn's API. It ensures users are warned about upcoming removals and provides guidance on alternatives.
Code Reference
Source Location
- Repository: scikit-learn
- File: sklearn/utils/deprecation.py
Signature
class deprecated:
def __init__(self, extra=""):
def __call__(self, obj):
def _decorate_class(self, cls):
def _decorate_property(self, prop):
def _decorate_fun(self, fun):
Import
from sklearn.utils import deprecated
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| extra | str | No | Additional message appended to the deprecation warning (default ) |
| obj | class, function, or property | Yes | The object to be marked as deprecated (passed via decorator syntax) |
Outputs
| Name | Type | Description |
|---|---|---|
| wrapped | class, function, or property | The wrapped object that issues deprecation warnings when used |
Usage Examples
Basic Usage
from sklearn.utils import deprecated
@deprecated("Use new_function instead.")
def old_function():
return "result"
old_function() # Issues FutureWarning: Function old_function is deprecated. Use new_function instead.