Skip to content

Commit

Permalink
restore deprecation messages
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhewitt committed Oct 6, 2024
1 parent 5847743 commit f46bd07
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 0 deletions.
51 changes: 51 additions & 0 deletions src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ impl<T, D> PyArray<T, D> {
/// assert_eq!(array.bind(py).readonly().as_slice().unwrap(), [0.0; 5]);
/// });
/// ```
#[deprecated(since = "0.21.0", note = "use Bound::unbind() instead")]
pub fn to_owned(&self) -> Py<Self> {
unsafe { Py::from_borrowed_ptr(self.py(), self.as_ptr()) }
}
Expand All @@ -238,6 +239,7 @@ impl<T, D> PyArray<T, D> {
/// # Safety
///
/// This is a wrapper around [`pyo3::FromPyPointer::from_owned_ptr_or_opt`] and inherits its safety contract.
#[deprecated(since = "0.21.0", note = "use Bound::from_owned_ptr() instead")]
pub unsafe fn from_owned_ptr<'py>(py: Python<'py>, ptr: *mut ffi::PyObject) -> &'py Self {
#![allow(deprecated)]
py.from_owned_ptr(ptr)
Expand All @@ -248,6 +250,7 @@ impl<T, D> PyArray<T, D> {
/// # Safety
///
/// This is a wrapper around [`pyo3::FromPyPointer::from_borrowed_ptr_or_opt`] and inherits its safety contract.
#[deprecated(since = "0.21.0", note = "use Bound::from_borrowed_ptr() instead")]
pub unsafe fn from_borrowed_ptr<'py>(py: Python<'py>, ptr: *mut ffi::PyObject) -> &'py Self {
#![allow(deprecated)]
py.from_borrowed_ptr(ptr)
Expand Down Expand Up @@ -577,6 +580,10 @@ impl<T: Element, D: Dimension> PyArray<T, D> {
///
/// # Safety
/// Same as [`PyArray<T, D>::new_bound`]
#[deprecated(
since = "0.21.0",
note = "will be replaced by `PyArray::new_bound` in the future"
)]
pub unsafe fn new<'py, ID>(py: Python<'py>, dims: ID, is_fortran: bool) -> &Self
where
ID: IntoDimension<Dim = D>,
Expand All @@ -588,6 +595,10 @@ impl<T: Element, D: Dimension> PyArray<T, D> {
///
/// # Safety
/// Same as [`PyArray<T, D>::borrow_from_array_bound`]
#[deprecated(
since = "0.21.0",
note = "will be replaced by `PyArray::borrow_from_array_bound` in the future"
)]
pub unsafe fn borrow_from_array<'py, S>(
array: &ArrayBase<S, D>,
container: &'py PyAny,
Expand All @@ -599,6 +610,10 @@ impl<T: Element, D: Dimension> PyArray<T, D> {
}

/// Deprecated form of [`PyArray<T, D>::zeros_bound`]
#[deprecated(
since = "0.21.0",
note = "will be replaced by `PyArray::zeros_bound` in the future"
)]
pub fn zeros<'py, ID>(py: Python<'py>, dims: ID, is_fortran: bool) -> &Self
where
ID: IntoDimension<Dim = D>,
Expand Down Expand Up @@ -641,6 +656,10 @@ impl<T: Element, D: Dimension> PyArray<T, D> {
}

/// Deprecated form of [`PyArray<T, D>::from_owned_array_bound`]
#[deprecated(
since = "0.21.0",
note = "will be replaced by PyArray::from_owned_array_bound in the future"
)]
pub fn from_owned_array<'py>(py: Python<'py>, arr: Array<T, D>) -> &'py Self {
Self::from_owned_array_bound(py, arr).into_gil_ref()
}
Expand Down Expand Up @@ -821,6 +840,10 @@ impl<T: Element, D: Dimension> PyArray<T, D> {
}

