File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff 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+ }
You can’t perform that action at this time.
0 commit comments