Skip to content

Commit cd68c99

Browse files
authored
Add support for Python 3.13 (#78)
* add support for Python 3.13 * bumping pyo3 and rust-numpy to 0.21 * temporarily remove 3.13 from ci to test that migration of pyo3 and rust-numpy is working. * bumping to 0.22 and adding 3.13 back to ci
1 parent 05334d5 commit cd68c99

File tree

5 files changed

+34
-33
lines changed

5 files changed

+34
-33
lines changed

.github/workflows/ci-tsdownsample.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
matrix:
4747
os: ['windows-latest', 'macOS-latest', 'ubuntu-latest']
4848
rust: ['nightly'] # ['stable', 'beta']
49-
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12']
49+
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12', "3.13"]
5050
exclude: # Python < 3.8 is not supported on Apple Silicon ARM64
5151
- os: macOS-latest
5252
python-version: '3.7'

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ license = "MIT"
99

1010
[dependencies]
1111
downsample_rs = { path = "downsample_rs", features = ["half"]}
12-
pyo3 = { version = "0.20", features = ["extension-module"] }
13-
numpy = { version = "0.20", features = ["half"] }
12+
pyo3 = { version = "0.22", features = ["extension-module"] }
13+
numpy = { version = "0.22", features = ["half"] }
1414
half = { version = "2.3.1", default-features = false }
1515
paste = { version = "1.0.14", default-features = false }
1616

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,21 @@ install-dev-requirements:
1111

1212
.PHONY: format
1313
format:
14-
ruff --fix tsdownsample tests
14+
ruff format tsdownsample tests
1515
$(black)
1616
cargo fmt
1717

1818
.PHONY: lint-python
1919
lint-python:
20-
ruff tsdownsample tests
20+
ruff check tsdownsample tests
2121
$(black) --check --diff
2222

2323
.PHONY: lint-rust
2424
lint-rust:
2525
cargo fmt --version
2626
cargo fmt --all -- --check
2727
cargo clippy --version
28-
cargo clippy -- -D warnings -A incomplete_features -W clippy::dbg_macro -W clippy::print_stdout
28+
cargo clippy -- -D warnings -A incomplete_features -W clippy::dbg_macro -W clippy::print_stdout -A clippy::empty_line_after_doc_comments
2929

3030
.PHONY: lint
3131
lint: lint-python lint-rust

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ classifiers = [
2222
'Programming Language :: Python :: 3.10',
2323
'Programming Language :: Python :: 3.11',
2424
'Programming Language :: Python :: 3.12',
25+
'Programming Language :: Python :: 3.13',
2526
'Operating System :: POSIX',
2627
'Operating System :: MacOS :: MacOS X',
2728
'Operating System :: Microsoft :: Windows'

src/lib.rs

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ macro_rules! _create_pyfunc_without_x {
2222
py: Python<'py>,
2323
y: PyReadonlyArray1<$type>,
2424
n_out: usize,
25-
) -> &'py PyArray1<usize> {
25+
) -> Bound<'py, PyArray1<usize>> {
2626
let y = y.as_slice().unwrap();
2727
let sampled_indices = $resample_mod::$resample_fn(y, n_out);
28-
sampled_indices.into_pyarray(py)
28+
sampled_indices.into_pyarray_bound(py)
2929
}
3030
// Add the function to the module
3131
$mod.add_wrapped(wrap_pyfunction!($name))?;
@@ -41,10 +41,10 @@ macro_rules! _create_pyfunc_without_x_with_ratio {
4141
y: PyReadonlyArray1<$type>,
4242
n_out: usize,
4343
ratio: usize,
44-
) -> &'py PyArray1<usize> {
44+
) -> Bound<'py, PyArray1<usize>> {
4545
let y = y.as_slice().unwrap();
4646
let sampled_indices = $resample_mod::$resample_fn(y, n_out, ratio);
47-
sampled_indices.into_pyarray(py)
47+
sampled_indices.into_pyarray_bound(py)
4848
}
4949
// Add the function to the module
5050
$mod.add_wrapped(wrap_pyfunction!($name))?;
@@ -80,11 +80,11 @@ macro_rules! _create_pyfunc_with_x {
8080
x: PyReadonlyArray1<$type_x>,
8181
y: PyReadonlyArray1<$type_y>,
8282
n_out: usize,
83-
) -> &'py PyArray1<usize> {
83+
) -> Bound<'py, PyArray1<usize>> {
8484
let x = x.as_slice().unwrap();
8585
let y = y.as_slice().unwrap();
8686
let sampled_indices = $resample_mod::$resample_fn(x, y, n_out);
87-
sampled_indices.into_pyarray(py)
87+
sampled_indices.into_pyarray_bound(py)
8888
}
8989
// Add the function to the module
9090
$mod.add_wrapped(wrap_pyfunction!($name))?;
@@ -101,11 +101,11 @@ macro_rules! _create_pyfunc_with_x_with_ratio {
101101
y: PyReadonlyArray1<$type_y>,
102102
n_out: usize,
103103
ratio: usize,
104-
) -> &'py PyArray1<usize> {
104+
) -> Bound<'py, PyArray1<usize>> {
105105
let x = x.as_slice().unwrap();
106106
let y = y.as_slice().unwrap();
107107
let sampled_indices = $resample_mod::$resample_fn(x, y, n_out, ratio);
108-
sampled_indices.into_pyarray(py)
108+
sampled_indices.into_pyarray_bound(py)
109109
}
110110
// Add the function to the module
111111
$mod.add_wrapped(wrap_pyfunction!($name))?;
@@ -255,10 +255,10 @@ use downsample_rs::minmax as minmax_mod;
255255