/// Deprecated form of [`PyArray<T, D>::from_array_bound`]
#[deprecated(
since = "0.21.0",
note = "will be replaced by PyArray::from_array_bound in the future"
)]
pub fn from_array<'py, S>(py: Python<'py>, arr: &ArrayBase<S, D>) -> &'py Self
where
S: Data<Elem = T>,
Expand Down Expand Up @@ -981,6 +1004,10 @@ where
impl<D: Dimension> PyArray<PyObject, D> {
/// Deprecated form of [`PyArray<T, D>::from_owned_object_array_bound`]
#[cfg(feature = "gil-refs")]
#[deprecated(
since = "0.21.0",
note = "will be replaced by PyArray::from_owned_object_array_bound in the future"
)]
pub fn from_owned_object_array<'py, T>(py: Python<'py>, arr: Array<Py<T>, D>) -> &'py Self {
Self::from_owned_object_array_bound(py, arr).into_gil_ref()
}
Expand Down Expand Up @@ -1119,17 +1146,29 @@ impl<T: Element> PyArray<T, Ix1> {
#[cfg(feature = "gil-refs")]
impl<T: Element> PyArray<T, Ix1> {
/// Deprecated form of [`PyArray<T, Ix1>::from_slice_bound`]
#[deprecated(
since = "0.21.0",
note = "will be replaced by `PyArray::from_slice_bound` in the future"
)]
pub fn from_slice<'py>(py: Python<'py>, slice: &[T]) -> &'py Self {
Self::from_slice_bound(py, slice).into_gil_ref()
}

/// Deprecated form of [`PyArray<T, Ix1>::from_vec_bound`]
#[inline(always)]
#[deprecated(
since = "0.21.0",
note = "will be replaced by `PyArray::from_vec_bound` in the future"
)]
pub fn from_vec<'py>(py: Python<'py>, vec: Vec<T>) -> &'py Self {
Self::from_vec_bound(py, vec).into_gil_ref()
}

/// Deprecated form of [`PyArray<T, Ix1>::from_iter_bound`]
#[deprecated(
since = "0.21.0",
note = "will be replaced by PyArray::from_iter_bound in the future"
)]
pub fn from_iter<'py, I>(py: Python<'py>, iter: I) -> &'py Self
where
I: IntoIterator<Item = T>,
Expand All @@ -1141,6 +1180,10 @@ impl<T: Element> PyArray<T, Ix1> {
impl<T: Element> PyArray<T, Ix2> {
/// Deprecated form of [`PyArray<T, Ix2>::from_vec2_bound`]
#[cfg(feature = "gil-refs")]
#[deprecated(
since = "0.21.0",
note = "will be replaced by `PyArray::from_vec2_bound` in the future"
)]
pub fn from_vec2<'py>(py: Python<'py>, v: &[Vec<T>]) -> Result<&'py Self, FromVecError> {
Self::from_vec2_bound(py, v).map(Bound::into_gil_ref)
}
Expand Down Expand Up @@ -1191,6 +1234,10 @@ impl<T: Element> PyArray<T, Ix2> {
impl<T: Element> PyArray<T, Ix3> {
/// Deprecated form of [`PyArray<T, Ix3>::from_vec3_bound`]
#[cfg(feature = "gil-refs")]
#[deprecated(
since = "0.21.0",
note = "will be replaced by `PyArray::from_vec3_bound` in the future"
)]
pub fn from_vec3<'py>(py: Python<'py>, v: &[Vec<Vec<T>>]) -> Result<&'py Self, FromVecError> {
Self::from_vec3_bound(py, v).map(Bound::into_gil_ref)
}
Expand Down Expand Up @@ -1428,6 +1475,10 @@ impl<T: Element, D> PyArray<T, D> {
impl<T: Element + AsPrimitive<f64>> PyArray<T, Ix1> {
/// Deprecated form of [`PyArray<T, Ix1>::arange_bound`]
#[cfg(feature = "gil-refs")]
#[deprecated(
since = "0.21.0",
note = "will be replaced by PyArray::arange_bound in the future"
)]
pub fn arange<'py>(py: Python<'py>, start: T, stop: T, step: T) -> &Self {
Self::arange_bound(py, start, stop, step).into_gil_ref()
}
Expand Down
20 changes: 20 additions & 0 deletions src/dtype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ pyobject_native_type_extract!(PyArrayDescr);

