diff --git a/CHANGELOG.md b/CHANGELOG.md index 9104972..276c26b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.8.0] - 2022-01-06 + +### Changed + +- Minor changes to make tests pass with new matchms versions (>=0.18.0). Should nearly always be backwards compatible though. +- Now dependency requirement is set to `matchms>=0.14.0` + ## [0.7.0] - 2022-10-01 ### Added @@ -135,7 +142,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fossa configuration - Flowchart -[Unreleased]: https://github.com/iomega/spec2vec/compare/0.7.0...HEAD +[Unreleased]: https://github.com/iomega/spec2vec/compare/0.8.0...HEAD +[0.8.0]: https://github.com/iomega/spec2vec/compare/0.6.0...0.7.0 [0.7.0]: https://github.com/iomega/spec2vec/compare/0.6.0...0.7.0 [0.6.0]: https://github.com/iomega/spec2vec/compare/0.5.0...0.6.0 [0.5.0]: https://github.com/iomega/spec2vec/compare/0.4.0...0.5.0 diff --git a/conda/meta.yaml b/conda/meta.yaml index 5c95da1..f188996 100644 --- a/conda/meta.yaml +++ b/conda/meta.yaml @@ -1,5 +1,5 @@ {% set name = "spec2vec" %} -{% set version = "0.7.0" %} +{% set version = "0.8.0" %} package: name: {{ name|lower }} @@ -37,7 +37,7 @@ requirements: - setuptools run: - gensim >=4.2.0 - - matchms >=0.6.0 + - matchms >=0.14.0 - numba >=0.51 - numpy - pip diff --git a/integration-tests/test_user_workflow_spec2vec.py b/integration-tests/test_user_workflow_spec2vec.py index a505c84..6012eeb 100644 --- a/integration-tests/test_user_workflow_spec2vec.py +++ b/integration-tests/test_user_workflow_spec2vec.py @@ -1,6 +1,6 @@ import os import gensim -import pytest +import numpy as np from matchms import calculate_scores from matchms.filtering import (add_losses, add_parent_mass, default_filters, normalize_intensities, @@ -68,16 +68,18 @@ def apply_my_filters(s): actual_top10 = sorted_by_score[:10] expected_top10 = [ - (documents[19], documents[25], pytest.approx(0.9999121928249473, rel=1e-9)), - (documents[20], documents[25], pytest.approx(0.9998846890269892, rel=1e-9)), - (documents[20], documents[45], pytest.approx(0.9998756073673759, rel=1e-9)), - (documents[25], documents[45], pytest.approx(0.9998750427994474, rel=1e-9)), - (documents[19], documents[27], pytest.approx(0.9998722768460854, rel=1e-9)), - (documents[22], documents[27], pytest.approx(0.9998633023352553, rel=1e-9)), - (documents[18], documents[27], pytest.approx(0.9998616961532616, rel=1e-9)), - (documents[19], documents[45], pytest.approx(0.9998528723697396, rel=1e-9)), - (documents[14], documents[71], pytest.approx(0.9998404364805897, rel=1e-9)), - (documents[20], documents[27], pytest.approx(0.9998336807761137, rel=1e-9)) + (documents[19], documents[25], 0.9999121928249473), + (documents[20], documents[25], 0.9998846890269892), + (documents[20], documents[45], 0.9998756073673759), + (documents[25], documents[45], 0.9998750427994474), + (documents[19], documents[27], 0.9998722768460854), + (documents[22], documents[27], 0.9998633023352553), + (documents[18], documents[27], 0.9998616961532616), + (documents[19], documents[45], 0.9998528723697396), + (documents[14], documents[71], 0.9998404364805897), + (documents[20], documents[27], 0.9998336807761137) ] - assert actual_top10 == expected_top10, "Expected different top 10 table." + assert [x[0] for x in actual_top10] == [x[0] for x in expected_top10] + assert [x[1] for x in actual_top10] == [x[1] for x in expected_top10] + assert np.allclose([x[2][0] for x in actual_top10], [x[2] for x in expected_top10]), "Expected different top 10 table." diff --git a/setup.cfg b/setup.cfg index 2e6ea60..9ed1c30 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 0.7.0 +current_version = 0.8.0 [bumpversion:file:conda/meta.yaml] search = set version = "{current_version}" diff --git a/setup.py b/setup.py index 961b8c6..c5da5f5 100644 --- a/setup.py +++ b/setup.py @@ -47,7 +47,7 @@ python_requires='>=3.7', install_requires=[ "gensim >=4.2.0", - "matchms <0.18.0", + "matchms >=0.14.0", "numba >=0.51", "numpy", "scipy", diff --git a/spec2vec/Spec2Vec.py b/spec2vec/Spec2Vec.py index db96447..cf009c9 100644 --- a/spec2vec/Spec2Vec.py +++ b/spec2vec/Spec2Vec.py @@ -134,6 +134,7 @@ def pair(self, reference: Union[SpectrumDocument, Spectrum], def matrix(self, references: Union[List[SpectrumDocument], List[Spectrum]], queries: Union[List[SpectrumDocument], List[Spectrum]], + array_type: str = "numpy", is_symmetric: bool = False) -> np.ndarray: """Calculate the spec2vec similarities between all references and queries. @@ -143,6 +144,10 @@ def matrix(self, references: Union[List[SpectrumDocument], List[Spectrum]], Reference spectrums or spectrum documents. queries: Query spectrums or spectrum documents. + array_type + Specify the output array type. Can be "numpy" or "sparse". + Currently, only "numpy" is supported and will return a numpy array. + Future versions will include "sparse" as option to return a COO-sparse array. is_symmetric: Set to True if references == queries to speed up calculation about 2x. Uses the fact that in this case score[i, j] = score[j, i]. Default is False. diff --git a/spec2vec/__version__.py b/spec2vec/__version__.py index a71c5c7..32a90a3 100644 --- a/spec2vec/__version__.py +++ b/spec2vec/__version__.py @@ -1 +1 @@ -__version__ = '0.7.0' +__version__ = '0.8.0' diff --git a/spec2vec/serialization/model_importing.py b/spec2vec/serialization/model_importing.py index 1e03d1f..8459ad3 100644 --- a/spec2vec/serialization/model_importing.py +++ b/spec2vec/serialization/model_importing.py @@ -38,9 +38,12 @@ def build(self) -> KeyedVectors: def from_dict(self, dictionary: dict): expected_keys = {"vector_size", "__numpys", "__scipys", "__ignoreds", "__recursive_saveloads", - "index_to_key", "norms", "key_to_index", "next_index", "__weights_format"} + "index_to_key", "norms", "key_to_index", "__weights_format"} if dictionary.keys() == expected_keys: self.__dict__ = dictionary + elif expected_keys.symmetric_difference(dictionary.keys()) == {"next_index"}: # backward compatibility + dictionary.pop("next_index") + self.__dict__ = dictionary else: raise ValueError("The keys of model's dictionary representation do not match the expected keys.") return self