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

Skip to content

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

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

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

Conversation

SuccessMoses
Copy link
Contributor

@SuccessMoses SuccessMoses commented Dec 24, 2024

Reference Issues/PRs

This PR is continues the stalled #27129 (closes #27129). And fixes #26982.

What does this implement/fix? Explain your changes.

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

Any other comments?

This may be required for #26961

Copy link

github-actions bot commented Dec 24, 2024

✔️ Linting Passed

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

Generated for commit: 3bedd77. Link to the linter CI: here

@StefanieSenger
Copy link
Contributor

I am just commenting to let you know that we are short in reviewers and in time.

Your efforts are very appreciated @SuccessMoses!

I am sorry we cannot grant you a more timely response.

@StefanieSenger StefanieSenger self-requested a review June 19, 2025 08:40
Copy link
Contributor

@StefanieSenger StefanieSenger left a comment

Choose a reason for hiding this comment

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

Hello @SuccessMoses,

thanks for picking the PR up and finishing it. I looked through and have added a few review comments. Especially, we should keep the public function names in the examples section to not expose private functions.

: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.9. By :user:`Success Moses <SuccessMoses>`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
will be removed in 1.9. By :user:`Success Moses <SuccessMoses>`.
will be removed in 1.9. By :user:`Success Moses <SuccessMoses>` and
:user:`Shreesha Kumar Bhat<Shreesha3112>`.

Let's also mention @Shreesha3112, who had done the first PR this one is based on.

Comment on lines -1215 to +1225
>>> from sklearn.metrics.pairwise import paired_euclidean_distances
>>> from sklearn.metrics.pairwise import _paired_euclidean_distances
>>> X = [[0, 0, 0], [1, 1, 1]]
>>> Y = [[1, 0, 0], [1, 1, 0]]
>>> paired_euclidean_distances(X, Y)
>>> _paired_euclidean_distances(X, Y)
Copy link
Contributor

Choose a reason for hiding this comment

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

I would leave that as it was, for two reasons:

  1. There is no need, since users can still use these functions as they were until they get removed .
  2. We should not expose our internal functions to users in the API docs, because these can be subject of change in the future and we want to be able to do that without a deprecation cycle.

This comment is applicable to all of the 4 deprecated functions.

Comment on lines +1432 to +1433
# TODO(1.9): Remove PAIRED_DISTANCES dictionary since pairwise_*_distance public
# functions are deprecated in 1.9
Copy link
Contributor

Choose a reason for hiding this comment

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

I think I would tend to keep PAIRED_DISTANCES and not go through the renaming (so we don't need to change the imports in other files). The mention of this dict will be gone after removing the functions that use them from the public API anyways.

Comment on lines -281 to -284
"sklearn.metrics.pairwise.paired_cosine_distances",
"sklearn.metrics.pairwise.paired_distances",
"sklearn.metrics.pairwise.paired_euclidean_distances",
"sklearn.metrics.pairwise.paired_manhattan_distances",
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't really mind, just wanted to comment on that: A leaner way would be to use ignore_warnings from sklearn/utils/_testing.py that can also be used as a context manager and it could be done in the same testing function. It doesn't really matter in a practical sense, but would be the more conventional way in scikit-learn.

@deprecated(
"The public function `sklearn.pairwise.paired_euclidean_distances` has been "
"deprecated in 1.7 and will be removed in 1.9."
)
@validate_params(
Copy link
Contributor

Choose a reason for hiding this comment

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

We could consider to also apply the validate_params() decorator on the private functions, but it doesn't matter so much.

@@ -1187,6 +1187,13 @@ def cosine_distances(X, Y=None):


# Paired distances


# TODO(1.9): Remove in 1.9
Copy link
Contributor

Choose a reason for hiding this comment

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

Now, the versions in this whole PR have to be changed from 1.7 for deprecation to 1.8 and from 1.9 for removal to 1.10.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

API Deprecate paired_distances and paired_*_distances
2 participants