@@ -235,7 +235,9 @@ impl<T, D> PyArray<T, D> {
235235 /// # Safety
236236 ///
237237 /// This is a wrapper around [`pyo3::FromPyPointer::from_owned_ptr_or_opt`] and inherits its safety contract.
238+ #[ deprecated( since = "0.21.0" , note = "use Bound::from_owned_ptr() instead" ) ]
238239 pub unsafe fn from_owned_ptr < ' py > ( py : Python < ' py > , ptr : * mut ffi:: PyObject ) -> & ' py Self {
240+ #[ allow( deprecated) ]
239241 py. from_owned_ptr ( ptr)
240242 }
241243
@@ -244,7 +246,9 @@ impl<T, D> PyArray<T, D> {
244246 /// # Safety
245247 ///
246248 /// This is a wrapper around [`pyo3::FromPyPointer::from_borrowed_ptr_or_opt`] and inherits its safety contract.
249+ #[ deprecated( since = "0.21.0" , note = "use Bound::from_borrowed_ptr() instead" ) ]
247250 pub unsafe fn from_borrowed_ptr < ' py > ( py : Python < ' py > , ptr : * mut ffi:: PyObject ) -> & ' py Self {
251+ #[ allow( deprecated) ]
248252 py. from_borrowed_ptr ( ptr)
249253 }
250254
@@ -258,7 +262,7 @@ impl<T, D> PyArray<T, D> {
258262impl < T : Element , D : Dimension > PyArray < T , D > {
259263 fn extract < ' a , ' py , E > ( ob : & ' a Bound < ' py , PyAny > ) -> Result < & ' a Bound < ' py , Self > , E >
260264 where
261- E : From < DowncastError < ' a , ' py > > + From < DimensionalityError > + From < TypeError < ' a > > ,
265+ E : From < DowncastError < ' a , ' py > > + From < DimensionalityError > + From < TypeError < ' py > > ,
262266 {
263267 // Check if the object is an array.
264268 let array = unsafe {
@@ -786,14 +790,14 @@ impl<T: Element, D: Dimension> PyArray<T, D> {
786790 /// # Example
787791 ///
788792 /// ```
789- /// use numpy::PyArray2;
790- /// use pyo3::Python;
793+ /// use numpy::{ PyArray2, PyArrayMethods} ;
794+ /// use pyo3::{ Python, types::PyAnyMethods} ;
791795 ///
792796 /// Python::with_gil(|py| {
793797 /// let pyarray= py
794- /// .eval ("__import__('numpy').array([[0, 1], [2, 3]], dtype='int64')", None, None)
798+ /// .eval_bound ("__import__('numpy').array([[0, 1], [2, 3]], dtype='int64')", None, None)
795799 /// .unwrap()
796- /// .downcast ::<PyArray2<i64>>()
800+ /// .downcast_into ::<PyArray2<i64>>()
797801 /// .unwrap();
798802 ///
799803 /// assert_eq!(pyarray.to_vec().unwrap(), vec![0, 1, 2, 3]);
@@ -842,10 +846,7 @@ impl<T: Element, D: Dimension> PyArray<T, D> {
842846
843847 /// Get an immutable borrow of the NumPy array
844848 pub fn try_readonly ( & self ) -> Result < PyReadonlyArray < ' _ , T , D > , BorrowError > {
845- // TODO: replace with `Borrowed::to_owned` once
846- // pyo3#3963 makes it into a release
847- let bound = & * self . as_borrowed ( ) ;
848- PyReadonlyArray :: try_new ( bound. clone ( ) )
849+ PyReadonlyArray :: try_new ( self . as_borrowed ( ) . to_owned ( ) )
849850 }
850851
851852 /// Get an immutable borrow of the NumPy array
@@ -861,10 +862,7 @@ impl<T: Element, D: Dimension> PyArray<T, D> {
861862
862863 /// Get a mutable borrow of the NumPy array
863864 pub fn try_readwrite ( & self ) -> Result < PyReadwriteArray < ' _ , T , D > , BorrowError > {
864- // TODO: replace with `Borrowed::to_owned` once
865- // pyo3#3963 makes it into a release
866- let bound = & * self . as_borrowed ( ) ;
867- PyReadwriteArray :: try_new ( bound. clone ( ) )
865+ PyReadwriteArray :: try_new ( self . as_borrowed ( ) . to_owned ( ) )
868866 }
869867
870868 /// Get a mutable borrow of the NumPy array
@@ -1013,10 +1011,11 @@ impl<D: Dimension> PyArray<PyObject, D> {
10131011 ///
10141012 /// ```
10151013 /// use ndarray::array;
1016- /// use pyo3::{pyclass, Py, Python};
1014+ /// use pyo3::{pyclass, Py, Python, types::PyAnyMethods };
10171015 /// use numpy::{PyArray, PyArrayMethods};
10181016 ///
10191017 /// #[pyclass]
1018+ /// # #[allow(dead_code)]
10201019 /// struct CustomElement {
10211020 /// foo: i32,
10221021 /// bar: f64,
@@ -1036,7 +1035,7 @@ impl<D: Dimension> PyArray<PyObject, D> {
10361035 ///
10371036 /// let pyarray = PyArray::from_owned_object_array_bound(py, array);
10381037 ///
1039- /// assert!(pyarray.readonly().as_array().get(0).unwrap().as_ref (py).is_instance_of::<CustomElement>());
1038+ /// assert!(pyarray.readonly().as_array().get(0).unwrap().bind (py).is_instance_of::<CustomElement>());
10401039 /// });
10411040 /// ```
10421041 pub fn from_owned_object_array_bound < T > (
@@ -1703,14 +1702,14 @@ pub trait PyArrayMethods<'py, T, D>: PyUntypedArrayMethods<'py> {
17031702 /// # Example
17041703 ///
17051704 /// ```
1706- /// use numpy::PyArray2;
1707- /// use pyo3::Python;
1705+ /// use numpy::{ PyArray2, PyArrayMethods} ;
1706+ /// use pyo3::{ Python, types::PyAnyMethods} ;
17081707 ///
17091708 /// Python::with_gil(|py| {
17101709 /// let pyarray= py
1711- /// .eval ("__import__('numpy').array([[0, 1], [2, 3]], dtype='int64')", None, None)
1710+ /// .eval_bound ("__import__('numpy').array([[0, 1], [2, 3]], dtype='int64')", None, None)
17121711 /// .unwrap()
1713- /// .downcast ::<PyArray2<i64>>()
1712+ /// .downcast_into ::<PyArray2<i64>>()
17141713 /// .unwrap();
17151714 ///
17161715 /// assert_eq!(pyarray.to_vec().unwrap(), vec![0, 1, 2, 3]);
0 commit comments