@@ -19,7 +19,7 @@ use std::sync::Arc;
1919
2020use datafusion:: arrow:: array:: ArrayRef ;
2121use datafusion:: arrow:: datatypes:: DataType ;
22- use datafusion:: arrow:: pyarrow:: PyArrowType ;
22+ use datafusion:: arrow:: pyarrow:: { PyArrowType , ToPyArrow } ;
2323use datafusion:: common:: ScalarValue ;
2424use datafusion:: error:: { DataFusionError , Result } ;
2525use datafusion:: logical_expr:: {
@@ -47,14 +47,14 @@ impl RustAccumulator {
4747
4848impl Accumulator for RustAccumulator {
4949 fn state ( & mut self ) -> Result < Vec < ScalarValue > > {
50- Python :: attach ( |py| {
50+ Python :: attach ( |py| -> PyResult < Vec < ScalarValue > > {
5151 let values = self . accum . bind ( py) . call_method0 ( "state" ) ?;
5252 let mut scalars = Vec :: new ( ) ;
53- for item in values. iter ( ) ? {
54- let item = item?;
53+ for item in values. try_iter ( ) ? {
54+ let item: Bound < ' _ , PyAny > = item?;
5555 let scalar = match item. extract :: < PyScalarValue > ( ) {
5656 Ok ( py_scalar) => py_scalar. 0 ,
57- Err ( _) => py_obj_to_scalar_value ( py, item. into_py ( py ) ) ?,
57+ Err ( _) => py_obj_to_scalar_value ( py, item. unbind ( ) ) ?,
5858 } ;
5959 scalars. push ( scalar) ;
6060 }
@@ -64,11 +64,11 @@ impl Accumulator for RustAccumulator {
6464 }
6565
6666 fn evaluate ( & mut self ) -> Result < ScalarValue > {
67- Python :: attach ( |py| {
67+ Python :: attach ( |py| -> PyResult < ScalarValue > {
6868 let value = self . accum . bind ( py) . call_method0 ( "evaluate" ) ?;
6969 match value. extract :: < PyScalarValue > ( ) {
7070 Ok ( py_scalar) => Ok ( py_scalar. 0 ) ,
71- Err ( _) => py_obj_to_scalar_value ( py, value. into_py ( py ) ) ,
71+ Err ( _) => py_obj_to_scalar_value ( py, value. unbind ( ) ) ,
7272 }
7373 } )
7474 . map_err ( |e| DataFusionError :: Execution ( format ! ( "{e}" ) ) )
@@ -79,7 +79,7 @@ impl Accumulator for RustAccumulator {
7979 // 1. cast args to Pyarrow array
8080 let py_args = values
8181 . iter ( )
82- . map ( |arg| arg. into_data ( ) . to_pyarrow ( py) . unwrap ( ) )
82+ . map ( |arg| arg. to_data ( ) . to_pyarrow ( py) . unwrap ( ) )
8383 . collect :: < Vec < _ > > ( ) ;
8484 let py_args = PyTuple :: new ( py, py_args) . map_err ( to_datafusion_err) ?;
8585
@@ -100,7 +100,7 @@ impl Accumulator for RustAccumulator {
100100 . iter ( )
101101 . map ( |state| {
102102 state
103- . into_data ( )
103+ . to_data ( )
104104 . to_pyarrow ( py)
105105 . map_err ( |e| DataFusionError :: Execution ( format ! ( "{e}" ) ) )
106106 } )
@@ -125,7 +125,7 @@ impl Accumulator for RustAccumulator {
125125 // 1. cast args to Pyarrow array
126126 let py_args = values
127127 . iter ( )
128- . map ( |arg| arg. into_data ( ) . to_pyarrow ( py) . unwrap ( ) )
128+ . map ( |arg| arg. to_data ( ) . to_pyarrow ( py) . unwrap ( ) )
129129 . collect :: < Vec < _ > > ( ) ;
130130 let py_args = PyTuple :: new ( py, py_args) . map_err ( to_datafusion_err) ?;
131131
@@ -150,7 +150,7 @@ impl Accumulator for RustAccumulator {
150150}
151151
152152pub fn to_rust_accumulator ( accum : Py < PyAny > ) -> AccumulatorFactoryFunction {
153- Arc :: new ( move |args | -> Result < Box < dyn Accumulator > > {
153+ Arc :: new ( move |_args | -> Result < Box < dyn Accumulator > > {
154154 let accum = Python :: attach ( |py| {
155155 accum
156156 . call0 ( py)
0 commit comments