@@ -132,7 +132,7 @@ impl<T: ToPyArrow> IntoPyArrow for T {
132
132
}
133
133
134
134
fn validate_class ( expected : & str , value : & Bound < PyAny > ) -> PyResult < ( ) > {
135
- let pyarrow = PyModule :: import_bound ( value. py ( ) , "pyarrow" ) ?;
135
+ let pyarrow = PyModule :: import ( value. py ( ) , "pyarrow" ) ?;
136
136
let class = pyarrow. getattr ( expected) ?;
137
137
if !value. is_instance ( & class) ? {
138
138
let expected_module = class. getattr ( "__module__" ) ?. extract :: < PyBackedStr > ( ) ?;
@@ -198,7 +198,7 @@ impl ToPyArrow for DataType {
198
198
fn to_pyarrow ( & self , py : Python ) -> PyResult < PyObject > {
199
199
let c_schema = FFI_ArrowSchema :: try_from ( self ) . map_err ( to_py_err) ?;
200
200
let c_schema_ptr = & c_schema as * const FFI_ArrowSchema ;
201
- let module = py. import_bound ( "pyarrow" ) ?;
201
+ let module = py. import ( "pyarrow" ) ?;
202
202
let class = module. getattr ( "DataType" ) ?;
203
203
let dtype = class. call_method1 ( "_import_from_c" , ( c_schema_ptr as Py_uintptr_t , ) ) ?;
204
204
Ok ( dtype. into ( ) )
@@ -234,7 +234,7 @@ impl ToPyArrow for Field {
234
234
fn to_pyarrow ( & self , py : Python ) -> PyResult < PyObject > {
235
235
let c_schema = FFI_ArrowSchema :: try_from ( self ) . map_err ( to_py_err) ?;
236
236
let c_schema_ptr = & c_schema as * const FFI_ArrowSchema ;
237
- let module = py. import_bound ( "pyarrow" ) ?;
237
+ let module = py. import ( "pyarrow" ) ?;
238
238
let class = module. getattr ( "Field" ) ?;
239
239
let dtype = class. call_method1 ( "_import_from_c" , ( c_schema_ptr as Py_uintptr_t , ) ) ?;
240
240
Ok ( dtype. into ( ) )
@@ -270,7 +270,7 @@ impl ToPyArrow for Schema {
270
270
fn to_pyarrow ( & self , py : Python ) -> PyResult < PyObject > {
271
271
let c_schema = FFI_ArrowSchema :: try_from ( self ) . map_err ( to_py_err) ?;
272
272
let c_schema_ptr = & c_schema as * const FFI_ArrowSchema ;
273
- let module = py. import_bound ( "pyarrow" ) ?;
273
+ let module = py. import ( "pyarrow" ) ?;
274
274
let class = module. getattr ( "Schema" ) ?;
275
275
let schema = class. call_method1 ( "_import_from_c" , ( c_schema_ptr as Py_uintptr_t , ) ) ?;
276
276
Ok ( schema. into ( ) )
@@ -330,7 +330,7 @@ impl ToPyArrow for ArrayData {
330
330
let array = FFI_ArrowArray :: new ( self ) ;
331
331
let schema = FFI_ArrowSchema :: try_from ( self . data_type ( ) ) . map_err ( to_py_err) ?;
332
332
333
- let module = py. import_bound ( "pyarrow" ) ?;
333
+ let module = py. import ( "pyarrow" ) ?;
334
334
let class = module. getattr ( "Array" ) ?;
335
335
let array = class. call_method1 (
336
336
"_import_from_c" ,
@@ -339,7 +339,7 @@ impl ToPyArrow for ArrayData {
339
339
addr_of ! ( schema) as Py_uintptr_t ,
340
340
) ,
341
341
) ?;
342
- Ok ( array. to_object ( py ) )
342
+ Ok ( array. unbind ( ) )
343
343
}
344
344
}
345
345
@@ -356,7 +356,7 @@ impl<T: ToPyArrow> ToPyArrow for Vec<T> {
356
356
. iter ( )
357
357
. map ( |v| v. to_pyarrow ( py) )
358
358
. collect :: < PyResult < Vec < _ > > > ( ) ?;
359
- Ok ( values. to_object ( py ) )
359
+ Ok ( PyList :: new ( py , values) ? . unbind ( ) . into ( ) )
360
360
}
361
361
}
362
362
@@ -472,7 +472,7 @@ impl FromPyArrow for ArrowArrayStreamReader {
472
472
// make the conversion through PyArrow's private API
473
473
// this changes the pointer's memory and is thus unsafe.
474
474
// In particular, `_export_to_c` can go out of bounds
475
- let args = PyTuple :: new_bound ( value. py ( ) , [ stream_ptr as Py_uintptr_t ] ) ;
475
+ let args = PyTuple :: new ( value. py ( ) , [ stream_ptr as Py_uintptr_t ] ) ? ;
476
476
value. call_method1 ( "_export_to_c" , args) ?;
477
477
478
478
let stream_reader = ArrowArrayStreamReader :: try_new ( stream)
@@ -490,9 +490,9 @@ impl IntoPyArrow for Box<dyn RecordBatchReader + Send> {
490
490
let mut stream = FFI_ArrowArrayStream :: new ( self ) ;
491
491
492
492
let stream_ptr = ( & mut stream) as * mut FFI_ArrowArrayStream ;
493
- let module = py. import_bound ( "pyarrow" ) ?;
493
+ let module = py. import ( "pyarrow" ) ?;
494
494
let class = module. getattr ( "RecordBatchReader" ) ?;
495
- let args = PyTuple :: new_bound ( py, [ stream_ptr as Py_uintptr_t ] ) ;
495
+ let args = PyTuple :: new ( py, [ stream_ptr as Py_uintptr_t ] ) ? ;
496
496
let reader = class. call_method1 ( "_import_from_c" , args) ?;
497
497
498
498
Ok ( PyObject :: from ( reader) )
@@ -521,11 +521,17 @@ impl<'source, T: FromPyArrow> FromPyObject<'source> for PyArrowType<T> {
521
521
}
522
522
}
523
523
524
- impl < T : IntoPyArrow > IntoPy < PyObject > for PyArrowType < T > {
525
- fn into_py ( self , py : Python ) -> PyObject {
524
+ impl < ' py , T : IntoPyArrow > IntoPyObject < ' py > for PyArrowType < T > {
525
+ type Target = PyAny ;
526
+
527
+ type Output = Bound < ' py , Self :: Target > ;
528
+
529
+ type Error = PyErr ;
530
+
531
+ fn into_pyobject ( self , py : Python < ' py > ) -> Result < Self :: Output , PyErr > {
526
532
match self . 0 . into_pyarrow ( py) {
527
- Ok ( obj) => obj,
528
- Err ( err) => err . to_object ( py ) ,
533
+ Ok ( obj) => Result :: Ok ( obj. into_bound ( py ) ) ,
534
+ Err ( err) => Result :: Err ( err ) ,
529
535
}
530
536
}
531
537
}
0 commit comments