Skip to content

Use scipy cdist to calculate distance matrix #133

Open
mikemhenry wants to merge 2 commits intomainfrom
fix/issue_57
Open

Use scipy cdist to calculate distance matrix #133
mikemhenry wants to merge 2 commits intomainfrom
fix/issue_57

Conversation

@mikemhenry
Copy link
Contributor

@mikemhenry mikemhenry commented Feb 13, 2026

Checklist

  • All new code is appropriately documented (user-facing code must have complete docstrings).
  • Added a news entry, or the changes are not user-facing.
  • Ran pre-commit: you can run pre-commit locally or comment on this PR with pre-commit.ci autofix.

Developers certificate of origin

Fixes issue #57

@github-actions
Copy link

No API break detected ✅

@codecov
Copy link

codecov bot commented Feb 13, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.17%. Comparing base (8aab3c5) to head (bc04fee).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #133      +/-   ##
==========================================
- Coverage   98.18%   98.17%   -0.02%     
==========================================
  Files          13       13              
  Lines         661      656       -5     
==========================================
- Hits          649      644       -5     
  Misses         12       12              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@IAlibay IAlibay left a comment

Choose a reason for hiding this comment

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

Couple things, mostly re: intent on adding extra arguments if we aren't planning to ever use them internally.

Also inconsistencies in typing.

] = vector_eucledean_dist,
]
| str = "euclidean",
metric_kwargs: dict = {},
Copy link
Member

Choose a reason for hiding this comment

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

Why is this being added? It's a private method, so unless you're planning on expanding the method it's best to assume it will never be used.

position matrix B
metric : Callable[[Union[float, Iterable], Union[float, Iterable]],
Union[float, Iterable]], optional
Union[float, Iterable]] | str, optional
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't match your signature. Again, unless we intend someone to pass through a str here (i.e. it will be called somewhere lese in the class for other reasons), then I would just leave it as a callable?

Also, it's not optional by function kwarg typing, should it be optional here?

metric: eucledean distance. See
https://docs.scipy.org/doc/scipy/reference/generated/scipy.spatial.distance.cdist.html#scipy.spatial.distance.cdist
for other options.
metric_kwargs: dict, optional
Copy link
Member

Choose a reason for hiding this comment

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

As above, also the function typing isn't opptional, should it be?

https://docs.scipy.org/doc/scipy/reference/generated/scipy.spatial.distance.cdist.html#scipy.spatial.distance.cdist
for other options.
metric_kwargs: dict, optional
Extra arguemnts to metric, see https://docs.scipy.org/doc/scipy/reference/generated/scipy.spatial.distance.cdist.html#scipy.spatial.distance.cdist
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Extra arguemnts to metric, see https://docs.scipy.org/doc/scipy/reference/generated/scipy.spatial.distance.cdist.html#scipy.spatial.distance.cdist
Extra arguements to metric, see https://docs.scipy.org/doc/scipy/reference/generated/scipy.spatial.distance.cdist.html#scipy.spatial.distance.cdist

@mikemhenry
Copy link
Contributor Author

I was trying to match the functionality of the old way it worked (you could pass in a callable) and merge it with cdist (you can pass in a string OR a callable).

I don't think we really need to support different metrics, so I rather just hard-code Euclidean and make this much more simple, is that okay @IAlibay ?

@IAlibay
Copy link
Member

IAlibay commented Feb 16, 2026

I don't think we really need to support different metrics, so I rather just hard-code Euclidean and make this much more simple, is that okay @IAlibay ?

Works for me! Fewer options == less testing needed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants