Skip to content

Commit c386c8e

Browse files
authored
update pyo3 to 0.23 (#457)
* remove `gil-ref` feature * initial migration to pyo3 0.23 * fix all deprecations * reintroduce names with `_bound` suffix * switch from `ToPyObject` to `IntoPyObject` * bump to pyo3 0.23 release * fix doc-tests * add changelog
1 parent 9eaa51f commit c386c8e

32 files changed

+839
-2097
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
# Changelog
22
- v0.23.0
33
- Drop support for PyPy 3.7 and 3.8. ([#470](https://github.com/PyO3/rust-numpy/pull/470))
4+
- Require `Element: Sync` as part of the free-threading support in PyO3 0.23 ([#469](https://github.com/PyO3/rust-numpy/pull/469))
5+
- Bump PyO3 dependency to v0.23.0 ([[#457](https://github.com/PyO3/rust-numpy/pull/457)])
6+
- removed the `gil-refs` feature
7+
- reintroduced function names without `_bound` suffix + deprecating the old names
8+
- switched to `IntoPyObject` as trait bound
9+
410
- v0.22.1
511
- Fix building on 32-bit Windows. ([#463](https://github.com/PyO3/rust-numpy/pull/463))
612
- Add `PyReadwriteArray::make_nonwriteable`. ([#462](https://github.com/PyO3/rust-numpy/pull/462))

Cargo.toml

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "numpy"
3-
version = "0.22.1"
3+
version = "0.23.0-dev"
44
authors = [
55
"The rust-numpy Project Developers",
66
"PyO3 Project and Contributors <https://github.com/PyO3>"
@@ -22,15 +22,12 @@ num-complex = ">= 0.2, < 0.5"
2222
num-integer = "0.1"
2323
num-traits = "0.2"
2424
ndarray = ">= 0.15, < 0.17"
25-
pyo3 = { version = "0.22.0", default-features = false, features = ["macros"] }
25+
pyo3 = { version = "0.23.0", default-features = false, features = ["macros"] }
2626
rustc-hash = "1.1"
2727

2828
[dev-dependencies]
29-
pyo3 = { version = "0.22.0", default-features = false, features = ["auto-initialize"] }
29+
pyo3 = { version = "0.23.0", default-features = false, features = ["auto-initialize"] }
3030
nalgebra = { version = ">=0.30, <0.34", default-features = false, features = ["std"] }
3131

3232
[package.metadata.docs.rs]
3333
all-features = true
34-
35-
[features]
36-
gil-refs = ["pyo3/gil-refs"]

README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ fn rust_ext<'py>(_py: Python<'py>, m: &Bound<'py, PyModule>) -> PyResult<()> {
7171
let x = x.as_array();
7272
let y = y.as_array();
7373
let z = axpy(a, x, y);
74-
z.into_pyarray_bound(py)
74+
z.into_pyarray(py)
7575
}
7676

7777
// wrapper of `mult`
@@ -99,15 +99,15 @@ numpy = "0.22"
9999

100100
```rust
101101
use numpy::{PyArray1, PyArrayMethods};
102-
use pyo3::{types::{IntoPyDict, PyAnyMethods}, PyResult, Python};
102+
use pyo3::{types::{IntoPyDict, PyAnyMethods}, PyResult, Python, ffi::c_str};
103103

104104
fn main() -> PyResult<()> {
105105
Python::with_gil(|py| {
106-
let np = py.import_bound("numpy")?;
107-
let locals = [("np", np)].into_py_dict_bound(py);
106+
let np = py.import("numpy")?;
107+
let locals = [("np", np)].into_py_dict(py)?;
108108

109109
let pyarray = py
110-
.eval_bound("np.absolute(np.array([-1, -2, -3], dtype='int32'))", Some(&locals), None)?
110+
.eval(c_str!("np.absolute(np.array([-1, -2, -3], dtype='int32'))"), Some(&locals), None)?
111111
.downcast_into::<PyArray1<i32>>()?;
112112

113113
let readonly = pyarray.readonly();

benches/array.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ use test::{black_box, Bencher};
66
use std::ops::Range;
77

88
use numpy::{PyArray1, PyArray2, PyArray3};
9-
use pyo3::{types::PyAnyMethods, Bound, Python, ToPyObject};
9+
use pyo3::{types::PyAnyMethods, Bound, Python};
1010

1111
#[bench]
1212
fn extract_success(bencher: &mut Bencher) {
1313
Python::with_gil(|py| {
14-
let any = PyArray2::<f64>::zeros_bound(py, (10, 10), false).into_any();
14+
let any = PyArray2::<f64>::zeros(py, (10, 10), false).into_any();
1515

1616
bencher.iter(|| {
1717
black_box(&any)
@@ -24,7 +24,7 @@ fn extract_success(bencher: &mut Bencher) {
2424
#[bench]
2525
fn extract_failure(bencher: &mut Bencher) {
2626
Python::with_gil(|py| {
27-
let any = PyArray2::<f64>::zeros_bound(py, (10, 10), false).into_any();
27+
let any = PyArray2::<f64>::zeros(py, (10, 10), false).into_any();
2828

2929
bencher.iter(|| {
3030
black_box(&any)
@@ -37,7 +37,7 @@ fn extract_failure(bencher: &mut Bencher) {
3737
#[bench]
3838
fn downcast_success(bencher: &mut Bencher) {
3939
Python::with_gil(|py| {
40-
let any = PyArray2::<f64>::zeros_bound(py, (10, 10), false).into_any();
40+
let any = PyArray2::<f64>::zeros(py, (10, 10), false).into_any();
4141

4242
bencher.iter(|| black_box(&any).downcast::<PyArray2<f64>>().unwrap());
4343
});
@@ -46,7 +46,7 @@ fn downcast_success(bencher: &mut Bencher) {
4646
#[bench]
4747
fn downcast_failure(bencher: &mut Bencher) {
4848
Python::with_gil(|py| {
49-
let any = PyArray2::<f64>::zeros_bound(py, (10, 10), false).into_any();
49+
let any = PyArray2::<f64>::zeros(py, (10, 10), false).into_any();
5050

5151
bencher.iter(|| black_box(&any).downcast::<PyArray2<f64>>().unwrap_err());
5252
});
@@ -67,7 +67,7 @@ fn from_iter(bencher: &mut Bencher, size: usize) {
6767
bencher.iter(|| {
6868
let iter = black_box(Iter(0..size));
6969

70-
PyArray1::from_iter_bound(py, iter)
70+
PyArray1::from_iter(py, iter)
7171
});
7272
});
7373
}
@@ -94,7 +94,7 @@ fn from_slice(bencher: &mut Bencher, size: usize) {
9494
bencher.iter(|| {
9595
let slice = black_box(&vec);
9696

97-
PyArray1::from_slice_bound(py, slice)
97+
PyArray1::from_slice(py, slice)
9898
});
9999
});
100100
}
@@ -121,7 +121,7 @@ fn from_object_slice(bencher: &mut Bencher, size: usize) {
121121
bencher.iter(|| {
122122
let slice = black_box(&vec);
123123

124-
PyArray1::from_slice_bound(py, slice)
124+
PyArray1::from_slice(py, slice)
125125
});
126126
});
127127
}
@@ -148,7 +148,7 @@ fn from_vec2(bencher: &mut Bencher, size: usize) {
148148
bencher.iter(|| {
149149
let vec2 = black_box(&vec2);
150150

151-
PyArray2::from_vec2_bound(py, vec2).unwrap()
151+
PyArray2::from_vec2(py, vec2).unwrap()
152152
});
153153
});
154154
}
@@ -175,7 +175,7 @@ fn from_vec3(bencher: &mut Bencher, size: usize) {
175175
bencher.iter(|| {
176176
let vec3 = black_box(&vec3);
177177

178-
PyArray3::from_vec3_bound(py, vec3).unwrap()
178+
PyArray3::from_vec3(py, vec3).unwrap()
179179
});
180180
});
181181
}

benches/borrow.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use pyo3::Python;
99
#[bench]
1010
fn initial_shared_borrow(bencher: &mut Bencher) {
1111
Python::with_gil(|py| {
12-
let array = PyArray::<f64, _>::zeros_bound(py, (6, 5, 4, 3, 2, 1), false);
12+
let array = PyArray::<f64, _>::zeros(py, (6, 5, 4, 3, 2, 1), false);
1313

1414
bencher.iter(|| {
1515
let array = black_box(&array);
@@ -22,7 +22,7 @@ fn initial_shared_borrow(bencher: &mut Bencher) {
2222
#[bench]
2323
fn additional_shared_borrow(bencher: &mut Bencher) {
2424
Python::with_gil(|py| {
25-
let array = PyArray::<f64, _>::zeros_bound(py, (6, 5, 4, 3, 2, 1), false);
25+
let array = PyArray::<f64, _>::zeros(py, (6, 5, 4, 3, 2, 1), false);
2626

2727
let _shared = (0..128).map(|_| array.readonly()).collect::<Vec<_>>();
2828

@@ -37,7 +37,7 @@ fn additional_shared_borrow(bencher: &mut Bencher) {
3737
#[bench]
3838
fn exclusive_borrow(bencher: &mut Bencher) {
3939
Python::with_gil(|py| {
40-
let array = PyArray::<f64, _>::zeros_bound(py, (6, 5, 4, 3, 2, 1), false);
40+
let array = PyArray::<f64, _>::zeros(py, (6, 5, 4, 3, 2, 1), false);
4141

4242
bencher.iter(|| {
4343
let array = black_box(&array);

examples/linalg/Cargo.lock

+14-59
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/linalg/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ name = "rust_linalg"
99
crate-type = ["cdylib"]
1010

1111
[dependencies]
12-
pyo3 = { version = "0.22.0", features = ["extension-module"] }
12+
pyo3 = { version = "0.23.0", features = ["extension-module"] }
1313
numpy = { path = "../.." }
1414
ndarray-linalg = { version = "0.14.1", features = ["openblas-system"] }
1515

examples/linalg/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ fn rust_linalg<'py>(m: &Bound<'py, PyModule>) -> PyResult<()> {
1313
let y = x
1414
.inv()
1515
.map_err(|e| PyRuntimeError::new_err(e.to_string()))?;
16-
Ok(y.into_pyarray_bound(py))
16+
Ok(y.into_pyarray(py))
1717
}
1818
Ok(())
1919
}

examples/parallel/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ name = "rust_parallel"
99
crate-type = ["cdylib"]
1010

1111
[dependencies]
12-
pyo3 = { version = "0.22.0", features = ["extension-module", "multiple-pymethods"] }
12+
pyo3 = { version = "0.23.0", features = ["extension-module", "multiple-pymethods"] }
1313
numpy = { path = "../.." }
1414
ndarray = { version = "0.16", features = ["rayon", "blas"] }
1515
blas-src = { version = "0.8", features = ["openblas"] }

examples/parallel/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ fn rust_parallel<'py>(m: &Bound<'py, PyModule>) -> PyResult<()> {
1616
let x = x.as_array();
1717
let y = y.as_array();
1818
let z = Zip::from(x.rows()).par_map_collect(|row| row.dot(&y));
19-
z.into_pyarray_bound(py)
19+
z.into_pyarray(py)
2020
}
2121
Ok(())
2222
}

examples/simple/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ name = "rust_ext"
99
crate-type = ["cdylib"]
1010

1111
[dependencies]
12-
pyo3 = { version = "0.22.0", features = ["extension-module", "abi3-py37"] }
12+
pyo3 = { version = "0.23.0", features = ["extension-module", "abi3-py37"] }
1313
numpy = { path = "../.." }
1414

1515
[workspace]

0 commit comments

Comments
 (0)