Skip to content
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

MNT Deprecate metrics.pairwise.paired_*_distances and paired_distances public functions #27129

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

Shreesha3112
Copy link
Contributor

@Shreesha3112 Shreesha3112 commented Aug 22, 2023

Reference Issues/PRs

Fixes #26982

What does this implement/fix? Explain your changes.

Deprecates metrics.pairwise.paired_*_distance functions and metrics.pairwise.paired_distance

  • metrics.pairwise.paired_euclidean_distances
  • metrics.pairwise.paired_manhattan_distances
  • metrics.pairwise.paired_cosine_distances
  • metrics.pairwise.paired_distances

Any other comments?

@github-actions
Copy link

github-actions bot commented Aug 22, 2023

✔️ Linting Passed

All linting checks passed. Your pull request is in excellent shape! ☀️

Generated for commit: aaf36e6. Link to the linter CI: here

@Shreesha3112 Shreesha3112 changed the title API Deprecate metrics.pairwise.paired_*_distance public functions MNT Deprecate metrics.pairwise.paired_*_distance public functions Aug 22, 2023
@Shreesha3112
Copy link
Contributor Author

I've noticed that the changes to metrics.pairwise.paired_distance could impact cluster.AgglomerativeClustering. Specifically, the linkage_tree function relies on metrics.pairwise.paired_distances when the affinity isn't precomputed. Given this, should I go ahead and make the required changes to both metrics.pairwise.paired_distances and the linkage_tree function within this PR, or would it be preferred to handle them separately?

@Shreesha3112 Shreesha3112 marked this pull request as ready for review August 22, 2023 10:25
@ogrisel
Copy link
Member

ogrisel commented Aug 22, 2023

Maybe we could put the code in private functions (with a _ prefix and without redundant input parameter and data checks) and make the deprecated public functions call their private counterparts.

The AgglomerativeClustering estimator could then directly call the private functions.

@Shreesha3112 Shreesha3112 changed the title MNT Deprecate metrics.pairwise.paired_*_distance public functions MNT Deprecate metrics.pairwise.paired_*_distances and paired_distances public functions Aug 24, 2023
@glemaitre glemaitre self-requested a review October 31, 2023 15:59
@glemaitre
Copy link
Member

I resolved the conflicts with main. I will give a round of review.

Copy link
Member

@glemaitre glemaitre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am fine with the deprecation. I only commented to add some info that we use when we grep the files seeking for deprecated function/variables.

sklearn/metrics/pairwise.py Outdated Show resolved Hide resolved
sklearn/metrics/pairwise.py Outdated Show resolved Hide resolved
sklearn/metrics/pairwise.py Outdated Show resolved Hide resolved
sklearn/metrics/pairwise.py Outdated Show resolved Hide resolved
sklearn/metrics/pairwise.py Outdated Show resolved Hide resolved
sklearn/metrics/tests/test_pairwise.py Outdated Show resolved Hide resolved
sklearn/metrics/tests/test_pairwise.py Outdated Show resolved Hide resolved
sklearn/metrics/tests/test_pairwise.py Outdated Show resolved Hide resolved
sklearn/metrics/tests/test_pairwise.py Outdated Show resolved Hide resolved
@@ -275,10 +275,6 @@ def _check_function_param_validation(
"sklearn.metrics.pairwise.linear_kernel",
"sklearn.metrics.pairwise.manhattan_distances",
"sklearn.metrics.pairwise.nan_euclidean_distances",
"sklearn.metrics.pairwise.paired_cosine_distances",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would still test them but add a comment above to remove them.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this still needs to be reverted.

Copy link
Member

@glemaitre glemaitre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am fine with the deprecation. I only commented to add some info that we use when we grep the files seeking for deprecated function/variables. Thanks @Shreesha3112

Copy link
Member

@glemaitre glemaitre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am fine with the deprecation. I only commented to add some info that we use when we grep the files seeking for deprecated function/variables. Thanks @Shreesha3112

@glemaitre glemaitre added the Waiting for Second Reviewer First reviewer is done, need a second one! label Oct 31, 2023
Co-authored-by: Guillaume Lemaitre <g.lemaitre58@gmail.com>
Copy link
Member

@amueller amueller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good but I'd add a note to the deprecation message that tells users what function to use instead (pairwise_distances I assume).

Copy link
Member

@thomasjpfan thomasjpfan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good but I'd add a note to the deprecation message that tells users what function to use instead (pairwise_distances I assume).

@amueller If the paired_*_distances are removed, there is no direct replacement.

metrics.pairwise.paired_euclidean_distances
metrics.pairwise.paired_manhattan_distances
metrics.pairwise.paired_cosine_distances
metrics.pairwise.paired_distances
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can these be moved to

Recently deprecated
===================
?

:func:`~metrics.pairwise.paired_euclidean_distances`,
:func:`~metrics.pairwise.paired_manhattan_distances` and
:func:`~metrics.pairwise.paired_cosine_distances` are now deprecated and
will be removed in 1.6.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since 1.4 is released, this changelog entry needs to be moved to v1.5.rst and:

Suggested change
will be removed in 1.6.
will be removed in 1.7.

@@ -1129,6 +1130,11 @@ def cosine_distances(X, Y=None):
return S


# TODO(1.6): Remove in 1.6
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# TODO(1.6): Remove in 1.6
# TODO(1.7): Remove in 1.7

# TODO(1.6): Remove in 1.6
@deprecated(
"The public function `sklearn.pairwise.paired_euclidean_distances` has been "
"deprecated in 1.4 and will be removed in 1.6."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"deprecated in 1.4 and will be removed in 1.6."
"deprecated in 1.5 and will be removed in 1.7."

@@ -1157,6 +1186,11 @@ def paired_euclidean_distances(X, Y):
return row_norms(X - Y)


# TODO(1.6): Remove in 1.6
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# TODO(1.6): Remove in 1.6
# TODO(1.7): Remove in 1.7

# TODO*1.6: Remove in 1.6
@deprecated(
"The public function `sklearn.pairwise.paired_cosine_distances` has been "
"deprecated in 1.4 and will be removed in 1.6."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"deprecated in 1.4 and will be removed in 1.6."
"deprecated in 1.5 and will be removed in 1.7."

@@ -1201,6 +1260,11 @@ def paired_manhattan_distances(X, Y):
return np.abs(diff).sum(axis=-1)


# TODO*1.6: Remove in 1.6
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# TODO*1.6: Remove in 1.6
# TODO(1.7): Remove in 1.7


# TODO(1.6): Remove in 1.6
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# TODO(1.6): Remove in 1.6
# TODO(1.7): Remove in 1.7

# TODO(1.6): Remove in 1.6
@deprecated(
"The public function `sklearn.pairwise.paired_distances` has been "
"deprecated in 1.4 and will be removed in 1.6."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"deprecated in 1.4 and will be removed in 1.6."
"deprecated in 1.5 and will be removed in 1.7."

@@ -275,10 +275,6 @@ def _check_function_param_validation(
"sklearn.metrics.pairwise.linear_kernel",
"sklearn.metrics.pairwise.manhattan_distances",
"sklearn.metrics.pairwise.nan_euclidean_distances",
"sklearn.metrics.pairwise.paired_cosine_distances",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this still needs to be reverted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module:metrics Waiting for Second Reviewer First reviewer is done, need a second one!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

API Deprecate paired_distances and paired_*_distances
5 participants