Skip to content

update pyo3 to 0.25 #492

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 1 commit into from
May 14, 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
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "numpy"
version = "0.24.0"
version = "0.25.0"
authors = [
"The rust-numpy Project Developers",
"PyO3 Project and Contributors <https://github.com/PyO3>"
Expand All @@ -22,15 +22,15 @@ num-complex = ">= 0.2, < 0.5"
num-integer = "0.1"
num-traits = "0.2"
ndarray = ">= 0.15, < 0.17"
pyo3 = { version = "0.24.1", default-features = false, features = ["macros"] }
pyo3 = { version = "0.25.0", default-features = false, features = ["macros"] }
rustc-hash = "2.0"

[dev-dependencies]
pyo3 = { version = "0.24", default-features = false, features = ["auto-initialize"] }
pyo3 = { version = "0.25", default-features = false, features = ["auto-initialize"] }
nalgebra = { version = ">=0.30, <0.34", default-features = false, features = ["std"] }

[build-dependencies]
pyo3-build-config = { version = "0.24", features = ["resolve-config"] }
pyo3-build-config = { version = "0.25", features = ["resolve-config"] }

[package.metadata.docs.rs]
all-features = true
2 changes: 1 addition & 1 deletion examples/linalg/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ name = "rust_linalg"
crate-type = ["cdylib"]

[dependencies]
pyo3 = { version = "0.24.1", features = ["extension-module"] }
pyo3 = { version = "0.25.0", features = ["extension-module"] }
numpy = { path = "../.." }
ndarray-linalg = { version = "0.14.1", features = ["openblas-system"] }

Expand Down
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.24.0", features = ["extension-module", "multiple-pymethods"] }
pyo3 = { version = "0.25.0", features = ["extension-module", "multiple-pymethods"] }
numpy = { path = "../.." }
ndarray = { version = "0.16", 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,7 +9,7 @@ name = "rust_ext"
crate-type = ["cdylib"]

[dependencies]
pyo3 = { version = "0.24.0", features = ["extension-module", "abi3-py37"] }
pyo3 = { version = "0.25.0", features = ["extension-module", "abi3-py37"] }
numpy = { path = "../.." }

[workspace]
123 changes: 0 additions & 123 deletions src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,23 +216,6 @@ impl<T: Element, D: Dimension> PyArray<T, D> {
Self::new_uninit(py, dims, ptr::null_mut(), flags)
}

/// Deprecated name for [`PyArray::new`].
///
/// # Safety
/// See [`PyArray::new`].
#[deprecated(since = "0.23.0", note = "renamed to `PyArray::new`")]
#[inline]
pub unsafe fn new_bound<'py, ID>(
py: Python<'py>,
dims: ID,
is_fortran: bool,
) -> Bound<'py, Self>
where
ID: IntoDimension<Dim = D>,
{
Self::new(py, dims, is_fortran)
}

pub(crate) unsafe fn new_uninit<'py, ID>(
py: Python<'py>,
dims: ID,
Expand Down Expand Up @@ -358,22 +341,6 @@ impl<T: Element, D: Dimension> PyArray<T, D> {
)
}

/// Deprecated name for [`PyArray::borrow_from_array`].
///
/// # Safety
/// See [`PyArray::borrow_from_array`]
#[deprecated(since = "0.23.0", note = "renamed to `PyArray::borrow_from_array`")]
#[inline]
pub unsafe fn borrow_from_array_bound<'py, S>(
array: &ArrayBase<S, D>,
container: Bound<'py, PyAny>,
) -> Bound<'py, Self>
where
S: Data<Elem = T>,
{
Self::borrow_from_array(array, container)
}

/// Construct a new NumPy array filled with zeros.
///
/// If `is_fortran` is true, then it has Fortran/column-major order,
Expand Down Expand Up @@ -416,16 +383,6 @@ impl<T: Element, D: Dimension> PyArray<T, D> {
}
}

/// Deprecated name for [`PyArray::zeros`].
#[deprecated(since = "0.23.0", note = "renamed to `PyArray::zeros`")]
#[inline]
pub fn zeros_bound<ID>(py: Python<'_>, dims: ID, is_fortran: bool) -> Bound<'_, Self>
where
ID: IntoDimension<Dim = D>,
{
Self::zeros(py, dims, is_fortran)
}

/// Constructs a NumPy from an [`ndarray::Array`]
///
/// This method uses the internal [`Vec`] of the [`ndarray::Array`] as the base object of the NumPy array.
Expand Down Expand Up @@ -456,12 +413,6 @@ impl<T: Element, D: Dimension> PyArray<T, D> {
)
}
}
/// Deprecated name for [`PyArray::from_owned_array`].
#[deprecated(since = "0.23.0", note = "renamed to `PyArray::from_owned_array`")]
#[inline]
pub fn from_owned_array_bound(py: Python<'_>, arr: Array<T, D>) -> Bound<'_, Self> {
Self::from_owned_array(py, arr)
}

/// Construct a NumPy array from a [`ndarray::ArrayBase`].
///
Expand All @@ -487,16 +438,6 @@ impl<T: Element, D: Dimension> PyArray<T, D> {
{
ToPyArray::to_pyarray(arr, py)
}

/// Deprecated name for [`PyArray::from_array`].
#[deprecated(since = "0.23.0", note = "renamed to `PyArray::from_array`")]
#[inline]
pub fn from_array_bound<'py, S>(py: Python<'py>, arr: &ArrayBase<S, D>) -> Bound<'py, Self>
where
S: Data<Elem = T>,
{
Self::from_array(py, arr)
}
}