/// Returns the type descriptor ("dtype") for a registered type.
#[cfg(feature = "gil-refs")]
#[deprecated(
since = "0.21.0",
note = "This will be replaced by `dtype_bound` in the future."
)]
pub fn dtype<'py, T: Element>(py: Python<'py>) -> &'py PyArrayDescr {
T::get_dtype_bound(py).into_gil_ref()
}
Expand Down Expand Up @@ -136,6 +140,10 @@ impl PyArrayDescr {
/// Equivalent to invoking the constructor of [`numpy.dtype`][dtype].
///
/// [dtype]: https://numpy.org/doc/stable/reference/generated/numpy.dtype.html
#[deprecated(
since = "0.21.0",
note = "This will be replace by `new_bound` in the future."
)]
pub fn new<'py, T: ToPyObject + ?Sized>(py: Python<'py>, ob: &T) -> PyResult<&'py Self> {
Self::new_bound(py, ob).map(Bound::into_gil_ref)
}
Expand All @@ -153,11 +161,19 @@ impl PyArrayDescr {
}

/// Shortcut for creating a type descriptor of `object` type.
#[deprecated(
since = "0.21.0",
note = "This will be replaced by `object_bound` in the future."
)]
pub fn object<'py>(py: Python<'py>) -> &'py Self {
Self::object_bound(py).into_gil_ref()
}

/// Returns the type descriptor for a registered type.
#[deprecated(
since = "0.21.0",
note = "This will be replaced by `of_bound` in the future."
)]
pub fn of<'py, T: Element>(py: Python<'py>) -> &'py Self {
Self::of_bound::<T>(py).into_gil_ref()
}
Expand Down Expand Up @@ -693,6 +709,10 @@ pub unsafe trait Element: Sized + Send {

/// Returns the associated type descriptor ("dtype") for the given element type.
#[cfg(feature = "gil-refs")]
#[deprecated(
since = "0.21.0",
note = "This will be replaced by `get_dtype_bound` in the future."
)]
fn get_dtype<'py>(py: Python<'py>) -> &'py PyArrayDescr {
Self::get_dtype_bound(py).into_gil_ref()
}
Expand Down
16 changes: 16 additions & 0 deletions src/sum_products.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ where
impl<'py, T> ArrayOrScalar<'py, T> for T where T: Element + FromPyObject<'py> {}

/// Deprecated form of [`inner_bound`]
#[deprecated(
since = "0.21.0",
note = "will be replaced by `inner_bound` in the future"
)]
#[cfg(feature = "gil-refs")]
pub fn inner<'py, T, DIN1, DIN2, OUT>(
array1: &'py PyArray<T, DIN1>,
Expand Down Expand Up @@ -101,6 +105,10 @@ where

/// Deprecated form of [`dot_bound`]
#[cfg(feature = "gil-refs")]
#[deprecated(
since = "0.21.0",
note = "will be replaced by `dot_bound` in the future"
)]
pub fn dot<'py, T, DIN1, DIN2, OUT>(
array1: &'py PyArray<T, DIN1>,
array2: &'py PyArray<T, DIN2>,
Expand Down Expand Up @@ -174,6 +182,10 @@ where

/// Deprecated form of [`einsum_bound`]
#[cfg(feature = "gil-refs")]
#[deprecated(
since = "0.21.0",
note = "will be replaced by `einsum_bound` in the future"
)]
pub fn einsum<'py, T, OUT>(subscripts: &str, arrays: &[&'py PyArray<T, IxDyn>]) -> PyResult<OUT>
where
T: Element,
Expand Down Expand Up @@ -221,6 +233,10 @@ where

/// Deprecated form of [`einsum_bound!`][crate::einsum_bound!]
#[cfg(feature = "gil-refs")]
#[deprecated(
since = "0.21.0",
note = "will be replaced by `einsum_bound!` in the future"
)]
#[macro_export]
macro_rules! einsum {
($subscripts:literal $(,$array:ident)+ $(,)*) => {{
Expand Down

0 comments on commit f46bd07

Please sign in to comment.