diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 35422c397..43ff9834b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,7 +31,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: [3.7, 3.8, 3.9] + python-version: ["3.7", "3.8", "3.9", "3.10"] platform: [ { os: "ubuntu-latest", python-architecture: "x64", rust-target: "x86_64-unknown-linux-gnu" }, { os: "macOS-latest", python-architecture: "x64", rust-target: "x86_64-apple-darwin" }, diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ffdcda99..b627472ee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Changelog - Unreleased + - Bump PyO3 version to 0.16 ([#259](https://github.com/PyO3/rust-numpy/pull/212)) - Support object arrays ([#216](https://github.com/PyO3/rust-numpy/pull/216)) - Support borrowing arrays that are part of other Python objects via `PyArray::borrow_from_array` ([#230](https://github.com/PyO3/rust-numpy/pull/216)) - Fixed downcasting ignoring element type and dimensionality ([#265](https://github.com/PyO3/rust-numpy/pull/265)) diff --git a/Cargo.toml b/Cargo.toml index 6bcb761e4..f7f42e1c5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,13 +16,13 @@ license = "BSD-2-Clause" [dependencies] libc = "0.2" -num-complex = ">= 0.2, <= 0.4" +num-complex = ">= 0.2, < 0.5" num-traits = "0.2" ndarray = ">= 0.13, < 0.16" -pyo3 = { version = "0.15", default-features = false } +pyo3 = { version = "0.16", default-features = false } [dev-dependencies] -pyo3 = { version = "0.15", features = ["auto-initialize"] } +pyo3 = { version = "0.16", features = ["auto-initialize"] } [workspace] members = ["examples/*"] diff --git a/README.md b/README.md index 5cb2b0694..bea001328 100644 --- a/README.md +++ b/README.md @@ -15,8 +15,8 @@ Rust bindings for the NumPy C-API. ## Requirements - Rust >= 1.48.0 - Basically, our MSRV follows the one of [PyO3](https://github.com/PyO3/pyo3) -- Python >= 3.6 - - Python 3.5 support is dropped from 0.13 +- Python >= 3.7 + - Python 3.6 support was dropped from 0.16 - Some Rust libraries - [ndarray](https://github.com/rust-ndarray/ndarray) for Rust-side matrix library - [PyO3](https://github.com/PyO3/pyo3) for Python bindings @@ -70,16 +70,16 @@ fn rust_ext(_py: Python<'_>, m: &PyModule) -> PyResult<()> { ) -> &'py PyArrayDyn { let x = x.as_array(); let y = y.as_array(); - axpy(a, x, y).into_pyarray(py) + let z = axpy(a, x, y); + z.into_pyarray(py) } // wrapper of `mult` #[pyfn(m)] #[pyo3(name = "mult")] - fn mult_py(_py: Python<'_>, a: f64, x: &PyArrayDyn) -> PyResult<()> { + fn mult_py(_py: Python<'_>, a: f64, x: &PyArrayDyn) { let x = unsafe { x.as_array_mut() }; mult(a, x); - Ok(()) } Ok(()) diff --git a/examples/linalg/Cargo.toml b/examples/linalg/Cargo.toml index ddb422903..4712e61d9 100644 --- a/examples/linalg/Cargo.toml +++ b/examples/linalg/Cargo.toml @@ -9,6 +9,6 @@ name = "rust_linalg" crate-type = ["cdylib"] [dependencies] -pyo3 = { version = "0.15", features = ["extension-module"] } +pyo3 = { version = "0.16", features = ["extension-module"] } numpy = { path = "../.." } ndarray-linalg = { version = "0.14.1", features = ["openblas-system"] } diff --git a/examples/parallel/Cargo.toml b/examples/parallel/Cargo.toml index ca5a2921a..77e8a4c25 100644 --- a/examples/parallel/Cargo.toml +++ b/examples/parallel/Cargo.toml @@ -9,7 +9,7 @@ name = "rust_parallel" crate-type = ["cdylib"] [dependencies] -pyo3 = { version = "0.15", features = ["extension-module"] } +pyo3 = { version = "0.16", features = ["extension-module"] } numpy = { path = "../.." } ndarray = { version = "0.15", features = ["rayon", "blas"] } blas-src = { version = "0.8", features = ["openblas"] } diff --git a/examples/simple/Cargo.toml b/examples/simple/Cargo.toml index 0017f42e6..1adc0243d 100644 --- a/examples/simple/Cargo.toml +++ b/examples/simple/Cargo.toml @@ -9,5 +9,5 @@ name = "rust_ext" crate-type = ["cdylib"] [dependencies] -pyo3 = { version = "0.15", features = ["extension-module"] } +pyo3 = { version = "0.16", features = ["extension-module"] } numpy = { path = "../.." } diff --git a/src/array.rs b/src/array.rs index 279b33c26..693034169 100644 --- a/src/array.rs +++ b/src/array.rs @@ -922,7 +922,7 @@ impl PyArray { /// /// let pyarray = PyArray::from_owned_object_array(py, array); /// - /// assert!(pyarray.readonly().get(0).unwrap().as_ref(py).is_instance::().unwrap()); + /// assert!(pyarray.readonly().get(0).unwrap().as_ref(py).is_instance_of::().unwrap()); /// }); /// ``` pub fn from_owned_object_array<'py, T>(py: Python<'py>, arr: Array, D>) -> &'py Self { diff --git a/src/dtype.rs b/src/dtype.rs index f7b4e95ce..b062be57c 100644 --- a/src/dtype.rs +++ b/src/dtype.rs @@ -498,13 +498,15 @@ mod tests { #[test] fn test_dtype_new() { Python::with_gil(|py| { - assert_eq!(PyArrayDescr::new(py, "float64").unwrap(), dtype::(py)); + assert!(PyArrayDescr::new(py, "float64") + .unwrap() + .is(dtype::(py))); let dt = PyArrayDescr::new(py, [("a", "O"), ("b", "?")].as_ref()).unwrap(); assert_eq!(dt.names(), Some(vec!["a", "b"])); assert!(dt.has_object()); - assert_eq!(dt.get_field("a").unwrap().0, dtype::(py)); - assert_eq!(dt.get_field("b").unwrap().0, dtype::(py)); + assert!(dt.get_field("a").unwrap().0.is(dtype::(py))); + assert!(dt.get_field("b").unwrap().0.is(dtype::(py))); assert!(PyArrayDescr::new(py, &123_usize).is_err()); }); diff --git a/src/slice_container.rs b/src/slice_container.rs index b450d7582..1060be377 100644 --- a/src/slice_container.rs +++ b/src/slice_container.rs @@ -1,11 +1,13 @@ use std::{mem, slice}; use ndarray::{ArrayBase, Dimension, OwnedRepr}; -use pyo3::class::impl_::{PyClassImpl, ThreadCheckerStub}; -use pyo3::pyclass::PyClass; -use pyo3::pyclass_slots::PyClassDummySlot; -use pyo3::type_object::{LazyStaticType, PyTypeInfo}; -use pyo3::{ffi, types::PyAny, PyCell, Python}; +use pyo3::{ + ffi, + impl_::pyclass::{PyClassDummySlot, PyClassImpl, PyClassItems, ThreadCheckerStub}, + pyclass::PyClass, + type_object::{LazyStaticType, PyTypeInfo}, + PyAny, PyCell, Python, +}; /// Utility type to safely store `Box<[_]>` or `Vec<_>` on the Python heap pub(crate) struct PySliceContainer { @@ -95,6 +97,8 @@ impl PyClassImpl for PySliceContainer { type BaseType = PyAny; type Layout = PyCell; type ThreadChecker = ThreadCheckerStub; + + fn for_all_items(_visitor: &mut dyn FnMut(&PyClassItems)) {} } unsafe impl PyTypeInfo for PySliceContainer { diff --git a/tests/array.rs b/tests/array.rs index 9d54e8be8..5faff65d9 100644 --- a/tests/array.rs +++ b/tests/array.rs @@ -120,8 +120,8 @@ fn as_slice() { fn is_instance() { pyo3::Python::with_gil(|py| { let arr = PyArray2::::zeros(py, [3, 5], false); - assert!(arr.is_instance::>().unwrap()); - assert!(!arr.is_instance::().unwrap()); + assert!(arr.is_instance_of::>().unwrap()); + assert!(!arr.is_instance_of::().unwrap()); }) }