Skip to content

Bump PyO3 to 0.16 #259

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

Merged
merged 3 commits into from
Feb 28, 2022
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.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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))
Expand Down
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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/*"]
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -70,16 +70,16 @@ fn rust_ext(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
) -> &'py PyArrayDyn<f64> {
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<f64>) -> PyResult<()> {
fn mult_py(_py: Python<'_>, a: f64, x: &PyArrayDyn<f64>) {
let x = unsafe { x.as_array_mut() };
mult(a, x);
Ok(())
}

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion examples/linalg/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
2 changes: 1 addition & 1 deletion examples/parallel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
2 changes: 1 addition & 1 deletion examples/simple/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "../.." }
2 changes: 1 addition & 1 deletion src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,7 @@ impl<D: Dimension> PyArray<PyObject, D> {
///
/// let pyarray = PyArray::from_owned_object_array(py, array);
///
/// assert!(pyarray.readonly().get(0).unwrap().as_ref(py).is_instance::<CustomElement>().unwrap());
/// assert!(pyarray.readonly().get(0).unwrap().as_ref(py).is_instance_of::<CustomElement>().unwrap());
/// });
/// ```
pub fn from_owned_object_array<'py, T>(py: Python<'py>, arr: Array<Py<T>, D>) -> &'py Self {
Expand Down
8 changes: 5 additions & 3 deletions src/dtype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -498,13 +498,15 @@ mod tests {
#[test]
fn test_dtype_new() {
Python::with_gil(|py| {
assert_eq!(PyArrayDescr::new(py, "float64").unwrap(), dtype::<f64>(py));
assert!(PyArrayDescr::new(py, "float64")
.unwrap()
.is(dtype::<f64>(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::<PyObject>(py));
assert_eq!(dt.get_field("b").unwrap().0, dtype::<bool>(py));
assert!(dt.get_field("a").unwrap().0.is(dtype::<PyObject>(py)));
assert!(dt.get_field("b").unwrap().0.is(dtype::<bool>(py)));

assert!(PyArrayDescr::new(py, &123_usize).is_err());
});
Expand Down
14 changes: 9 additions & 5 deletions src/slice_container.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -95,6 +97,8 @@ impl PyClassImpl for PySliceContainer {
type BaseType = PyAny;
type Layout = PyCell<Self>;
type ThreadChecker = ThreadCheckerStub<Self>;

fn for_all_items(_visitor: &mut dyn FnMut(&PyClassItems)) {}
}

unsafe impl PyTypeInfo for PySliceContainer {
Expand Down
4 changes: 2 additions & 2 deletions tests/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ fn as_slice() {
fn is_instance() {
pyo3::Python::with_gil(|py| {
let arr = PyArray2::<f64>::zeros(py, [3, 5], false);
assert!(arr.is_instance::<PyArray2<f64>>().unwrap());
assert!(!arr.is_instance::<PyList>().unwrap());
assert!(arr.is_instance_of::<PyArray2<f64>>().unwrap());
assert!(!arr.is_instance_of::<PyList>().unwrap());
})
}

Expand Down