@@ -1106,6 +1106,18 @@ impl<T: Element> PyArray<T, Ix1> {
1106
1106
vec. into_pyarray_bound ( py) . into_gil_ref ( )
1107
1107
}
1108
1108
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
+
1109
1121
/// Construct a one-dimensional array from an [`Iterator`].
1110
1122
///
1111
1123
/// If no reliable [`size_hint`][Iterator::size_hint] is available,
@@ -1114,20 +1126,20 @@ impl<T: Element> PyArray<T, Ix1> {
1114
1126
/// # Example
1115
1127
///
1116
1128
/// ```
1117
- /// use numpy::PyArray;
1129
+ /// use numpy::{ PyArray, PyArrayMethods} ;
1118
1130
/// use pyo3::Python;
1119
1131
///
1120
1132
/// 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));
1122
1134
/// assert_eq!(pyarray.readonly().as_slice().unwrap(), &[97, 98, 99, 100, 101]);
1123
1135
/// });
1124
1136
/// ```
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 >
1126
1138
where
1127
1139
I : IntoIterator < Item = T > ,
1128
1140
{
1129
1141
let data = iter. into_iter ( ) . collect :: < Vec < _ > > ( ) ;
1130
- data. into_pyarray_bound ( py) . into_gil_ref ( )
1142
+ data. into_pyarray_bound ( py)
1131
1143
}
1132
1144
}
1133
1145
@@ -1288,13 +1300,14 @@ impl<T: Element, D> PyArray<T, D> {
1288
1300
/// # Example
1289
1301
///
1290
1302
/// ```
1303
+ /// use numpy::prelude::*;
1291
1304
/// use numpy::{npyffi::NPY_ORDER, PyArray};
1292
1305
/// use pyo3::Python;
1293
1306
/// use ndarray::array;
1294
1307
///
1295
1308
/// Python::with_gil(|py| {
1296
1309
/// 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();
1298
1311
///
1299
1312
/// assert_eq!(array.readonly().as_array(), array![[0, 3, 6], [1, 4, 7], [2, 5, 8]]);
1300
1313
/// assert!(array.is_fortran_contiguous());
@@ -1830,13 +1843,14 @@ pub trait PyArrayMethods<'py, T, D>: PyUntypedArrayMethods<'py> {
1830
1843
/// # Example
1831
1844
///
1832
1845
/// ```
1846
+ /// use numpy::prelude::*;
1833
1847
/// use numpy::{npyffi::NPY_ORDER, PyArray};
1834
1848
/// use pyo3::Python;
1835
1849
/// use ndarray::array;
1836
1850
///
1837
1851
/// Python::with_gil(|py| {
1838
1852
/// 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();
1840
1854
///
1841
1855
/// assert_eq!(array.readonly().as_array(), array![[0, 3, 6], [1, 4, 7], [2, 5, 8]]);
1842
1856
/// assert!(array.is_fortran_contiguous());
0 commit comments