@@ -146,29 +146,28 @@ impl<T, D> PyArray<T, D> {
146146 self . as_ptr ( ) as _
147147 }
148148
149- // TODO: 'increasing ref counts' is really collect approach for extension?
150- /// Get `PyArray` from `&PyArray`, by increasing ref counts.
149+ /// Get `Py<PyArray>` from `&PyArray`, which is the owned wrapper of PyObject.
151150 ///
152151 /// You can use this method when you have to avoid lifetime annotation to your function args
153152 /// or return types, like used with pyo3's `pymethod`.
154153 ///
155154 /// # Example
156155 /// ```
157156 /// # extern crate pyo3; extern crate numpy; fn main() {
158- /// use pyo3::{GILGuard, Python};
157+ /// use pyo3::{GILGuard, Python, Py, AsPyRef };
159158 /// use numpy::PyArray1;
160- /// fn return_py_array() -> PyArray1<i32> {
159+ /// fn return_py_array() -> Py< PyArray1<i32> > {
161160 /// let gil = Python::acquire_gil();
162161 /// let array = PyArray1::zeros(gil.python(), [5], false);
163- /// array.to_owned(gil.python() )
162+ /// array.to_owned()
164163 /// }
164+ /// let gil = Python::acquire_gil();
165165 /// let array = return_py_array();
166- /// assert_eq!(array.as_slice(), &[0, 0, 0, 0, 0]);
166+ /// assert_eq!(array.as_ref(gil.python()). as_slice(), &[0, 0, 0, 0, 0]);
167167 /// # }
168168 /// ```
169- pub fn to_owned ( & self , py : Python ) -> Self {
170- let obj = unsafe { PyObject :: from_borrowed_ptr ( py, self . as_ptr ( ) ) } ;
171- PyArray ( obj, PhantomData , PhantomData )
169+ pub fn to_owned ( & self ) -> Py < Self > {
170+ unsafe { Py :: from_borrowed_ptr ( self . as_ptr ( ) ) }
172171 }
173172
174173 /// Constructs `PyArray` from raw python object without incrementing reference counts.
0 commit comments