impl<D: Dimension> PyArray<PyObject, D> {
Expand Down Expand Up @@ -548,19 +489,6 @@ impl<D: Dimension> PyArray<PyObject, D> {
)
}
}

/// Deprecated name for [`PyArray::from_owned_object_array`].
#[deprecated(
since = "0.23.0",
note = "renamed to `PyArray::from_owned_object_array`"
)]
#[inline]
pub fn from_owned_object_array_bound<T>(
py: Python<'_>,
arr: Array<Py<T>, D>,
) -> Bound<'_, Self> {
Self::from_owned_object_array(py, arr)
}
}

impl<T: Element> PyArray<T, Ix1> {
Expand All @@ -587,13 +515,6 @@ impl<T: Element> PyArray<T, Ix1> {
}
}

/// Deprecated name for [`PyArray::from_slice`].
#[deprecated(since = "0.23.0", note = "renamed to `PyArray::from_slice`")]
#[inline]
pub fn from_slice_bound<'py>(py: Python<'py>, slice: &[T]) -> Bound<'py, Self> {
Self::from_slice(py, slice)
}

/// Construct a one-dimensional array from a [`Vec<T>`][Vec].
///
/// # Example
Expand All @@ -613,13 +534,6 @@ impl<T: Element> PyArray<T, Ix1> {
vec.into_pyarray(py)
}

/// Deprecated name for [`PyArray::from_vec`].
#[deprecated(since = "0.23.0", note = "renamed to `PyArray::from_vec`")]
#[inline]
pub fn from_vec_bound<'py>(py: Python<'py>, vec: Vec<T>) -> Bound<'py, Self> {
Self::from_vec(py, vec)
}

/// Construct a one-dimensional array from an [`Iterator`].
///
/// If no reliable [`size_hint`][Iterator::size_hint] is available,
Expand All @@ -643,16 +557,6 @@ impl<T: Element> PyArray<T, Ix1> {
let data = iter.into_iter().collect::<Vec<_>>();
data.into_pyarray(py)
}

/// Deprecated name for [`PyArray::from_iter`].
#[deprecated(since = "0.23.0", note = "renamed to `PyArray::from_iter`")]
#[inline]
pub fn from_iter_bound<I>(py: Python<'_>, iter: I) -> Bound<'_, Self>
where
I: IntoIterator<Item = T>,
{
Self::from_iter(py, iter)
}
}

impl<T: Element> PyArray<T, Ix2> {
Expand Down Expand Up @@ -694,16 +598,6 @@ impl<T: Element> PyArray<T, Ix2> {
Ok(array)
}
}

/// Deprecated name for [`PyArray::from_vec2`].
#[deprecated(since = "0.23.0", note = "renamed to `PyArray::from_vec2`")]
#[inline]
pub fn from_vec2_bound<'py>(
py: Python<'py>,
v: &[Vec<T>],
) -> Result<Bound<'py, Self>, FromVecError> {
Self::from_vec2(py, v)
}
}

impl<T: Element> PyArray<T, Ix3> {
Expand Down Expand Up @@ -764,16 +658,6 @@ impl<T: Element> PyArray<T, Ix3> {
Ok(array)
}
}

/// Deprecated name for [`PyArray::from_vec3`].
#[deprecated(since = "0.23.0", note = "renamed to `PyArray::from_vec3`")]
#[inline]
pub fn from_vec3_bound<'py>(
py: Python<'py>,
v: &[Vec<Vec<T>>],
) -> Result<Bound<'py, Self>, FromVecError> {
Self::from_vec3(py, v)
}
}

impl<T: Element + AsPrimitive<f64>> PyArray<T, Ix1> {
Expand Down Expand Up @@ -810,13 +694,6 @@ impl<T: Element + AsPrimitive<f64>> PyArray<T, Ix1> {
Bound::from_owned_ptr(py, ptr).downcast_into_unchecked()
}
}

/// Deprecated name for [`PyArray::arange`].
#[deprecated(since = "0.23.0", note = "renamed to `PyArray::arange`")]
#[inline]
pub fn arange_bound<'py>(py: Python<'py>, start: T, stop: T, step: T) -> Bound<'py, Self> {
Self::arange(py, start, stop, step)
}
}

