Skip to content

Commit ee7823d

Browse files
Icxoluadamreichold
authored andcommitted
deprecate PyArray::from_array
1 parent 6234a72 commit ee7823d

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

src/array.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -803,6 +803,18 @@ impl<T: Element, D: Dimension> PyArray<T, D> {
803803
self.as_borrowed().to_vec()
804804
}
805805

806+
/// Deprecated form of [`PyArray<T, D>::from_array_bound`]
807+
#[deprecated(
808+
since = "0.21.0",
809+
note = "will be replaced by PyArray::from_array_bound in the future"
810+
)]
811+
pub fn from_array<'py, S>(py: Python<'py>, arr: &ArrayBase<S, D>) -> &'py Self
812+
where
813+
S: Data<Elem = T>,
814+
{
815+
Self::from_array_bound(py, arr).into_gil_ref()
816+
}
817+
806818
/// Construct a NumPy array from a [`ndarray::ArrayBase`].
807819
///
808820
/// This method allocates memory in Python's heap via the NumPy API,
@@ -811,21 +823,21 @@ impl<T: Element, D: Dimension> PyArray<T, D> {
811823
/// # Example
812824
///
813825
/// ```
814-
/// use numpy::PyArray;
826+
/// use numpy::{PyArray, PyArrayMethods};
815827
/// use ndarray::array;
816828
/// use pyo3::Python;
817829
///
818830
/// Python::with_gil(|py| {
819-
/// let pyarray = PyArray::from_array(py, &array![[1, 2], [3, 4]]);
831+
/// let pyarray = PyArray::from_array_bound(py, &array![[1, 2], [3, 4]]);
820832
///
821833
/// assert_eq!(pyarray.readonly().as_array(), array![[1, 2], [3, 4]]);
822834
/// });
823835
/// ```
824-
pub fn from_array<'py, S>(py: Python<'py>, arr: &ArrayBase<S, D>) -> &'py Self
836+
pub fn from_array_bound<'py, S>(py: Python<'py>, arr: &ArrayBase<S, D>) -> Bound<'py, Self>
825837
where
826838
S: Data<Elem = T>,
827839
{
828-
ToPyArray::to_pyarray_bound(arr, py).into_gil_ref()
840+
ToPyArray::to_pyarray_bound(arr, py)
829841
}
830842

831843
/// Get an immutable borrow of the NumPy array

tests/to_py.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ fn to_pyarray_array() {
4242
.map(|dim| dim * size_of::<f64>() as isize)
4343
.collect::<Vec<_>>();
4444

45-
let py_arr = PyArray::from_array(py, &arr);
45+
let py_arr = PyArray::from_array_bound(py, &arr);
4646

4747
assert_eq!(py_arr.shape(), shape.as_slice());
4848
assert_eq!(py_arr.strides(), strides.as_slice());

0 commit comments

Comments
 (0)