Skip to content

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

Closed
Shreesha3112 wants to merge 13 commits into
scikit-learn:mainfrom
Shreesha3112:deprecate_pairwise_distance_public_funcs
Closed

Shreesha3112 wants to merge 13 commits into
scikit-learn:mainfrom
Shreesha3112:deprecate_pairwise_distance_public_funcs

Conversation

@Shreesha3112

@Shreesha3112 Shreesha3112 commented Aug 22, 2023 •

Copy link
Copy Markdown
Contributor

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

github-actions Bot commented Aug 22, 2023 •

Copy link
Copy Markdown

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

ogrisel commented Aug 22, 2023

Copy link
Copy Markdown
Member

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

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

@glemaitre glemaitre 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.

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.

Comment thread sklearn/metrics/pairwise.py Resolved
Comment thread sklearn/metrics/pairwise.py Resolved
Comment thread sklearn/metrics/pairwise.py Resolved
Comment thread sklearn/metrics/pairwise.py Resolved
Comment thread sklearn/metrics/pairwise.py Resolved
Comment thread sklearn/metrics/tests/test_pairwise.py Resolved
Comment thread sklearn/metrics/tests/test_pairwise.py Resolved
Comment thread sklearn/metrics/tests/test_pairwise.py Resolved
Comment thread sklearn/metrics/tests/test_pairwise.py Resolved
"sklearn.metrics.pairwise.linear_kernel",
"sklearn.metrics.pairwise.manhattan_distances",
"sklearn.metrics.pairwise.nan_euclidean_distances",
"sklearn.metrics.pairwise.paired_cosine_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 would still test them but add a comment above to remove them.

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 this still needs to be reverted.

@glemaitre glemaitre 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.

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 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.

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 <[email protected]>

@amueller amueller 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.

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

@thomasjpfan thomasjpfan 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.

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.

Comment thread doc/modules/classes.rst
metrics.pairwise.paired_euclidean_distances
metrics.pairwise.paired_manhattan_distances
metrics.pairwise.paired_cosine_distances
metrics.pairwise.paired_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.

Can these be moved to

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

Comment thread doc/whats_new/v1.4.rst
: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
Copy Markdown
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.

return S


# TODO(1.6): Remove in 1.6

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
# 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
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
"deprecated in 1.4 and will be removed in 1.6."
"deprecated in 1.5 and will be removed in 1.7."

return row_norms(X - Y)


# TODO(1.6): Remove in 1.6

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
# 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
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
"deprecated in 1.4 and will be removed in 1.6."
"deprecated in 1.5 and will be removed in 1.7."

return np.abs(diff).sum(axis=-1)


# TODO*1.6: Remove in 1.6

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
# TODO*1.6: Remove in 1.6
# TODO(1.7): Remove in 1.7

}


# TODO(1.6): Remove in 1.6

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
# 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
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
"deprecated in 1.4 and will be removed in 1.6."
"deprecated in 1.5 and will be removed in 1.7."

"sklearn.metrics.pairwise.linear_kernel",
"sklearn.metrics.pairwise.manhattan_distances",
"sklearn.metrics.pairwise.nan_euclidean_distances",
"sklearn.metrics.pairwise.paired_cosine_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 think this still needs to be reverted.

@Micky774

Copy link
Copy Markdown
Contributor

@Shreesha3112 since the core work is done, and all that remains is some small tidying, I wanted to remind you of this in case you'd still like to finish!

@Sean-Jay-M

Sean-Jay-M commented Oct 29, 2024 •

Copy link
Copy Markdown
Contributor

@Shreesha3112 since the core work is done, and all that remains is some small tidying, I wanted to remind you of this in case you'd still like to finish!

@Micky774, @thomasjpfan Is this considered stalled ?

I'll take a look at cleaning this up and finishing it since it appears @Shreesha3112 has gone dormant. Will start in the coming days if we get no response.

@SuccessMoses

Copy link
Copy Markdown
Contributor

@Sean-Jay-M are you working on this?

@Sean-Jay-M

Sean-Jay-M commented Dec 23, 2024 •

Copy link
Copy Markdown
Contributor

@Sean-Jay-M are you working on this?

Hey I'm not currently working on this. Trying to close out a different PR. Feel free to take the issue. I never got a response from the maintainers if it should be considered a stalled PR. I think should be considered stalled.

@Micky774

Copy link
Copy Markdown
Contributor

Yes at this point the PR is stalled and continuation of the effort is welcomed!

@lesteve

lesteve commented Jul 31, 2025 •

Copy link
Copy Markdown
Member

Closing this one, since the more recent PR #30537 is slightly more likely to be merged one day. Thanks for your work on this @Shreesha3112 anyway!

@lesteve lesteve closed this Jul 31, 2025
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]>
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

10 participants