Skip to content

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

Open
SuccessMoses wants to merge 6 commits into
scikit-learn:mainfrom
SuccessMoses:deprecate_funcs
Open

SuccessMoses wants to merge 6 commits into
scikit-learn:mainfrom
SuccessMoses:deprecate_funcs

Conversation

@SuccessMoses

@SuccessMoses SuccessMoses commented Dec 24, 2024 •

Copy link
Copy Markdown
Contributor

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

@github-actions

github-actions Bot commented Dec 24, 2024 •

Copy link
Copy Markdown

✔️ 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
Copy Markdown
Member

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

@StefanieSenger StefanieSenger left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown
Member

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
Copy Markdown
Member

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
Copy Markdown
Member

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
Copy Markdown
Member

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.

"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
Copy Markdown
Member

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.

# Paired distances


# TODO(1.9): Remove in 1.9

Copy link
Copy Markdown
Member

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.

@StefanieSenger

Copy link
Copy Markdown
Member

Hi @SuccessMoses, are you still working on this?
There's no rush to finish it fast in any case. ☺️
I would just set a help wanted label otherwise to get this deprecation into the next release in November.

Pedrom2002 added a commit to Pedrom2002/scikit-learn that referenced this pull request Apr 20, 2026
Deprecates `paired_distances`, `paired_euclidean_distances`,
`paired_manhattan_distances` and `paired_cosine_distances` in 1.10;
removal scheduled for 1.12. Internal callers now use module-private
`_paired_*` helpers to avoid triggering the deprecation warnings on
their own use. The `PAIRED_DISTANCES` dict is kept (same name) and
repointed to the private implementations.

Continues the stalled work in scikit-learn#30537 (originally based on scikit-learn#27129).

Co-authored-by: Success Moses <[email protected]>
Co-authored-by: Shreesha Kumar Bhat <[email protected]>

This branch has not been deployed

No deployments
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