Skip to content

MNT Deprecate paired_*_distances and paired_distances public functions - #33809

Open
Pedrom2002 wants to merge 3 commits into
scikit-learn:mainfrom
Pedrom2002:deprecate-paired-distances
Open

Pedrom2002 wants to merge 3 commits into
scikit-learn:mainfrom
Pedrom2002:deprecate-paired-distances

Conversation

@Pedrom2002

Copy link
Copy Markdown

Reference Issues/PRs

Continues the stalled #30537 (which in turn continued #27129). Fixes #26982.

The original author (@SuccessMoses) was last active on the branch in December 2024 and did not respond to the maintainer re-ping in July 2025. Work has been picked up with full credit preserved (see commit trailers and changelog).

What does this implement/fix?

Deprecates the four public metrics.pairwise functions
paired_distances, paired_euclidean_distances,
paired_manhattan_distances and paired_cosine_distances via the
@deprecated decorator. Deprecation targets 1.10; removal scheduled
for 1.12.

Internal callers (only sklearn.cluster._agglomerative.linkage_tree)
now go through module-private _paired_* helpers so they do not
trigger the deprecation warnings on their own use. The
PAIRED_DISTANCES dict is kept under the same name (per review
feedback in #30537) but its values are repointed to the private
implementations.

Changes relative to #30537

Addresses all outstanding review comments from @StefanieSenger:

  • Bumped versions to reflect the current release window: deprecate in
    1.10, remove in 1.12 (was 1.7/1.9 and then 1.8/1.10).
  • Kept the original public-facing docstrings/examples on the
    deprecated functions (the prior iteration had changed them to
    reference the private _paired_* counterparts, which we do not want
    to expose in API docs).
  • Kept the name PAIRED_DISTANCES (no rename to _PAIRED_DISTANCES)
    so no other import sites need to change.
  • Used @ignore_warnings(category=FutureWarning) as a decorator for
    the new parametrized test_deprecated_function_param_validation,
    per the suggestion to use the context manager / decorator form.
  • Added @Shreesha3112 to the changelog alongside @SuccessMoses.

Test plan

  • pytest sklearn/metrics/tests/test_pairwise.py -k paired
  • pytest sklearn/tests/test_public_functions.py -k paired
  • pytest sklearn/cluster/tests/test_hierarchical.py (sanity
    check for internal _paired_distances call site)
  • pytest sklearn/metrics/tests/test_common.py -k array_api

Notes:

  • The new test_paired_distances_deprecation asserts the
    FutureWarning is raised for each of the four deprecated public
    functions.
  • test_deprecated_function_param_validation keeps param-validation
    coverage while silencing the expected FutureWarning.

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]>
Pedrom2002 and others added 2 commits April 20, 2026 15:03
These public functions are deprecated in 1.10 and will be removed in
1.12; promoting their array-api support would mislead users.
Keep the :func:\`paired_*_distances\` entries in \`doc/api_reference.py\`
so the deprecated pages stay reachable during the removal cycle.

Co-authored-by: Success Moses <[email protected]>
Co-authored-by: Shreesha Kumar Bhat <[email protected]>
The CI runs doctests with SKLEARN_WARNINGS_AS_ERRORS=1, which elevates
the FutureWarning emitted by the @deprecated decorator to an exception
and breaks the doctests for the four paired_*_distances examples. Keep
the examples visible in the rendered docs but skip their execution with
# doctest: +SKIP until the functions are removed.

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

Copy link
Copy Markdown

Hi @Pedrom2002
Just noticed this PR has some merge conflicts and a failing changelog check
Are you planning to rebase this soon, or would you be open to me picking it up and pushing it across the finish line for the upcoming release?
Happy to help either way

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