@@ -111,7 +111,7 @@ impl<T: ToPyArrow> IntoPyArrow for T {
111
111
}
112
112
113
113
fn validate_class ( expected : & str , value : & Bound < PyAny > ) -> PyResult < ( ) > {
114
- let pyarrow = PyModule :: import_bound ( value. py ( ) , "pyarrow" ) ?;
114
+ let pyarrow = PyModule :: import ( value. py ( ) , "pyarrow" ) ?;
115
115
let class = pyarrow. getattr ( expected) ?;
116
116
if !value. is_instance ( & class) ? {
117
117
let expected_module = class. getattr ( "__module__" ) ?. extract :: < PyBackedStr > ( ) ?;
@@ -177,7 +177,7 @@ impl ToPyArrow for DataType {
177
177
fn to_pyarrow ( & self , py : Python ) -> PyResult < PyObject > {
178
178
let c_schema = FFI_ArrowSchema :: try_from ( self ) . map_err ( to_py_err) ?;
179
179
let c_schema_ptr = & c_schema as * const FFI_ArrowSchema ;
180
- let module = py. import_bound ( "pyarrow" ) ?;
180
+ let module = py. import ( "pyarrow" ) ?;
181
181
let class = module. getattr ( "DataType" ) ?;
182
182
let dtype = class. call_method1 ( "_import_from_c" , ( c_schema_ptr as Py_uintptr_t , ) ) ?;
183
183
Ok ( dtype. into ( ) )
@@ -213,7 +213,7 @@ impl ToPyArrow for Field {
213
213
fn to_pyarrow ( & self , py : Python ) -> PyResult < PyObject > {
214
214
let c_schema = FFI_ArrowSchema :: try_from ( self ) . map_err ( to_py_err) ?;
215
215
let c_schema_ptr = & c_schema as * const FFI_ArrowSchema ;
216
- let module = py. import_bound ( "pyarrow" ) ?;
216
+ let module = py. import ( "pyarrow" ) ?;
217
217
let class = module. getattr ( "Field" ) ?;
218
218
let dtype = class. call_method1 ( "_import_from_c" , ( c_schema_ptr as Py_uintptr_t , ) ) ?;
219
219
Ok ( dtype. into ( ) )
@@ -249,7 +249,7 @@ impl ToPyArrow for Schema {
249
249
fn to_pyarrow ( & self , py : Python ) -> PyResult < PyObject > {
250
250
let c_schema = FFI_ArrowSchema :: try_from ( self ) . map_err ( to_py_err) ?;
251
251
let c_schema_ptr = & c_schema as * const FFI_ArrowSchema ;
252
- let module = py. import_bound ( "pyarrow" ) ?;
252
+ let module = py. import ( "pyarrow" ) ?;
253
253
let class = module. getattr ( "Schema" ) ?;
254
254
let schema = class. call_method1 ( "_import_from_c" , ( c_schema_ptr as Py_uintptr_t , ) ) ?;
255
255
Ok ( schema. into ( ) )
@@ -309,7 +309,7 @@ impl ToPyArrow for ArrayData {
309
309
let array = FFI_ArrowArray :: new ( self ) ;
310
310
let schema = FFI_ArrowSchema :: try_from ( self . data_type ( ) ) . map_err ( to_py_err) ?;
311
311
312
- let module = py. import_bound ( "pyarrow" ) ?;
312
+ let module = py. import ( "pyarrow" ) ?;
313
313
let class = module. getattr ( "Array" ) ?;
314
314
let array = class. call_method1 (
315
315
"_import_from_c" ,
@@ -318,7 +318,7 @@ impl ToPyArrow for ArrayData {
318
318
addr_of ! ( schema) as Py_uintptr_t ,
319
319
) ,
320
320
) ?;
321
- Ok ( array. to_object ( py ) )
321
+ Ok ( array. unbind ( ) )
322
322
}
323
323
}
324
324
@@ -335,7 +335,7 @@ impl<T: ToPyArrow> ToPyArrow for Vec<T> {
335
335
. iter ( )
336
336
. map ( |v| v. to_pyarrow ( py) )
337
337
. collect :: < PyResult < Vec < _ > > > ( ) ?;
338
- Ok ( values. to_object ( py ) )
338
+ Ok ( PyList :: new ( py , values) ? . unbind ( ) . into ( ) )
339
339
}
340
340
}
341
341
@@ -451,7 +451,7 @@ impl FromPyArrow for ArrowArrayStreamReader {
451
451
// make the conversion through PyArrow's private API
452
452
// this changes the pointer's memory and is thus unsafe.
453
453
// In particular, `_export_to_c` can go out of bounds
454
- let args = PyTuple :: new_bound ( value. py ( ) , [ stream_ptr as Py_uintptr_t ] ) ;
454
+ let args = PyTuple :: new ( value. py ( ) , [ stream_ptr as Py_uintptr_t ] ) ? ;
455
455
value. call_method1 ( "_export_to_c" , args) ?;
456
456
457
457
let stream_reader = ArrowArrayStreamReader :: try_new ( stream)
@@ -469,9 +469,9 @@ impl IntoPyArrow for Box<dyn RecordBatchReader + Send> {
469
469
let mut stream = FFI_ArrowArrayStream :: new ( self ) ;
470
470
471
471
let stream_ptr = ( & mut stream) as * mut FFI_ArrowArrayStream ;
472
- let module = py. import_bound ( "pyarrow" ) ?;
472
+ let module = py. import ( "pyarrow" ) ?;
473
473
let class = module. getattr ( "RecordBatchReader" ) ?;
474
- let args = PyTuple :: new_bound ( py, [ stream_ptr as Py_uintptr_t ] ) ;
474
+ let args = PyTuple :: new ( py, [ stream_ptr as Py_uintptr_t ] ) ? ;
475
475
let reader = class. call_method1 ( "_import_from_c" , args) ?;
476
476
477
477
Ok ( PyObject :: from ( reader) )
@@ -500,11 +500,17 @@ impl<'source, T: FromPyArrow> FromPyObject<'source> for PyArrowType<T> {
500
500
}
501
501
}
502
502
503
- impl < T : IntoPyArrow > IntoPy < PyObject > for PyArrowType < T > {
504
- fn into_py ( self , py : Python ) -> PyObject {
503
+ impl < ' py , T : IntoPyArrow > IntoPyObject < ' py > for PyArrowType < T > {
504
+ type Target = PyAny ;
505
+
506
+ type Output = Bound < ' py , Self :: Target > ;
507
+
508
+ type Error = PyErr ;
509
+
510
+ fn into_pyobject ( self , py : Python < ' py > ) -> Result < Self :: Output , PyErr > {
505
511
match self . 0 . into_pyarrow ( py) {
506
- Ok ( obj) => obj,
507
- Err ( err) => err . to_object ( py ) ,
512
+ Ok ( obj) => Result :: Ok ( obj. into_bound ( py ) ) ,
513
+ Err ( err) => Result :: Err ( err ) ,
508
514
}
509
515
}
510
516
}
0 commit comments