256256
// Create a sub module for the minmax algorithm
257257
#[pymodule]
258-
fn minmax(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
258+
fn minmax(_py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> {
259259
// ----------------- SEQUENTIAL
260260

261-
let sequential_mod = PyModule::new(_py, "sequential")?;
261+
let sequential_mod = PyModule::new_bound(_py, "sequential")?;
262262

263263
// ----- WITHOUT X
264264
{
@@ -274,7 +274,7 @@ fn minmax(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
274274

275275
// ----------------- PARALLEL
276276

277-
let parallel_mod = PyModule::new(_py, "parallel")?;
277+
let parallel_mod = PyModule::new_bound(_py, "parallel")?;
278278

279279
// ----- WITHOUT X
280280
{
@@ -289,8 +289,8 @@ fn minmax(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
289289
}
290290

291291
// Add the sub modules to the module
292-
m.add_submodule(sequential_mod)?;
293-
m.add_submodule(parallel_mod)?;
292+
m.add_submodule(&sequential_mod)?;
293+
m.add_submodule(&parallel_mod)?;
294294

295295
Ok(())
296296
}
@@ -301,10 +301,10 @@ use downsample_rs::m4 as m4_mod;
301301

302302
// Create a sub module for the M4 algorithm
303303
#[pymodule]
304-
fn m4(_py: Python, m: &PyModule) -> PyResult<()> {
304+
fn m4(_py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> {
305305
// ----------------- SEQUENTIAL
306306

307-
let sequential_mod = PyModule::new(_py, "sequential")?;
307+
let sequential_mod = PyModule::new_bound(_py, "sequential")?;
308308

309309
// ----- WITHOUT X
310310
{
@@ -320,7 +320,7 @@ fn m4(_py: Python, m: &PyModule) -> PyResult<()> {
320320

321321
// ----------------- PARALLEL
322322

323-
let parallel_mod = PyModule::new(_py, "parallel")?;
323+
let parallel_mod = PyModule::new_bound(_py, "parallel")?;
324324

325325
// ----- WITHOUT X
326326
{
@@ -335,8 +335,8 @@ fn m4(_py: Python, m: &PyModule) -> PyResult<()> {
335335
}
336336

337337
// Add the sub modules to the module
338-
m.add_submodule(sequential_mod)?;
339-
m.add_submodule(parallel_mod)?;
338+
m.add_submodule(&sequential_mod)?;
339+
m.add_submodule(&parallel_mod)?;
340340

341341
Ok(())
342342
}
@@ -347,10 +347,10 @@ use downsample_rs::lttb as lttb_mod;
347347

348348
// Create a sub module for the LTTB algorithm
349349
#[pymodule]
350-
fn lttb(_py: Python, m: &PyModule) -> PyResult<()> {
350+
fn lttb(_py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> {
351351
// ----------------- SEQUENTIAL
352352

353-
let sequential_mod = PyModule::new(_py, "sequential")?;
353+
let sequential_mod = PyModule::new_bound(_py, "sequential")?;
354354

355355
// Create the Python functions for the module
356356
// ----- WITHOUT X
@@ -364,7 +364,7 @@ fn lttb(_py: Python, m: &PyModule) -> PyResult<()> {
364364
}
365365

366366
// Add the sub modules to the module
367-
m.add_submodule(sequential_mod)?;
367+
m.add_submodule(&sequential_mod)?;
368368

369369
Ok(())
370370
}
@@ -375,10 +375,10 @@ use downsample_rs::minmaxlttb as minmaxlttb_mod;
375375

376376
// Create a sub module for the MINMAXLTTB algorithm
377377
#[pymodule]
378-
fn minmaxlttb(_py: Python, m: &PyModule) -> PyResult<()> {
378+
fn minmaxlttb(_py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> {
379379
// ----------------- SEQUENTIAL
380380

381-
let sequential_mod = PyModule::new(_py, "sequential")?;
381+
let sequential_mod = PyModule::new_bound(_py, "sequential")?;
382382

383383
// ----- WITHOUT X
384384
{
@@ -394,7 +394,7 @@ fn minmaxlttb(_py: Python, m: &PyModule) -> PyResult<()> {
394394

395395
// ----------------- PARALLEL
396396

397-
let parallel_mod = PyModule::new(_py, "parallel")?;
397+
let parallel_mod = PyModule::new_bound(_py, "parallel")?;
398398

399399
// ----- WITHOUT X
400400
{
@@ -417,8 +417,8 @@ fn minmaxlttb(_py: Python, m: &PyModule) -> PyResult<()> {
417417
}
418418

419419
// Add the submodules to the module
420-
m.add_submodule(sequential_mod)?;
421-
m.add_submodule(parallel_mod)?;
420+
m.add_submodule(&sequential_mod)?;
421+
m.add_submodule(&parallel_mod)?;
422422

423423
Ok(())
424424
}
@@ -427,7 +427,7 @@ fn minmaxlttb(_py: Python, m: &PyModule) -> PyResult<()> {
427427

428428
#[pymodule] // The super module
429429
#[pyo3(name = "_tsdownsample_rs")] // How the module is imported in Python: https://github.com/PyO3/maturin/issues/256#issuecomment-1038576218
430-
fn tsdownsample(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
430+
fn tsdownsample(_py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> {
431431
m.add_wrapped(wrap_pymodule!(minmax))?;
432432
m.add_wrapped(wrap_pymodule!(m4))?;
433433
m.add_wrapped(wrap_pymodule!(lttb))?;

0 commit comments

Comments
 (0)