unsafe fn clone_elements<T: Element>(py: Python<'_>, elems: &[T], data_ptr: &mut *mut T) {
Expand Down
17 changes: 0 additions & 17 deletions src/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,6 @@ pub trait IntoPyArray: Sized {

/// Consumes `self` and moves its data into a NumPy array.
fn into_pyarray<'py>(self, py: Python<'py>) -> Bound<'py, PyArray<Self::Item, Self::Dim>>;

/// Deprecated name for [`IntoPyArray::into_pyarray`].
#[deprecated(since = "0.23.0", note = "renamed to `IntoPyArray::into_pyarray`")]
#[inline]
fn into_pyarray_bound<'py>(
self,
py: Python<'py>,
) -> Bound<'py, PyArray<Self::Item, Self::Dim>> {
self.into_pyarray(py)
}
}

impl<T: Element> IntoPyArray for Box<[T]> {
Expand Down Expand Up @@ -144,13 +134,6 @@ pub trait ToPyArray {

/// Copies the content pointed to by `&self` into a newly allocated NumPy array.
fn to_pyarray<'py>(&self, py: Python<'py>) -> Bound<'py, PyArray<Self::Item, Self::Dim>>;

/// Deprecated name for [ToPyArray::to_pyarray`].
#[deprecated(since = "0.23.0", note = "renamed to ToPyArray::to_pyarray`")]
#[inline]
fn to_pyarray_bound<'py>(&self, py: Python<'py>) -> Bound<'py, PyArray<Self::Item, Self::Dim>> {
self.to_pyarray(py)
}
}

impl<T: Element> ToPyArray for [T] {
Expand Down
45 changes: 3 additions & 42 deletions src/dtype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,6 @@ pub fn dtype<'py, T: Element>(py: Python<'py>) -> Bound<'py, PyArrayDescr> {
T::get_dtype(py)
}

/// Deprecated name for [`dtype`].
#[deprecated(since = "0.23.0", note = "renamed to `dtype`")]
#[inline]
pub fn dtype_bound<'py, T: Element>(py: Python<'py>) -> Bound<'py, PyArrayDescr> {
dtype::<T>(py)
}

impl PyArrayDescr {
/// Creates a new type descriptor ("dtype") object from an arbitrary object.
///
Expand Down Expand Up @@ -108,43 +101,18 @@ impl PyArrayDescr {
)
}

/// Deprecated name for [`PyArrayDescr::new`].
#[deprecated(since = "0.23.0", note = "renamed to `PyArrayDescr::new`")]
#[allow(deprecated)]
#[inline]
pub fn new_bound<'py, T: pyo3::ToPyObject + ?Sized>(
py: Python<'py>,
ob: &T,
) -> PyResult<Bound<'py, Self>> {
Self::new(py, ob.to_object(py))
}

/// Shortcut for creating a type descriptor of `object` type.
#[inline]
pub fn object(py: Python<'_>) -> Bound<'_, Self> {
Self::from_npy_type(py, NPY_TYPES::NPY_OBJECT)
}

/// Deprecated name for [`PyArrayDescr::object`].
#[deprecated(since = "0.23.0", note = "renamed to `PyArrayDescr::object`")]
#[inline]
pub fn object_bound(py: Python<'_>) -> Bound<'_, Self> {
Self::object(py)
}

/// Returns the type descriptor for a registered type.
#[inline]
pub fn of<'py, T: Element>(py: Python<'py>) -> Bound<'py, Self> {
T::get_dtype(py)
}

/// Deprecated name for [`PyArrayDescr::of`].
#[deprecated(since = "0.23.0", note = "renamed to `PyArrayDescr::of`")]
#[inline]
pub fn of_bound<'py, T: Element>(py: Python<'py>) -> Bound<'py, Self> {
Self::of::<T>(py)
}

fn from_npy_type<'py>(py: Python<'py>, npy_type: NPY_TYPES) -> Bound<'py, Self> {
unsafe {
let descr = PY_ARRAY_API.PyArray_DescrFromType(py, npy_type as _);
Expand Down Expand Up @@ -506,13 +474,6 @@ pub unsafe trait Element: Sized + Send + Sync {
/// Returns the associated type descriptor ("dtype") for the given element type.
fn get_dtype(py: Python<'_>) -> Bound<'_, PyArrayDescr>;

/// Deprecated name for [`Element::get_dtype`].
#[deprecated(since = "0.23.0", note = "renamed to `Element::get_dtype`")]
#[inline]
fn get_dtype_bound(py: Python<'_>) -> Bound<'_, PyArrayDescr> {
Self::get_dtype(py)
}

/// Create a clone of the value while the GIL is guaranteed to be held.
fn clone_ref(&self, py: Python<'_>) -> Self;

Expand Down Expand Up @@ -700,13 +661,13 @@ mod tests {
Python::with_gil(|py| {
assert!(PyArrayDescr::new(py, "float64")
.unwrap()
.is(&dtype::<f64>(py)));
.is(dtype::<f64>(py)));

let dt = PyArrayDescr::new(py, [("a", "O"), ("b", "?")].as_ref()).unwrap();
assert_eq!(dt.names(), Some(vec!["a".to_owned(), "b".to_owned()]));
assert!(dt.has_object());
assert!(dt.get_field("a").unwrap().0.is(&dtype::<PyObject>(py)));
assert!(dt.get_field("b").unwrap().0.is(&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
Loading
Loading