@@ -95,17 +95,17 @@ pub trait FromPyArrow: Sized {
9595/// Create a new PyArrow object from a arrow-rs type.
9696pub trait ToPyArrow {
9797 /// Convert the implemented type into a Python object without consuming it.
98- fn to_pyarrow ( & self , py : Python ) -> PyResult < Py < PyAny > > ;
98+ fn to_pyarrow < ' py > ( & self , py : Python < ' py > ) -> PyResult < Bound < ' py , PyAny > > ;
9999}
100100
101101/// Convert an arrow-rs type into a PyArrow object.
102102pub trait IntoPyArrow {
103103 /// Convert the implemented type into a Python object while consuming it.
104- fn into_pyarrow ( self , py : Python ) -> PyResult < Py < PyAny > > ;
104+ fn into_pyarrow < ' py > ( self , py : Python < ' py > ) -> PyResult < Bound < ' py , PyAny > > ;
105105}
106106
107107impl < T : ToPyArrow > IntoPyArrow for T {
108- fn into_pyarrow ( self , py : Python ) -> PyResult < Py < PyAny > > {
108+ fn into_pyarrow < ' py > ( self , py : Python < ' py > ) -> PyResult < Bound < ' py , PyAny > > {
109109 self . to_pyarrow ( py)
110110 }
111111}
@@ -172,7 +172,7 @@ impl FromPyArrow for DataType {
172172}
173173
174174impl ToPyArrow for DataType {
175- fn to_pyarrow ( & self , py : Python ) -> PyResult < Py < PyAny > > {
175+ fn to_pyarrow < ' py > ( & self , py : Python < ' py > ) -> PyResult < Bound < ' py , PyAny > > {
176176 let c_schema = FFI_ArrowSchema :: try_from ( self ) . map_err ( to_py_err) ?;
177177 let c_schema_ptr = & c_schema as * const FFI_ArrowSchema ;
178178 let module = py. import ( "pyarrow" ) ?;
@@ -208,7 +208,7 @@ impl FromPyArrow for Field {
208208}
209209
210210impl ToPyArrow for Field {
211- fn to_pyarrow ( & self , py : Python ) -> PyResult < Py < PyAny > > {
211+ fn to_pyarrow < ' py > ( & self , py : Python < ' py > ) -> PyResult < Bound < ' py , PyAny > > {
212212 let c_schema = FFI_ArrowSchema :: try_from ( self ) . map_err ( to_py_err) ?;
213213 let c_schema_ptr = & c_schema as * const FFI_ArrowSchema ;
214214 let module = py. import ( "pyarrow" ) ?;
@@ -244,7 +244,7 @@ impl FromPyArrow for Schema {
244244}
245245
246246impl ToPyArrow for Schema {
247- fn to_pyarrow ( & self , py : Python ) -> PyResult < Py < PyAny > > {
247+ fn to_pyarrow < ' py > ( & self , py : Python < ' py > ) -> PyResult < Bound < ' py , PyAny > > {
248248 let c_schema = FFI_ArrowSchema :: try_from ( self ) . map_err ( to_py_err) ?;
249249 let c_schema_ptr = & c_schema as * const FFI_ArrowSchema ;
250250 let module = py. import ( "pyarrow" ) ?;
@@ -303,7 +303,7 @@ impl FromPyArrow for ArrayData {
303303}
304304
305305impl ToPyArrow for ArrayData {
306- fn to_pyarrow ( & self , py : Python ) -> PyResult < Py < PyAny > > {
306+ fn to_pyarrow < ' py > ( & self , py : Python < ' py > ) -> PyResult < Bound < ' py , PyAny > > {
307307 let array = FFI_ArrowArray :: new ( self ) ;
308308 let schema = FFI_ArrowSchema :: try_from ( self . data_type ( ) ) . map_err ( to_py_err) ?;
309309
@@ -316,7 +316,7 @@ impl ToPyArrow for ArrayData {
316316 addr_of ! ( schema) as Py_uintptr_t ,
317317 ) ,
318318 ) ?;
319- Ok ( array. unbind ( ) )
319+ Ok ( array)
320320 }
321321}
322322
@@ -328,12 +328,12 @@ impl<T: FromPyArrow> FromPyArrow for Vec<T> {
328328}
329329
330330impl < T : ToPyArrow > ToPyArrow for Vec < T > {
331- fn to_pyarrow ( & self , py : Python ) -> PyResult < Py < PyAny > > {
331+ fn to_pyarrow < ' py > ( & self , py : Python < ' py > ) -> PyResult < Bound < ' py , PyAny > > {
332332 let values = self
333333 . iter ( )
334334 . map ( |v| v. to_pyarrow ( py) )
335335 . collect :: < PyResult < Vec < _ > > > ( ) ?;
336- Ok ( PyList :: new ( py, values) ?. unbind ( ) . into ( ) )
336+ Ok ( PyList :: new ( py, values) ?. into_any ( ) )
337337 }
338338}
339339
@@ -412,12 +412,12 @@ impl FromPyArrow for RecordBatch {
412412}
413413
414414impl ToPyArrow for RecordBatch {
415- fn to_pyarrow ( & self , py : Python ) -> PyResult < Py < PyAny > > {
415+ fn to_pyarrow < ' py > ( & self , py : Python < ' py > ) -> PyResult < Bound < ' py , PyAny > > {
416416 // Workaround apache/arrow#37669 by returning RecordBatchIterator
417417 let reader = RecordBatchIterator :: new ( vec ! [ Ok ( self . clone( ) ) ] , self . schema ( ) ) ;
418418 let reader: Box < dyn RecordBatchReader + Send > = Box :: new ( reader) ;
419419 let py_reader = reader. into_pyarrow ( py) ?;
420- py_reader. call_method0 ( py , "read_next_batch" )
420+ py_reader. call_method0 ( "read_next_batch" )
421421 }
422422}
423423
@@ -463,7 +463,7 @@ impl FromPyArrow for ArrowArrayStreamReader {
463463impl IntoPyArrow for Box < dyn RecordBatchReader + Send > {
464464 // We can't implement `ToPyArrow` for `T: RecordBatchReader + Send` because
465465 // there is already a blanket implementation for `T: ToPyArrow`.
466- fn into_pyarrow ( self , py : Python ) -> PyResult < Py < PyAny > > {
466+ fn into_pyarrow < ' py > ( self , py : Python < ' py > ) -> PyResult < Bound < ' py , PyAny > > {
467467 let mut stream = FFI_ArrowArrayStream :: new ( self ) ;
468468
469469 let stream_ptr = ( & mut stream) as * mut FFI_ArrowArrayStream ;
@@ -472,13 +472,13 @@ impl IntoPyArrow for Box<dyn RecordBatchReader + Send> {
472472 let args = PyTuple :: new ( py, [ stream_ptr as Py_uintptr_t ] ) ?;
473473 let reader = class. call_method1 ( "_import_from_c" , args) ?;
474474
475- Ok ( Py :: from ( reader) )
475+ Ok ( reader)
476476 }
477477}
478478
479479/// Convert a [`ArrowArrayStreamReader`] into a `pyarrow.RecordBatchReader`.
480480impl IntoPyArrow for ArrowArrayStreamReader {
481- fn into_pyarrow ( self , py : Python ) -> PyResult < Py < PyAny > > {
481+ fn into_pyarrow < ' py > ( self , py : Python < ' py > ) -> PyResult < Bound < ' py , PyAny > > {
482482 let boxed: Box < dyn RecordBatchReader + Send > = Box :: new ( self ) ;
483483 boxed. into_pyarrow ( py)
484484 }
@@ -506,10 +506,7 @@ impl<'py, T: IntoPyArrow> IntoPyObject<'py> for PyArrowType<T> {
506506 type Error = PyErr ;
507507
508508 fn into_pyobject ( self , py : Python < ' py > ) -> Result < Self :: Output , PyErr > {
509- match self . 0 . into_pyarrow ( py) {
510- Ok ( obj) => Result :: Ok ( obj. into_bound ( py) ) ,
511- Err ( err) => Result :: Err ( err) ,
512- }
509+ self . 0 . into_pyarrow ( py)
513510 }
514511}
515512
0 commit comments