Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IndexError in .matrix when all scores are 0 #702

Merged
merged 3 commits into from
Nov 6, 2024

Conversation

tornikeo
Copy link
Contributor

Using .matrix of any similarity, when none of the scores are > 0, gets us an index error. Specifically:

from matchms.similarity import CosineGreedy
from ..builder_Spectrum import SpectrumBuilder

builder = SpectrumBuilder()
spectrum_1 = builder.with_mz(np.array([100, 200, 300], dtype="float")).with_intensities(
    np.array([0.1, 0.2, 1.0], dtype="float")).build()

spectrum_2 = builder.with_mz(np.array([50, 60, 70], dtype="float")).with_intensities(
    np.array([0.5, 0.2, 1.0], dtype="float")).build()

scores = CosineGreedy().matrix([spectrum_1], [spectrum_2]) # IndexError

Will give an index error. This PR adds testcase, and a fix for this.

@hechth hechth mentioned this pull request Nov 6, 2024
5 tasks
@hechth hechth closed this Nov 6, 2024
@hechth hechth reopened this Nov 6, 2024
@hechth hechth merged commit 0ececae into matchms:master Nov 6, 2024
13 checks passed
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