Skip to content

Commit 05e4842

Browse files
committed
Adjust code and examples to PyO3 0.16 API changes.
1 parent 2a4bb67 commit 05e4842

File tree

5 files changed

+20
-14
lines changed

5 files changed

+20
-14
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,16 @@ fn rust_ext(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
7070
) -> &'py PyArrayDyn<f64> {
7171
let x = x.as_array();
7272
let y = y.as_array();
73-
axpy(a, x, y).into_pyarray(py)
73+
let z = axpy(a, x, y);
74+
z.into_pyarray(py)
7475
}
7576

7677
// wrapper of `mult`
7778
#[pyfn(m)]
7879
#[pyo3(name = "mult")]
79-
fn mult_py(_py: Python<'_>, a: f64, x: &PyArrayDyn<f64>) -> PyResult<()> {
80+
fn mult_py(_py: Python<'_>, a: f64, x: &PyArrayDyn<f64>) {
8081
let x = unsafe { x.as_array_mut() };
8182
mult(a, x);
82-
Ok(())
8383
}
8484

8585
Ok(())

src/array.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -922,7 +922,7 @@ impl<D: Dimension> PyArray<PyObject, D> {
922922
///
923923
/// let pyarray = PyArray::from_owned_object_array(py, array);
924924
///
925-
/// assert!(pyarray.readonly().get(0).unwrap().as_ref(py).is_instance::<CustomElement>().unwrap());
925+
/// assert!(pyarray.readonly().get(0).unwrap().as_ref(py).is_instance_of::<CustomElement>().unwrap());
926926
/// });
927927
/// ```
928928
pub fn from_owned_object_array<'py, T>(py: Python<'py>, arr: Array<Py<T>, D>) -> &'py Self {

src/dtype.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -498,13 +498,15 @@ mod tests {
498498
#[test]
499499
fn test_dtype_new() {
500500
Python::with_gil(|py| {
501-
assert_eq!(PyArrayDescr::new(py, "float64").unwrap(), dtype::<f64>(py));
501+
assert!(PyArrayDescr::new(py, "float64")
502+
.unwrap()
503+
.is(dtype::<f64>(py)));
502504

503505
let dt = PyArrayDescr::new(py, [("a", "O"), ("b", "?")].as_ref()).unwrap();
504506
assert_eq!(dt.names(), Some(vec!["a", "b"]));
505507
assert!(dt.has_object());
506-
assert_eq!(dt.get_field("a").unwrap().0, dtype::<PyObject>(py));
507-
assert_eq!(dt.get_field("b").unwrap().0, dtype::<bool>(py));
508+
assert!(dt.get_field("a").unwrap().0.is(dtype::<PyObject>(py)));
509+
assert!(dt.get_field("b").unwrap().0.is(dtype::<bool>(py)));
508510

509511
assert!(PyArrayDescr::new(py, &123_usize).is_err());
510512
});

src/slice_container.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
use std::{mem, slice};
22

33
use ndarray::{ArrayBase, Dimension, OwnedRepr};
4-
use pyo3::class::impl_::{PyClassImpl, ThreadCheckerStub};
5-
use pyo3::pyclass::PyClass;
6-
use pyo3::pyclass_slots::PyClassDummySlot;
7-
use pyo3::type_object::{LazyStaticType, PyTypeInfo};
8-
use pyo3::{ffi, types::PyAny, PyCell, Python};
4+
use pyo3::{
5+
ffi,
6+
impl_::pyclass::{PyClassDummySlot, PyClassImpl, PyClassItems, ThreadCheckerStub},
7+
pyclass::PyClass,
8+
type_object::{LazyStaticType, PyTypeInfo},
9+
PyAny, PyCell, Python,
10+
};
911

1012
/// Utility type to safely store `Box<[_]>` or `Vec<_>` on the Python heap
1113
pub(crate) struct PySliceContainer {
@@ -95,6 +97,8 @@ impl PyClassImpl for PySliceContainer {
9597
type BaseType = PyAny;
9698
type Layout = PyCell<Self>;
9799
type ThreadChecker = ThreadCheckerStub<Self>;
100+
101+
fn for_all_items(_visitor: &mut dyn FnMut(&PyClassItems)) {}
98102
}
99103

100104
unsafe impl PyTypeInfo for PySliceContainer {

tests/array.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ fn as_slice() {
120120
fn is_instance() {
121121
pyo3::Python::with_gil(|py| {
122122
let arr = PyArray2::<f64>::zeros(py, [3, 5], false);
123-
assert!(arr.is_instance::<PyArray2<f64>>().unwrap());
124-
assert!(!arr.is_instance::<PyList>().unwrap());
123+
assert!(arr.is_instance_of::<PyArray2<f64>>().unwrap());
124+
assert!(!arr.is_instance_of::<PyList>().unwrap());
125125
})
126126
}
127127

0 commit comments

Comments
 (0)