Skip to content

Commit b7fdd00

Browse files
Merge pull request #88 from iomega/matchms_0_18
Move to matchms >=0.18.0
2 parents b1edf87 + 248c4c0 commit b7fdd00

File tree

8 files changed

+37
-19
lines changed

8 files changed

+37
-19
lines changed

CHANGELOG.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [0.8.0] - 2022-01-06
11+
12+
### Changed
13+
14+
- Minor changes to make tests pass with new matchms versions (>=0.18.0). Should nearly always be backwards compatible though.
15+
- Now dependency requirement is set to `matchms>=0.14.0`
16+
1017
## [0.7.0] - 2022-10-01
1118

1219
### Added
@@ -135,7 +142,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
135142
- Fossa configuration
136143
- Flowchart
137144

138-
[Unreleased]: https://github.com/iomega/spec2vec/compare/0.7.0...HEAD
145+
[Unreleased]: https://github.com/iomega/spec2vec/compare/0.8.0...HEAD
146+
[0.8.0]: https://github.com/iomega/spec2vec/compare/0.6.0...0.7.0
139147
[0.7.0]: https://github.com/iomega/spec2vec/compare/0.6.0...0.7.0
140148
[0.6.0]: https://github.com/iomega/spec2vec/compare/0.5.0...0.6.0
141149
[0.5.0]: https://github.com/iomega/spec2vec/compare/0.4.0...0.5.0

conda/meta.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{% set name = "spec2vec" %}
2-
{% set version = "0.7.0" %}
2+
{% set version = "0.8.0" %}
33

44
package:
55
name: {{ name|lower }}
@@ -37,7 +37,7 @@ requirements:
3737
- setuptools
3838
run:
3939
- gensim >=4.2.0
40-
- matchms >=0.6.0
40+
- matchms >=0.14.0
4141
- numba >=0.51
4242
- numpy
4343
- pip

integration-tests/test_user_workflow_spec2vec.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os
22
import gensim
3-
import pytest
3+
import numpy as np
44
from matchms import calculate_scores
55
from matchms.filtering import (add_losses, add_parent_mass, default_filters,
66
normalize_intensities,
@@ -68,16 +68,18 @@ def apply_my_filters(s):
6868
actual_top10 = sorted_by_score[:10]
6969

7070
expected_top10 = [
71-
(documents[19], documents[25], pytest.approx(0.9999121928249473, rel=1e-9)),
72-
(documents[20], documents[25], pytest.approx(0.9998846890269892, rel=1e-9)),
73-
(documents[20], documents[45], pytest.approx(0.9998756073673759, rel=1e-9)),
74-
(documents[25], documents[45], pytest.approx(0.9998750427994474, rel=1e-9)),
75-
(documents[19], documents[27], pytest.approx(0.9998722768460854, rel=1e-9)),
76-
(documents[22], documents[27], pytest.approx(0.9998633023352553, rel=1e-9)),
77-
(documents[18], documents[27], pytest.approx(0.9998616961532616, rel=1e-9)),
78-
(documents[19], documents[45], pytest.approx(0.9998528723697396, rel=1e-9)),
79-
(documents[14], documents[71], pytest.approx(0.9998404364805897, rel=1e-9)),
80-
(documents[20], documents[27], pytest.approx(0.9998336807761137, rel=1e-9))
71+
(documents[19], documents[25], 0.9999121928249473),
72+
(documents[20], documents[25], 0.9998846890269892),
73+
(documents[20], documents[45], 0.9998756073673759),
74+
(documents[25], documents[45], 0.9998750427994474),
75+
(documents[19], documents[27], 0.9998722768460854),
76+
(documents[22], documents[27], 0.9998633023352553),
77+
(documents[18], documents[27], 0.9998616961532616),
78+
(documents[19], documents[45], 0.9998528723697396),
79+
(documents[14], documents[71], 0.9998404364805897),
80+
(documents[20], documents[27], 0.9998336807761137)
8181
]
8282

83-
assert actual_top10 == expected_top10, "Expected different top 10 table."
83+
assert [x[0] for x in actual_top10] == [x[0] for x in expected_top10]
84+
assert [x[1] for x in actual_top10] == [x[1] for x in expected_top10]
85+
assert np.allclose([x[2][0] for x in actual_top10], [x[2] for x in expected_top10]), "Expected different top 10 table."

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 0.7.0
2+
current_version = 0.8.0
33

44
[bumpversion:file:conda/meta.yaml]
55
search = set version = "{current_version}"

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
python_requires='>=3.7',
4848
install_requires=[
4949
"gensim >=4.2.0",
50-
"matchms <0.18.0",
50+
"matchms >=0.14.0",
5151
"numba >=0.51",
5252
"numpy",
5353
"scipy",

spec2vec/Spec2Vec.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ def pair(self, reference: Union[SpectrumDocument, Spectrum],
134134

135135
def matrix(self, references: Union[List[SpectrumDocument], List[Spectrum]],
136136
queries: Union[List[SpectrumDocument], List[Spectrum]],
137+
array_type: str = "numpy",
137138
is_symmetric: bool = False) -> np.ndarray:
138139
"""Calculate the spec2vec similarities between all references and queries.
139140
@@ -143,6 +144,10 @@ def matrix(self, references: Union[List[SpectrumDocument], List[Spectrum]],
143144
Reference spectrums or spectrum documents.
144145
queries:
145146
Query spectrums or spectrum documents.
147+
array_type
148+
Specify the output array type. Can be "numpy" or "sparse".
149+
Currently, only "numpy" is supported and will return a numpy array.
150+
Future versions will include "sparse" as option to return a COO-sparse array.
146151
is_symmetric:
147152
Set to True if references == queries to speed up calculation about 2x.
148153
Uses the fact that in this case score[i, j] = score[j, i]. Default is False.

spec2vec/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '0.7.0'
1+
__version__ = '0.8.0'

spec2vec/serialization/model_importing.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,12 @@ def build(self) -> KeyedVectors:
3838

3939
def from_dict(self, dictionary: dict):
4040
expected_keys = {"vector_size", "__numpys", "__scipys", "__ignoreds", "__recursive_saveloads",
41-
"index_to_key", "norms", "key_to_index", "next_index", "__weights_format"}
41+
"index_to_key", "norms", "key_to_index", "__weights_format"}
4242
if dictionary.keys() == expected_keys:
4343
self.__dict__ = dictionary
44+
elif expected_keys.symmetric_difference(dictionary.keys()) == {"next_index"}: # backward compatibility
45+
dictionary.pop("next_index")
46+
self.__dict__ = dictionary
4447
else:
4548
raise ValueError("The keys of model's dictionary representation do not match the expected keys.")
4649
return self

0 commit comments

Comments
 (0)