Skip to content

FIX Uses code literals in deprecated to prevent linking #20410

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
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: 3 additions & 3 deletions doc/developers/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ latest up-to-date workflow.
`Video <https://youtu.be/dyxS9KKCNzA>`__,
`Transcript
<https://github.com/data-umbrella/event-transcripts/blob/main/2021/27-thomas-pr.md>`__

.. note::
In January 2021, the default branch name changed from ``master`` to ``main``
for the scikit-learn GitHub repository to use more inclusive terms.
Expand Down Expand Up @@ -1115,8 +1115,8 @@ use the decorator ``deprecated`` on a property. Please note that the
decorator for the docstrings to be rendered properly.
E.g., renaming an attribute ``labels_`` to ``classes_`` can be done as::

@deprecated("Attribute labels_ was deprecated in version 0.13 and "
"will be removed in 0.15. Use 'classes_' instead")
@deprecated("Attribute `labels_` was deprecated in version 0.13 and "
"will be removed in 0.15. Use `classes_` instead")
@property
def labels_(self):
return self.classes_
Expand Down
4 changes: 2 additions & 2 deletions sklearn/calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -652,8 +652,8 @@ def __init__(self, base_estimator, calibrators, *, classes, method="sigmoid"):
# TODO: Remove in 1.1
# mypy error: Decorated property not supported
@deprecated( # type: ignore
"calibrators_ is deprecated in 0.24 and will be removed in 1.1"
"(renaming of 0.26). Use calibrators instead."
"`calibrators_` is deprecated in 0.24 and will be removed in 1.1"
"(renaming of 0.26). Use `calibrators` instead."
)
@property
def calibrators_(self):
Expand Down
2 changes: 1 addition & 1 deletion sklearn/cluster/_affinity_propagation.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ def __init__(
# TODO: Remove in 1.1
# mypy error: Decorated property not supported
@deprecated( # type: ignore
"Attribute _pairwise was deprecated in "
"Attribute `_pairwise` was deprecated in "
"version 0.24 and will be removed in 1.1 (renaming of 0.26)."
)
@property
Expand Down
6 changes: 4 additions & 2 deletions sklearn/cluster/_birch.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,15 +473,17 @@ def __init__(

# TODO: Remove in 1.2
# mypy error: Decorated property not supported
@deprecated("fit_ is deprecated in 1.0 and will be removed in 1.2") # type: ignore
@deprecated( # type: ignore
"`fit_` is deprecated in 1.0 and will be removed in 1.2"
)
@property
def fit_(self):
return self._deprecated_fit

# TODO: Remove in 1.2
# mypy error: Decorated property not supported
@deprecated( # type: ignore
"partial_fit_ is deprecated in 1.0 and will be removed in 1.2"
"`partial_fit_` is deprecated in 1.0 and will be removed in 1.2"
)
@property
def partial_fit_(self):
Expand Down
6 changes: 3 additions & 3 deletions sklearn/cluster/_kmeans.py
Original file line number Diff line number Diff line change
Expand Up @@ -1697,23 +1697,23 @@ def __init__(
self.reassignment_ratio = reassignment_ratio

@deprecated( # type: ignore
"The attribute 'counts_' is deprecated in 0.24"
"The attribute `counts_` is deprecated in 0.24"
" and will be removed in 1.1 (renaming of 0.26)."
)
@property
def counts_(self):
return self._counts

@deprecated( # type: ignore
"The attribute 'init_size_' is deprecated in "
"The attribute `init_size_` is deprecated in "
"0.24 and will be removed in 1.1 (renaming of 0.26)."
)
@property
def init_size_(self):
return self._init_size

@deprecated( # type: ignore
"The attribute 'random_state_' is deprecated "
"The attribute `random_state_` is deprecated "
"in 0.24 and will be removed in 1.1 (renaming of 0.26)."
)
@property
Expand Down
2 changes: 1 addition & 1 deletion sklearn/cluster/_spectral.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ def _more_tags(self):
# TODO: Remove in 1.1
# mypy error: Decorated property not supported
@deprecated( # type: ignore
"Attribute _pairwise was deprecated in "
"Attribute `_pairwise` was deprecated in "
"version 0.24 and will be removed in 1.1 (renaming of 0.26)."
)
@property
Expand Down
2 changes: 1 addition & 1 deletion sklearn/cluster/tests/test_affinity_propagation.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,6 @@ def test_sparse_input_for_fit_predict():
# TODO: Remove in 1.1
def test_affinity_propagation_pairwise_is_deprecated():
afp = AffinityPropagation(affinity="precomputed")
msg = r"Attribute _pairwise was deprecated in version 0\.24"
msg = r"Attribute `_pairwise` was deprecated in version 0\.24"
with pytest.warns(FutureWarning, match=msg):
afp._pairwise
2 changes: 1 addition & 1 deletion sklearn/cluster/tests/test_birch.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def test_birch_n_clusters_long_int():
@pytest.mark.parametrize("attribute", ["fit_", "partial_fit_"])
def test_birch_fit_attributes_deprecated(attribute):
"""Test that fit_ and partial_fit_ attributes are deprecated."""
msg = f"{attribute} is deprecated in 1.0 and will be removed in 1.2"
msg = f"`{attribute}` is deprecated in 1.0 and will be removed in 1.2"
X, y = make_blobs(n_samples=10)
brc = Birch().fit(X, y)

Expand Down
2 changes: 1 addition & 1 deletion sklearn/cluster/tests/test_k_means.py
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,7 @@ def test_minibatch_kmeans_deprecated_attributes(attr):
# check that we raise a deprecation warning when accessing `init_size_`
# FIXME: remove in 1.1
depr_msg = (
f"The attribute '{attr}' is deprecated in 0.24 and will be " f"removed in 1.1"
f"The attribute `{attr}` is deprecated in 0.24 and will be " f"removed in 1.1"
)
km = MiniBatchKMeans(n_clusters=2, n_init=1, init="random", random_state=0)
km.fit(X)
Expand Down
2 changes: 1 addition & 1 deletion sklearn/cluster/tests/test_spectral.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,6 @@ def test_verbose(assign_labels, capsys):
@pytest.mark.parametrize("affinity", ["precomputed", "precomputed_nearest_neighbors"])
def test_pairwise_is_deprecated(affinity):
sp = SpectralClustering(affinity=affinity)
msg = r"Attribute _pairwise was deprecated in version 0\.24"
msg = r"Attribute `_pairwise` was deprecated in version 0\.24"
with pytest.warns(FutureWarning, match=msg):
sp._pairwise
9 changes: 5 additions & 4 deletions sklearn/covariance/_graph_lasso.py
Original file line number Diff line number Diff line change
Expand Up @@ -931,8 +931,9 @@ def fit(self, X, y=None):
# TODO: Remove in 1.1 when grid_scores_ is deprecated
# mypy error: Decorated property not supported
@deprecated( # type: ignore
"The grid_scores_ attribute is deprecated in version 0.24 in favor "
"of cv_results_ and will be removed in version 1.1 (renaming of 0.26)."
"The `grid_scores_` attribute is deprecated in version 0.24 in favor "
"of `cv_results_` and will be removed in version 1.1 "
"(renaming of 0.26)."
)
@property
def grid_scores_(self):
Expand All @@ -945,8 +946,8 @@ def grid_scores_(self):
# TODO: Remove in 1.1 when cv_alphas_ is deprecated
# mypy error: Decorated property not supported
@deprecated( # type: ignore
"The cv_alphas_ attribute is deprecated in version 0.24 in favor "
"of cv_results_['alpha'] and will be removed in version 1.1 "
"The `cv_alphas_` attribute is deprecated in version 0.24 in favor "
"of `cv_results_['alpha']` and will be removed in version 1.1 "
"(renaming of 0.26)."
)
@property
Expand Down
8 changes: 4 additions & 4 deletions sklearn/covariance/tests/test_graphical_lasso.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,16 +180,16 @@ def test_graphical_lasso_cv_grid_scores_and_cv_alphas_deprecated():

total_alphas = n_refinements * n_alphas + 1
msg = (
r"The grid_scores_ attribute is deprecated in version 0\.24 in "
r"favor of cv_results_ and will be removed in version 1\.1 "
r"The `grid_scores_` attribute is deprecated in version 0\.24 in "
r"favor of `cv_results_` and will be removed in version 1\.1 "
r"\(renaming of 0\.26\)."
)
with pytest.warns(FutureWarning, match=msg):
assert cov.grid_scores_.shape == (total_alphas, splits)

msg = (
r"The cv_alphas_ attribute is deprecated in version 0\.24 in "
r"favor of cv_results_\['alpha'\] and will be removed in version "
r"The `cv_alphas_` attribute is deprecated in version 0\.24 in "
r"favor of `cv_results_\['alpha'\]` and will be removed in version "
r"1\.1 \(renaming of 0\.26\)"
)
with pytest.warns(FutureWarning, match=msg):
Expand Down
26 changes: 13 additions & 13 deletions sklearn/cross_decomposition/_pls.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,39 +465,39 @@ def fit_transform(self, X, y=None):

# mypy error: Decorated property not supported
@deprecated( # type: ignore
"Attribute norm_y_weights was deprecated in version 0.24 and "
"Attribute `norm_y_weights` was deprecated in version 0.24 and "
"will be removed in 1.1 (renaming of 0.26)."
)
@property
def norm_y_weights(self):
return self._norm_y_weights

@deprecated( # type: ignore
"Attribute x_mean_ was deprecated in version 0.24 and "
"Attribute `x_mean_` was deprecated in version 0.24 and "
"will be removed in 1.1 (renaming of 0.26)."
)
@property
def x_mean_(self):
return self._x_mean

@deprecated( # type: ignore
"Attribute y_mean_ was deprecated in version 0.24 and "
"Attribute `y_mean_` was deprecated in version 0.24 and "
"will be removed in 1.1 (renaming of 0.26)."
)
@property
def y_mean_(self):
return self._y_mean

@deprecated( # type: ignore
"Attribute x_std_ was deprecated in version 0.24 and "
"Attribute `x_std_` was deprecated in version 0.24 and "
"will be removed in 1.1 (renaming of 0.26)."
)
@property
def x_std_(self):
return self._x_std

@deprecated( # type: ignore
"Attribute y_std_ was deprecated in version 0.24 and "
"Attribute `y_std_` was deprecated in version 0.24 and "
"will be removed in 1.1 (renaming of 0.26)."
)
@property
Expand All @@ -510,7 +510,7 @@ def x_scores_(self):
if not isinstance(self, PLSRegression):
pass
warnings.warn(
"Attribute x_scores_ was deprecated in version 0.24 and "
"Attribute `x_scores_` was deprecated in version 0.24 and "
"will be removed in 1.1 (renaming of 0.26). Use "
"est.transform(X) on the training data instead.",
FutureWarning,
Expand All @@ -522,7 +522,7 @@ def y_scores_(self):
# TODO: raise error in 1.1 instead
if not isinstance(self, PLSRegression):
warnings.warn(
"Attribute y_scores_ was deprecated in version 0.24 and "
"Attribute `y_scores_` was deprecated in version 0.24 and "
"will be removed in 1.1 (renaming of 0.26). Use "
"est.transform(X) on the training data instead.",
FutureWarning,
Expand Down Expand Up @@ -1013,7 +1013,7 @@ def fit(self, X, Y):

# mypy error: Decorated property not supported
@deprecated( # type: ignore
"Attribute x_scores_ was deprecated in version 0.24 and "
"Attribute `x_scores_` was deprecated in version 0.24 and "
"will be removed in 1.1 (renaming of 0.26). Use est.transform(X) on "
"the training data instead."
)
Expand All @@ -1023,7 +1023,7 @@ def x_scores_(self):

# mypy error: Decorated property not supported
@deprecated( # type: ignore
"Attribute y_scores_ was deprecated in version 0.24 and "
"Attribute `y_scores_` was deprecated in version 0.24 and "
"will be removed in 1.1 (renaming of 0.26). Use est.transform(X, Y) "
"on the training data instead."
)
Expand All @@ -1032,31 +1032,31 @@ def y_scores_(self):
return self._y_scores

@deprecated( # type: ignore
"Attribute x_mean_ was deprecated in version 0.24 and "
"Attribute `x_mean_` was deprecated in version 0.24 and "
"will be removed in 1.1 (renaming of 0.26)."
)
@property
def x_mean_(self):
return self._x_mean

@deprecated( # type: ignore
"Attribute y_mean_ was deprecated in version 0.24 and "
"Attribute `y_mean_` was deprecated in version 0.24 and "
"will be removed in 1.1 (renaming of 0.26)."
)
@property
def y_mean_(self):
return self._y_mean

@deprecated( # type: ignore
"Attribute x_std_ was deprecated in version 0.24 and "
"Attribute `x_std_` was deprecated in version 0.24 and "
"will be removed in 1.1 (renaming of 0.26)."
)
@property
def x_std_(self):
return self._x_std

@deprecated( # type: ignore
"Attribute y_std_ was deprecated in version 0.24 and "
"Attribute `y_std_` was deprecated in version 0.24 and "
"will be removed in 1.1 (renaming of 0.26)."
)
@property
Expand Down
19 changes: 12 additions & 7 deletions sklearn/cross_decomposition/tests/test_pls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from sklearn.utils import check_random_state
from sklearn.utils.extmath import svd_flip
from sklearn.exceptions import ConvergenceWarning
from sklearn.utils._testing import ignore_warnings


def assert_matrix_orthogonal(M):
Expand Down Expand Up @@ -344,7 +345,7 @@ def test_convergence_fail():
pls_nipals.fit(X, Y)


@pytest.mark.filterwarnings("ignore:.*scores_ was deprecated") # 1.1
@pytest.mark.filterwarnings("ignore:.*`scores_` was deprecated") # 1.1
@pytest.mark.parametrize("Est", (PLSSVD, PLSRegression, PLSCanonical))
def test_attibutes_shapes(Est):
# Make sure attributes are of the correct shape depending on n_components
Expand All @@ -355,9 +356,13 @@ def test_attibutes_shapes(Est):
pls = Est(n_components=n_components)
pls.fit(X, Y)
assert all(
attr.shape[1] == n_components
for attr in (pls.x_scores_, pls.y_scores_, pls.x_weights_, pls.y_weights_)
attr.shape[1] == n_components for attr in (pls.x_weights_, pls.y_weights_)
)
# TODO: remove in 1.1
with ignore_warnings(category=FutureWarning):
assert all(
attr.shape[1] == n_components for attr in (pls.x_scores_, pls.y_scores_)
)


@pytest.mark.parametrize("Est", (PLSRegression, PLSCanonical, CCA))
Expand Down Expand Up @@ -500,9 +505,9 @@ def test_scores_deprecations(Est):
X = rng.randn(10, 5)
Y = rng.randn(10, 3)
est = Est().fit(X, Y)
with pytest.warns(FutureWarning, match="x_scores_ was deprecated"):
with pytest.warns(FutureWarning, match="`x_scores_` was deprecated"):
assert_allclose(est.x_scores_, est.transform(X))
with pytest.warns(FutureWarning, match="y_scores_ was deprecated"):
with pytest.warns(FutureWarning, match="`y_scores_` was deprecated"):
assert_allclose(est.y_scores_, est.transform(X, Y)[1])


Expand All @@ -512,7 +517,7 @@ def test_norm_y_weights_deprecation(Est):
X = rng.randn(10, 5)
Y = rng.randn(10, 3)
est = Est().fit(X, Y)
with pytest.warns(FutureWarning, match="norm_y_weights was deprecated"):
with pytest.warns(FutureWarning, match="`norm_y_weights` was deprecated"):
est.norm_y_weights


Expand All @@ -524,7 +529,7 @@ def test_mean_and_std_deprecation(Estimator, attribute):
X = rng.randn(10, 5)
Y = rng.randn(10, 3)
estimator = Estimator().fit(X, Y)
with pytest.warns(FutureWarning, match=f"{attribute} was deprecated"):
with pytest.warns(FutureWarning, match=f"`{attribute}` was deprecated"):
getattr(estimator, attribute)


Expand Down
4 changes: 2 additions & 2 deletions sklearn/decomposition/_dict_learning.py
Original file line number Diff line number Diff line change
Expand Up @@ -1262,9 +1262,9 @@ def fit(self, X, y=None):
return self

@deprecated( # type: ignore
"The attribute 'components_' is deprecated "
"The attribute `components_` is deprecated "
"in 0.24 and will be removed in 1.1 (renaming of 0.26). Use the "
"'dictionary' instead."
"`dictionary` instead."
)
@property
def components_(self):
Expand Down
2 changes: 1 addition & 1 deletion sklearn/decomposition/_kernel_pca.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ def __init__(
# TODO: Remove in 1.1
# mypy error: Decorated property not supported
@deprecated( # type: ignore
"Attribute _pairwise was deprecated in "
"Attribute `_pairwise` was deprecated in "
"version 0.24 and will be removed in 1.1 (renaming of 0.26)."
)
@property
Expand Down
2 changes: 1 addition & 1 deletion sklearn/decomposition/tests/test_dict_learning.py
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ def test_sparse_coder_deprecation():
init_dict = rng.rand(n_components, n_features)
sc = SparseCoder(init_dict)

with pytest.warns(FutureWarning, match="'components_' is deprecated"):
with pytest.warns(FutureWarning, match="`components_` is deprecated"):
sc.components_


Expand Down
2 changes: 1 addition & 1 deletion sklearn/decomposition/tests/test_kernel_pca.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,6 @@ def test_kernel_pcc_pairwise_is_deprecated():
Tests that a `FutureWarning` is issued when `_pairwise` is accessed.
"""
kp = KernelPCA(kernel="precomputed")
msg = r"Attribute _pairwise was deprecated in version 0\.24"
msg = r"Attribute `_pairwise` was deprecated in version 0\.24"
with pytest.warns(FutureWarning, match=msg):
kp._pairwise
Loading