Skip to content

DOC Standardize return descriptions across paired distance functions - #34352

Merged
virchan merged 3 commits into
scikit-learn:mainfrom
shipitdev:fix-Off-by-one-indexing-doc
Jul 9, 2026
Merged

virchan merged 3 commits into
scikit-learn:mainfrom
shipitdev:fix-Off-by-one-indexing-doc

Conversation

@shipitdev

Copy link
Copy Markdown
Contributor

Reference Issues/PRs

Fixes #34315

What does this implement/fix? Explain your changes.

This PR fixes an off-by-one indexing error in the docstring for paired_manhattan_distances within sklearn/metrics/pairwise.py.

The previous docstring stated that distances are calculated up to (X[n_samples], Y[n_samples]). Since Python uses 0-based indexing, attempting to access the n_samples index raises an IndexError in practice. This PR corrects the documentation to accurately reference the final elements as (X[n_samples - 1], Y[n_samples - 1]).

AI usage disclosure

I used AI assistance for:

  • formatting this template

Any other comments?

I've ensured this is fully human-reviewed and conforms to the guidelines. Let me know if anything else is needed!

@github-actions

Copy link
Copy Markdown

Thank you for opening your first pull request to scikit-learn! 🎉

To help get your contribution reviewed, please make sure that:

  • You have filled out the pull request template.
  • The pull request addresses an existing issue that is ready for
    contribution (e.g. not tagged as "Needs Triage", "Needs Decision", ...).
    If you are proposing a new feature, please open an issue to discuss it first.
  • There are no other open pull requests already targeting the same issue.
  • You have followed the pull request checklist.
    In particular, linting and tests should pass.

@github-actions github-actions Bot added module:metrics Documentation CI:Linter failure The linter CI is failing on this PR labels Jun 21, 2026
@shipitdev

Copy link
Copy Markdown
Contributor Author

Hey @virchan! I saw you had to close PR #34349 earlier today because an automated bot tried to blindly fix my issue (#34315).

I was originally holding off on claiming it until the Needs Triage label was officially removed, but to prevent any more AI-spam tools from scraping it and wasting reviewers' time, I went ahead and pushed this manually.

Let me know if this looks good from your end

@shipitdev

shipitdev commented Jun 30, 2026 •

Copy link
Copy Markdown
Contributor Author

gentle ping to the maintainers,

the single failed cython-lint check is on an unrelated file (_dbscan_inner.pyx), please let me know if my docstring fix here is good to go or you need me to adjust anything here. Happy to make any changes!

@github-actions github-actions Bot removed the CI:Linter failure The linter CI is failing on this PR label Jul 1, 2026
@shipitdev

shipitdev commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor Author

@AnneBeyer hi, i have made the changes as you requested please let me know if that’d be all or if you want me to change anything. Thank you for looking into this :)

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

Thank you, @shipitdev! One small nit, otherwise LGTM!

Could you update the title to reflect the new scope as well? (This will become the commit message once this get's merged.)

Comment thread sklearn/metrics/pairwise.py Resolved
Comment thread sklearn/metrics/pairwise.py Resolved
Comment thread sklearn/metrics/pairwise.py Resolved
@AnneBeyer AnneBeyer added Waiting for Second Reviewer First reviewer is done, need a second one! good first PR to review Simple atomic PR to review labels Jul 2, 2026
@shipitdev

Copy link
Copy Markdown
Contributor Author

Thank you, @shipitdev! One small nit, otherwise LGTM!

Could you update the title to reflect the new scope as well? (This will become the commit message once this get's merged.)

oh yes! For sure. I'll update the title to something the covers the scope here

@shipitdev shipitdev changed the title DOC Fix off-by-one indexing error in paired_manhattan_distances DOC Standardize return descriptions across paired distance functions Jul 2, 2026
@shipitdev

Copy link
Copy Markdown
Contributor Author

Thanks so much for the review, @AnneBeyer! Sorry for the delay in applying these, they didn't show up in my GitHub app initially. All fixed now. I really appreciate your time!

@shipitdev
shipitdev force-pushed the fix-Off-by-one-indexing-doc branch from e7ebaa5 to ad4578a Compare July 3, 2026 17:06
@shipitdev
shipitdev force-pushed the fix-Off-by-one-indexing-doc branch from ad4578a to 53c53c5 Compare July 3, 2026 17:08
@shipitdev

Copy link
Copy Markdown
Contributor Author

I apologize for the untidy history and multiple updates over the last few minutes. I was attempting to squash my commits but encountered some rebase issues, so I decided to leave the two commits intact rather than risk losing the changes. Thank you again for the review and your patience!"

@shipitdev

Copy link
Copy Markdown
Contributor Author

@AnneBeyer gentle ping, i'm happy to make any changes. Please let me know if this looks good from your end.

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

Thank you for the PR, @shipitdev. I have a few comments.

def paired_euclidean_distances(X, Y):
"""Compute the paired euclidean distances between X and Y.

Distances are calculated between (X[0], Y[0]), (X[1], Y[1]), ..., etc.

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 this change, as well as its counter-parts in paired_manhattan_distances and paired_cosine_distances. (I.e., #34352 (review).)

The other proposed changes also make sense, but the improvement is too minor to justify merging. Therefore, I suggest reverting them.

@shipitdev shipitdev Jul 6, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

sure, i'll go and revert it back.

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

LGTM! Thanks, @shipitdev!

@virchan
virchan merged commit f01a3b9 into scikit-learn:main Jul 9, 2026
33 checks passed
@jeremiedbb jeremiedbb mentioned this pull request Sep 8, 2026
14 tasks done
jeremiedbb pushed a commit to jeremiedbb/scikit-learn that referenced this pull request Sep 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Documentation good first PR to review Simple atomic PR to review 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.

Off-by-one indexing error in paired_manhattan_distances docstring

3 participants