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

Support Python 3.9 #68

Merged
merged 14 commits into from
Nov 25, 2021
7 changes: 5 additions & 2 deletions .github/workflows/CI_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install -e .[dev]
- name: Show pip list
run: |
pip list
- name: Test with coverage
run: |
pytest --cov --cov-report term --cov-report xml --junitxml=xunit-result.xml
Expand All @@ -50,7 +53,7 @@ jobs:
fail-fast: false
matrix:
os: ['ubuntu-latest', 'macos-latest', 'windows-latest']
python-version: ['3.7', '3.8']
python-version: ['3.7', '3.8', '3.9']
exclude:
# already tested in first_check job
- python-version: 3.8
Expand Down Expand Up @@ -160,7 +163,7 @@ jobs:
fail-fast: false
matrix:
os: ['ubuntu-latest', 'macos-latest', 'windows-latest']
python-version: ['3.7', '3.8']
python-version: ['3.7', '3.8', '3.9']
runs-on: ${{ matrix.os }}
needs: anaconda_build
steps:
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## Added

- Now supports Python 3.9 (including CI test runs) [#40](https://github.com/iomega/spec2vec/issues/40)

## [0.5.0] - 2021-06-18

## Changed
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ Installation

Prerequisites:

- Python 3.7 or 3.8
- Python 3.7, 3.8, or 3.9
- Recommended: Anaconda

We recommend installing spec2vec from Anaconda Cloud with
Expand Down
2 changes: 1 addition & 1 deletion conda/environment-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ dependencies:
- anaconda-client
- conda-build
- conda-verify
- python >=3.7,<3.9
- python >=3.7
2 changes: 1 addition & 1 deletion conda/environment-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ dependencies:
- numba >=0.51
- numpy
- pip
- python >=3.7,<3.9
- python >=3.7
- tqdm
- pip:
- -e ..[dev]
2 changes: 1 addition & 1 deletion conda/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ dependencies:
- matchms >=0.6.2
- numba >=0.51
- numpy
- python >=3.7,<3.9
- python >=3.7
- tqdm
4 changes: 2 additions & 2 deletions conda/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ requirements:
- numpy {{ numpy }}
- setuptools
host:
- python >=3.7,<3.9
- python >=3.7
- pip
- pytest-runner
- setuptools
Expand All @@ -41,7 +41,7 @@ requirements:
- numba >=0.51
- numpy
- pip
- python >=3.7,<3.9
- python >=3.7
- tqdm

test:
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
],
extras_require={"dev": ["bump2version",
"isort>=4.2.5,<5",
"pylint<2.12.0",
"prospector[with_pyroma]",
"pytest",
"pytest-cov",
Expand Down
5 changes: 2 additions & 3 deletions spec2vec/SpectrumDocument.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,9 @@ def __init__(self, spectrum, n_decimals: int = 2):

def _make_words(self):
"""Create word from peaks (and losses)."""
format_string = "{}@{:." + "{}".format(self.n_decimals) + "f}"
peak_words = [format_string.format("peak", mz) for mz in self._obj.peaks.mz]
peak_words = [f"peak@{mz:.{self.n_decimals}f}" for mz in self._obj.peaks.mz]
if self._obj.losses is not None:
loss_words = [format_string.format("loss", mz) for mz in self._obj.losses.mz]
loss_words = [f"loss@{mz:.{self.n_decimals}f}" for mz in self._obj.losses.mz]
else:
loss_words = []
self.words = peak_words + loss_words
Expand Down
11 changes: 5 additions & 6 deletions spec2vec/model_building.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,11 @@ def set_spec2vec_defaults(**settings):
assert "alpha" not in settings, "Expect 'learning_rate_initial' instead of 'alpha'."

# Set default parameters or replace by **settings input
for key in defaults:
for key, value in defaults.items():
if key in settings:
print("The value of {} is set from {} (default) to {}".format(key, defaults[key],
settings[key]))
print(f"The value of {key} is set from {value} (default) to {settings[key]}")
else:
settings[key] = defaults[key]
settings[key] = value
return settings


Expand Down Expand Up @@ -166,7 +165,7 @@ def set_learning_rate_decay(learning_rate_initial: float, learning_rate_decay: f
min_alpha = learning_rate_initial - num_of_epochs * learning_rate_decay
if min_alpha < 0:
print("Warning! Number of total iterations is too high for given learning_rate decay.")
print("Learning_rate_decay will be set from {} to {}.".format(learning_rate_decay,
learning_rate_initial/num_of_epochs))
print("Learning_rate_decay will be set from {learning_rate_decay} ",
"to {learning_rate_initial/num_of_epochs}.")
min_alpha = 0
return learning_rate_initial, min_alpha
4 changes: 2 additions & 2 deletions spec2vec/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def on_epoch_end(self, model):
print('\r',
' Epoch ' + str(self.epoch+1) + ' of ' + str(self.num_of_epochs) + '.',
end="")
print('Change in loss after epoch {}: {}'.format(self.epoch+1, loss - self.loss))
print(f'Change in loss after epoch {self.epoch + 1}: {loss - self.loss}')
self.epoch += 1
self.loss = loss

Expand Down Expand Up @@ -56,7 +56,7 @@ def on_epoch_end(self, model):

if self.filename and self.epoch in self.iterations:
if self.epoch < self.num_of_epochs:
filename = self.filename.split(".model")[0] + "_iter_{}.model".format(self.epoch)
filename = f"{self.filename.split('.model')[0]}_iter_{self.epoch}.model"
else:
filename = self.filename
print("Saving model with name:", filename)
Expand Down
4 changes: 2 additions & 2 deletions spec2vec/vector_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ def _check_model_coverage():
weights_missing_raised = numpy.power(weights_missing, intensity_weighting_power)
missing_percentage = 100 * weights_missing_raised.sum() / (weights_raised.sum()
+ weights_missing_raised.sum())
print("Found {} word(s) missing in the model.".format(len(idx_not_in_model)),
"Weighted missing percentage not covered by the given model is {:.2f}%.".format(missing_percentage))
print(f"Found {len(idx_not_in_model)} word(s) missing in the model.",
f"Weighted missing percentage not covered by the given model is {missing_percentage:.2f}%.")

message = ("Missing percentage is larger than set maximum.",
"Consider retraining the used model or increasing the allowed percentage.")
Expand Down
2 changes: 1 addition & 1 deletion tests/test_version_string_consistency.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def test_version_string_consistency():
repository_root = os.path.join(os.path.dirname(__file__), "..")
fixture = os.path.join(repository_root, "conda", "meta.yaml")

with open(fixture, "r") as f:
with open(fixture, "r", encoding="utf-8") as f:
metayaml_contents = f.read()

match = re.search(r"^{% set version = \"(?P<semver>.*)\" %}$", metayaml_contents, re.MULTILINE)
Expand Down