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

Skip to content

MNT Do not update docs with deprecated decorator #24410

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion sklearn/linear_model/_glm/glm.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,11 @@ def _get_loss(self):
)
@property
def family(self):
"""Ensure backward compatibility for the time of deprecation."""
"""Ensure backward compatibility for the time of deprecation.

.. deprecated:: 1.1
Will be removed in 1.3
"""
if isinstance(self, PoissonRegressor):
return "poisson"
elif isinstance(self, GammaRegressor):
Expand Down
8 changes: 7 additions & 1 deletion sklearn/tests/test_docstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,13 @@ def filter_errors(errors, method, Klass=None):

# Ignore PR02: Unknown parameters for properties. We sometimes use
# properties for ducktyping, i.e. SGDClassifier.predict_proba
if code == "PR02" and Klass is not None and method is not None:
# Ignore GL08: Parsing of the method signature failed, possibly because this is
# a property. Properties are sometimes used for deprecated attributes and the
# attribute is already documented in the class docstring.
#
# All error codes:
# https://numpydoc.readthedocs.io/en/latest/validation.html#built-in-validation-checks
if code in ("PR02", "GL08") and Klass is not None and method is not None:
method_obj = getattr(Klass, method)
if isinstance(method_obj, property):
continue
Expand Down
12 changes: 0 additions & 12 deletions sklearn/utils/deprecation.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ def wrapped(*args, **kwargs):
cls.__init__ = wrapped

wrapped.__name__ = "__init__"
wrapped.__doc__ = self._update_doc(init.__doc__)
wrapped.deprecated_original = init

return cls
Expand All @@ -87,7 +86,6 @@ def wrapped(*args, **kwargs):
warnings.warn(msg, category=FutureWarning)
return fun(*args, **kwargs)

wrapped.__doc__ = self._update_doc(wrapped.__doc__)
# Add a reference to the wrapped function so that we can introspect
# on function arguments in Python 2 (already works in Python 3)
wrapped.__wrapped__ = fun
Expand All @@ -103,18 +101,8 @@ def wrapped(*args, **kwargs):
warnings.warn(msg, category=FutureWarning)
return prop.fget(*args, **kwargs)

wrapped.__doc__ = self._update_doc(wrapped.__doc__)

return wrapped

def _update_doc(self, olddoc):
newdoc = "DEPRECATED"
if self.extra:
newdoc = "%s: %s" % (newdoc, self.extra)
if olddoc:
newdoc = "%s\n\n %s" % (newdoc, olddoc)
return newdoc


def _is_deprecated(func):
"""Helper to check if func is wrapped by our deprecated decorator"""
Expand Down
9 changes: 0 additions & 9 deletions sklearn/utils/tests/test_deprecation.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,3 @@ def test_is_deprecated():

def test_pickle():
pickle.loads(pickle.dumps(mock_function))


def test_deprecated_property_docstring_exists():
"""Deprecated property contains the original docstring."""
mock_class_property = getattr(MockClass2, "n_features_")
assert (
"DEPRECATED: n_features_ is deprecated\n\n Number of input features."
== mock_class_property.__doc__
)