@@ -1106,6 +1106,18 @@ impl<T: Element> PyArray<T, Ix1> {
11061106 vec. into_pyarray_bound ( py) . into_gil_ref ( )
11071107 }
11081108
1109+ /// Deprecated form of [`PyArray<T, Ix1>::from_iter_bound`]
1110+ #[ deprecated(
1111+ since = "0.21.0" ,
1112+ note = "will be replaced by PyArray::from_iter_bound in the future"
1113+ ) ]
1114+ pub fn from_iter < ' py , I > ( py : Python < ' py > , iter : I ) -> & ' py Self
1115+ where
1116+ I : IntoIterator < Item = T > ,
1117+ {
1118+ Self :: from_iter_bound ( py, iter) . into_gil_ref ( )
1119+ }
1120+
11091121 /// Construct a one-dimensional array from an [`Iterator`].
11101122 ///
11111123 /// If no reliable [`size_hint`][Iterator::size_hint] is available,
@@ -1114,20 +1126,20 @@ impl<T: Element> PyArray<T, Ix1> {
11141126 /// # Example
11151127 ///
11161128 /// ```
1117- /// use numpy::PyArray;
1129+ /// use numpy::{ PyArray, PyArrayMethods} ;
11181130 /// use pyo3::Python;
11191131 ///
11201132 /// Python::with_gil(|py| {
1121- /// let pyarray = PyArray::from_iter (py, "abcde".chars().map(u32::from));
1133+ /// let pyarray = PyArray::from_iter_bound (py, "abcde".chars().map(u32::from));
11221134 /// assert_eq!(pyarray.readonly().as_slice().unwrap(), &[97, 98, 99, 100, 101]);
11231135 /// });
11241136 /// ```
1125- pub fn from_iter < ' py , I > ( py : Python < ' py > , iter : I ) -> & ' py Self
1137+ pub fn from_iter_bound < I > ( py : Python < ' _ > , iter : I ) -> Bound < ' _ , Self >
11261138 where
11271139 I : IntoIterator < Item = T > ,
11281140 {
11291141 let data = iter. into_iter ( ) . collect :: < Vec < _ > > ( ) ;
1130- data. into_pyarray_bound ( py) . into_gil_ref ( )
1142+ data. into_pyarray_bound ( py)
11311143 }
11321144}
11331145
@@ -1288,13 +1300,14 @@ impl<T: Element, D> PyArray<T, D> {
12881300 /// # Example
12891301 ///
12901302 /// ```
1303+ /// use numpy::prelude::*;
12911304 /// use numpy::{npyffi::NPY_ORDER, PyArray};
12921305 /// use pyo3::Python;
12931306 /// use ndarray::array;
12941307 ///
12951308 /// Python::with_gil(|py| {
12961309 /// let array =
1297- /// PyArray::from_iter (py, 0..9).reshape_with_order([3, 3], NPY_ORDER::NPY_FORTRANORDER).unwrap();
1310+ /// PyArray::from_iter_bound (py, 0..9).reshape_with_order([3, 3], NPY_ORDER::NPY_FORTRANORDER).unwrap();
12981311 ///
12991312 /// assert_eq!(array.readonly().as_array(), array![[0, 3, 6], [1, 4, 7], [2, 5, 8]]);
13001313 /// assert!(array.is_fortran_contiguous());
@@ -1830,13 +1843,14 @@ pub trait PyArrayMethods<'py, T, D>: PyUntypedArrayMethods<'py> {
18301843 /// # Example
18311844 ///
18321845 /// ```
1846+ /// use numpy::prelude::*;
18331847 /// use numpy::{npyffi::NPY_ORDER, PyArray};
18341848 /// use pyo3::Python;
18351849 /// use ndarray::array;
18361850 ///
18371851 /// Python::with_gil(|py| {
18381852 /// let array =
1839- /// PyArray::from_iter (py, 0..9).reshape_with_order([3, 3], NPY_ORDER::NPY_FORTRANORDER).unwrap();
1853+ /// PyArray::from_iter_bound (py, 0..9).reshape_with_order([3, 3], NPY_ORDER::NPY_FORTRANORDER).unwrap();
18401854 ///
18411855 /// assert_eq!(array.readonly().as_array(), array![[0, 3, 6], [1, 4, 7], [2, 5, 8]]);
18421856 /// assert!(array.is_fortran_contiguous());
0 commit comments