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

Add support for Python 3.13 #78

Merged
merged 4 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci-tsdownsample.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
matrix:
os: ['windows-latest', 'macOS-latest', 'ubuntu-latest']
rust: ['nightly'] # ['stable', 'beta']
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12']
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12', "3.13"]
exclude: # Python < 3.8 is not supported on Apple Silicon ARM64
- os: macOS-latest
python-version: '3.7'
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ license = "MIT"

[dependencies]
downsample_rs = { path = "downsample_rs", features = ["half"]}
pyo3 = { version = "0.20", features = ["extension-module"] }
numpy = { version = "0.20", features = ["half"] }
pyo3 = { version = "0.22", features = ["extension-module"] }
numpy = { version = "0.22", features = ["half"] }
half = { version = "2.3.1", default-features = false }
paste = { version = "1.0.14", default-features = false }

Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@ install-dev-requirements:

.PHONY: format
format:
ruff --fix tsdownsample tests
ruff format tsdownsample tests
$(black)
cargo fmt

.PHONY: lint-python
lint-python:
ruff tsdownsample tests
ruff check tsdownsample tests
$(black) --check --diff

.PHONY: lint-rust
lint-rust:
cargo fmt --version
cargo fmt --all -- --check
cargo clippy --version
cargo clippy -- -D warnings -A incomplete_features -W clippy::dbg_macro -W clippy::print_stdout
cargo clippy -- -D warnings -A incomplete_features -W clippy::dbg_macro -W clippy::print_stdout -A clippy::empty_line_after_doc_comments

.PHONY: lint
lint: lint-python lint-rust
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ classifiers = [
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
'Programming Language :: Python :: 3.13',
'Operating System :: POSIX',
'Operating System :: MacOS :: MacOS X',
'Operating System :: Microsoft :: Windows'
Expand Down
54 changes: 27 additions & 27 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ macro_rules! _create_pyfunc_without_x {
py: Python<'py>,
y: PyReadonlyArray1<$type>,
n_out: usize,
) -> &'py PyArray1<usize> {
) -> Bound<'py, PyArray1<usize>> {
let y = y.as_slice().unwrap();
let sampled_indices = $resample_mod::$resample_fn(y, n_out);
sampled_indices.into_pyarray(py)
sampled_indices.into_pyarray_bound(py)
}
// Add the function to the module
$mod.add_wrapped(wrap_pyfunction!($name))?;
Expand All @@ -41,10 +41,10 @@ macro_rules! _create_pyfunc_without_x_with_ratio {
y: PyReadonlyArray1<$type>,
n_out: usize,
ratio: usize,
) -> &'py PyArray1<usize> {
) -> Bound<'py, PyArray1<usize>> {
let y = y.as_slice().unwrap();
let sampled_indices = $resample_mod::$resample_fn(y, n_out, ratio);
sampled_indices.into_pyarray(py)
sampled_indices.into_pyarray_bound(py)
}
// Add the function to the module
$mod.add_wrapped(wrap_pyfunction!($name))?;
Expand Down Expand Up @@ -80,11 +80,11 @@ macro_rules! _create_pyfunc_with_x {
x: PyReadonlyArray1<$type_x>,
y: PyReadonlyArray1<$type_y>,
n_out: usize,
) -> &'py PyArray1<usize> {
) -> Bound<'py, PyArray1<usize>> {
let x = x.as_slice().unwrap();
let y = y.as_slice().unwrap();
let sampled_indices = $resample_mod::$resample_fn(x, y, n_out);
sampled_indices.into_pyarray(py)
sampled_indices.into_pyarray_bound(py)
}
// Add the function to the module
$mod.add_wrapped(wrap_pyfunction!($name))?;
Expand All @@ -101,11 +101,11 @@ macro_rules! _create_pyfunc_with_x_with_ratio {
y: PyReadonlyArray1<$type_y>,
n_out: usize,
ratio: usize,
) -> &'py PyArray1<usize> {
) -> Bound<'py, PyArray1<usize>> {
let x = x.as_slice().unwrap();
let y = y.as_slice().unwrap();
let sampled_indices = $resample_mod::$resample_fn(x, y, n_out, ratio);
sampled_indices.into_pyarray(py)
sampled_indices.into_pyarray_bound(py)
}
// Add the function to the module
$mod.add_wrapped(wrap_pyfunction!($name))?;
Expand Down Expand Up @@ -255,10 +255,10 @@ use downsample_rs::minmax as minmax_mod;

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

let sequential_mod = PyModule::new(_py, "sequential")?;
let sequential_mod = PyModule::new_bound(_py, "sequential")?;

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

// ----------------- PARALLEL

let parallel_mod = PyModule::new(_py, "parallel")?;
let parallel_mod = PyModule::new_bound(_py, "parallel")?;

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

// Add the sub modules to the module
m.add_submodule(sequential_mod)?;
m.add_submodule(parallel_mod)?;
m.add_submodule(&sequential_mod)?;
m.add_submodule(&parallel_mod)?;

Ok(())
}
Expand All @@ -301,10 +301,10 @@ use downsample_rs::m4 as m4_mod;

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

let sequential_mod = PyModule::new(_py, "sequential")?;
let sequential_mod = PyModule::new_bound(_py, "sequential")?;

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

// ----------------- PARALLEL

let parallel_mod = PyModule::new(_py, "parallel")?;
let parallel_mod = PyModule::new_bound(_py, "parallel")?;

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

// Add the sub modules to the module
m.add_submodule(sequential_mod)?;
m.add_submodule(parallel_mod)?;
m.add_submodule(&sequential_mod)?;
m.add_submodule(&parallel_mod)?;

Ok(())
}
Expand All @@ -347,10 +347,10 @@ use downsample_rs::lttb as lttb_mod;

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

let sequential_mod = PyModule::new(_py, "sequential")?;
let sequential_mod = PyModule::new_bound(_py, "sequential")?;

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

// Add the sub modules to the module
m.add_submodule(sequential_mod)?;
m.add_submodule(&sequential_mod)?;

Ok(())
}
Expand All @@ -375,10 +375,10 @@ use downsample_rs::minmaxlttb as minmaxlttb_mod;

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

let sequential_mod = PyModule::new(_py, "sequential")?;
let sequential_mod = PyModule::new_bound(_py, "sequential")?;

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

// ----------------- PARALLEL

let parallel_mod = PyModule::new(_py, "parallel")?;
let parallel_mod = PyModule::new_bound(_py, "parallel")?;

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

// Add the submodules to the module
m.add_submodule(sequential_mod)?;
m.add_submodule(parallel_mod)?;
m.add_submodule(&sequential_mod)?;
m.add_submodule(&parallel_mod)?;

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

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