Skip to content

Commit c003b6c

Browse files
authored
Support Python 3.13 (#227)
Support Python 3.13, including: - [x] torch - [x] cupy - [x] lightfm - [x] pytorch_lightning excluding: - nmslib metabrainz/nmslib-metabrainz#5 - nmslib-metabrainz only supports until Python 3.12.
1 parent 6ffd25b commit c003b6c

13 files changed

Lines changed: 1072 additions & 224 deletions

File tree

.github/workflows/test.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
python-version: "3.10"
2222

2323
- name: Install poetry
24-
run: pip install urllib3==1.26.15 poetry==1.8.3
24+
run: pip install urllib3==1.26.15 poetry==1.8.5
2525

2626
- name: Load cached venv
2727
id: cached-poetry-dependencies
@@ -43,7 +43,7 @@ jobs:
4343
strategy:
4444
fail-fast: false
4545
matrix:
46-
python-version: [ "3.9", "3.10", "3.11", "3.12" ]
46+
python-version: [ "3.9", "3.10", "3.11", "3.12", "3.13" ]
4747

4848
steps:
4949
- uses: actions/checkout@v4
@@ -54,7 +54,7 @@ jobs:
5454
python-version: ${{ matrix.python-version }}
5555

5656
- name: Install poetry
57-
run: pip install urllib3==1.26.15 poetry==1.4.0
57+
run: pip install urllib3==1.26.15 poetry==1.8.5
5858

5959
- name: Load cached venv
6060
id: cached-poetry-dependencies

.readthedocs.yml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,15 @@ build:
77
jobs:
88
pre_build:
99
- cp -r examples docs/source/
10+
post_create_environment:
11+
- pip install poetry
1012
post_install:
11-
- pip install --no-cache-dir poetry==1.8.5
12-
- poetry export -f requirements.txt -o requirements.txt -E all --without-hashes
13-
- pip install --no-cache-dir -r requirements.txt
13+
- VIRTUAL_ENV=$READTHEDOCS_VIRTUALENV_PATH poetry install -E all --no-root --with docs
1414

1515
sphinx:
1616
builder: html
1717
configuration: docs/source/conf.py
1818
fail_on_warning: false
1919

20-
python:
21-
install:
22-
- requirements: docs/requirements.txt
23-
2420
formats:
2521
- pdf

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## Unreleased
9+
10+
### Added
11+
12+
- Python 3.13 support ([#227](https://github.com/MobileTeleSystems/RecTools/pull/227))
13+
814
## [0.13.0] - 10.04.2025
915

1016
### Added

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ install: .venv .reports
6161
poetry run pytest ${TESTS} --cov=${SOURCES} --cov-report=xml
6262

6363
.doctest:
64-
poetry run pytest --doctest-modules ${SOURCES} --ignore=rectools/models/lightfm.py
64+
poetry run pytest --doctest-modules ${SOURCES} --ignore=rectools/tools/ann.py
6565

6666
coverage: .venv .reports
6767
poetry run coverage run --source ${SOURCES} --module pytest

poetry.lock

Lines changed: 976 additions & 191 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ classifiers = [
3838
"Programming Language :: Python :: 3.10",
3939
"Programming Language :: Python :: 3.11",
4040
"Programming Language :: Python :: 3.12",
41+
"Programming Language :: Python :: 3.13",
4142
"Programming Language :: Python :: 3",
4243
"Topic :: Software Development :: Libraries :: Python Modules",
4344
"Intended Audience :: Science/Research",
@@ -52,13 +53,20 @@ packages = [
5253

5354

5455
[tool.poetry.dependencies]
55-
python = ">=3.9, <3.13"
56+
python = ">=3.9, <3.14"
5657
numpy = [
5758
{version = ">=1.22, <2.0.0", python = "<3.12"},
58-
{version = ">=1.26, <2.0.0", python = "3.12"} # numpy <1.26 fails to install on Python 3.12
59+
{version = ">=1.26, <2.0.0", python = "3.12"}, # numpy <1.26 fails to install on Python 3.12
60+
{version = ">=2.1.0, <3.0.0", python = ">=3.13"} # numpy <2.1 fails to install on Python 3.13
61+
]
62+
pandas = [
63+
{version = ">=1.5.0, <3.0.0", python = "<3.13"},
64+
{version = ">=2.2.3, <3.0.0", python = ">=3.13"} # pandas <2.2.3 fails to install on Python 3.13
65+
]
66+
scipy = [
67+
{version = "^1.10.1, <1.13", python = "<3.10"}, # there is a bug in 1.13* https://github.com/scipy/scipy/issues/20670
68+
{version = ">=1.14.1, <2.0.0", python = ">=3.10"} # scipy >=1.14.1 fails to install on Python 3.9
5969
]
60-
pandas = ">=1.5.0, <3.0.0"
61-
scipy = "^1.10.1, <1.13" # in 1.13 were introduced significant changes breaking our logic
6270
tqdm = "^4.27.0"
6371
implicit = "^0.7.1"
6472
attrs = ">=19.1.0,<24.0.0"
@@ -76,16 +84,27 @@ nmslib-metabrainz = {version = "^2.1.3", python = ">=3.11, <3.13", optional = tr
7684

7785
# The latest torch version available for MacOSX + x86_64 is 2.2.2
7886
torch = [
79-
{version = ">=1.6.0, <2.3.0", markers = "sys_platform == 'darwin' and platform_machine == 'x86_64'", optional = true},
80-
{version = ">=1.6.0, <3.0.0", optional = true}
87+
{version = ">=1.6.0, <2.3.0", python = "<3.13", markers = "sys_platform == 'darwin' and platform_machine == 'x86_64'", optional = true},
88+
{version = ">=1.6.0, <3.0.0", python = "<3.13", optional = true},
89+
{version = ">=2.6.0, <3.0.0", python = ">=3.13", optional = true},
90+
]
91+
pytorch-lightning = [
92+
{version = ">=1.6.0, <3.0.0", python = "<3.13", optional = true},
93+
{version = ">=2.5.1, <3.0.0", python = ">=3.13", optional = true},
8194
]
82-
pytorch-lightning = {version = ">=1.6.0, <3.0.0", optional = true}
8395

8496
ipywidgets = {version = ">=7.7,<8.2", optional = true}
8597
plotly = {version="^5.22.0", optional = true}
8698
nbformat = {version = ">=4.2.0", optional = true}
87-
cupy-cuda12x = {version = "^13.3.0", python = "<3.13", optional = true}
88-
99+
cupy-cuda12x = [
100+
{version = "^13.3.0", python = "<3.13", optional = true},
101+
{version = "^13.4.0", python = ">=3.13", optional = true},
102+
]
103+
# This is a dependency of cupy-cuda12x
104+
# poetry can't resolve appropriate version of fastrlock for Python 3.13
105+
# and cupy-cuda12x, so we add the version restriction here manually to avoid
106+
# installing older version of fastrlock which is incompatible with Python 3.13
107+
fastrlock = {version = "^0.8.3", optional = true}
89108

90109
[tool.poetry.extras]
91110
lightfm = ["rectools-lightfm"]
@@ -103,13 +122,13 @@ all = [
103122

104123

105124
[tool.poetry.group.dev.dependencies]
106-
black = "24.4.2"
125+
black = "24.10.0"
107126
isort = "5.13.2"
108127
pylint = "3.1.0"
109128
mypy = "1.13.0"
110129
flake8 = "7.0.0"
111130
bandit = "1.7.8"
112-
pytest = "8.1.1"
131+
pytest = "8.3.3"
113132
radon = "6.0.1"
114133
coverage = "7.5.0"
115134
autopep8 = "2.1.0"
@@ -122,10 +141,17 @@ pytest-mock = "3.14.0"
122141
click = "8.1.7"
123142
gitpython = "3.1.43"
124143

144+
[tool.poetry.group.docs]
145+
optional = true
146+
147+
[tool.poetry.group.docs.dependencies]
148+
sphinx = "5.1.1"
149+
nbsphinx = "0.8.9"
150+
sphinx-rtd-theme = "1.0.0"
125151

126152
[tool.black]
127153
line-length = 120
128-
target-version = ["py39", "py310", "py311", "py312"]
154+
target-version = ["py39", "py310", "py311", "py312", "py313"]
129155

130156

131157
[build-system]

rectools/metrics/scoring.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,4 +220,4 @@ def calc_metrics( # noqa # pylint: disable=too-many-branches,too-many-locals,t
220220
if len(results) < expected_results_len:
221221
warnings.warn("Custom metrics are not supported.")
222222

223-
return results
223+
return {k: v.item() if hasattr(v, "item") else v for k, v in results.items()}

rectools/models/nn/item_net.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,4 +486,4 @@ def forward(self, items: torch.Tensor) -> torch.Tensor:
486486
@property
487487
def out_dim(self) -> int:
488488
"""Return item net constructor output dimension."""
489-
return self.item_net_blocks[0].out_dim
489+
return self.item_net_blocks[0].out_dim # type: ignore[return-value]

rectools/models/nn/transformers/lightning.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ def _calc_bce_loss(cls, logits: torch.Tensor, y: torch.Tensor, w: torch.Tensor)
193193
return loss
194194

195195
def _calc_gbce_loss(self, logits: torch.Tensor, y: torch.Tensor, w: torch.Tensor) -> torch.Tensor:
196-
n_actual_items = self.torch_model.item_model.n_items - len(self.item_extra_tokens)
196+
n_actual_items = tp.cast(int, self.torch_model.item_model.n_items) - len(self.item_extra_tokens)
197197
logits = self._get_reduced_overconfidence_logits(logits, n_actual_items)
198198
loss = self._calc_bce_loss(logits, y, w)
199199
return loss

tests/models/nn/test_dssm.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import numpy as np
1818
import pandas as pd
1919
import pytest
20+
import pytorch_lightning # noqa # pylint: disable=unused-import
2021
from lightning_fabric import seed_everything
2122

2223
from rectools.columns import Columns
@@ -29,8 +30,12 @@
2930

3031
from ..data import INTERACTIONS
3132

33+
filter_warnings_decorator = pytest.mark.filterwarnings(
34+
"ignore::pytorch_lightning.utilities.warnings.PossibleUserWarning"
35+
)
3236

33-
@pytest.mark.filterwarnings("ignore::pytorch_lightning.utilities.warnings.PossibleUserWarning")
37+
38+
@filter_warnings_decorator
3439
@pytest.mark.filterwarnings("ignore::UserWarning")
3540
class TestDSSMModel:
3641
def setup_method(self) -> None:

0 commit comments

Comments
 (0)