Skip to content

Commit b6e58e2

Browse files
committed
Add a test for the ToPyArray impl for ArrayBase.
1 parent f5fe2ba commit b6e58e2

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

tests/to_py.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,3 +192,33 @@ fn to_pyarray_object_vec() {
192192
}
193193
})
194194
}
195+
196+
#[test]
197+
fn to_pyarray_object_array() {
198+
use ndarray::Array2;
199+
use pyo3::{
200+
types::{PyDict, PyString},
201+
ToPyObject,
202+
};
203+
use std::cmp::Ordering;
204+
205+
pyo3::Python::with_gil(|py| {
206+
let mut nd_arr = Array2::from_shape_fn((2, 3), |(_, _)| py.None());
207+
nd_arr[(0, 2)] = PyDict::new(py).to_object(py);
208+
nd_arr[(1, 0)] = PyString::new(py, "Hello:)").to_object(py);
209+
210+
let py_arr = nd_arr.to_pyarray(py).readonly();
211+
212+
for (a, b) in nd_arr
213+
.as_slice()
214+
.unwrap()
215+
.iter()
216+
.zip(py_arr.as_slice().unwrap().iter())
217+
{
218+
assert_eq!(
219+
a.as_ref(py).compare(b).map_err(|e| e.print(py)).unwrap(),
220+
Ordering::Equal
221+
);
222+
}
223+
})
224+
}

0 commit comments

Comments
 (0)