scikit-learn icon indicating copy to clipboard operation
scikit-learn copied to clipboard

DOC Fix off-by-one indexing error in paired_manhattan_distances

Open shipitdev opened this issue 5 months ago • 3 comments

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!

shipitdev avatar Jun 21 '26 03:06 shipitdev

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[bot] avatar Jun 21 '26 03:06 github-actions[bot]

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 avatar Jun 21 '26 03:06 shipitdev

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!

shipitdev avatar Jun 30 '26 11:06 shipitdev

@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 :)

shipitdev avatar Jul 01 '26 13:07 shipitdev

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 avatar Jul 02 '26 13:07 shipitdev

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 avatar Jul 03 '26 05:07 shipitdev

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 avatar Jul 03 '26 17:07 shipitdev

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

shipitdev avatar Jul 05 '26 09:07 shipitdev