Skip to content

Commit e65787a

Browse files
authored
update to pyo3 0.23.0 (apache#6745)
1 parent 0974cff commit e65787a

File tree

4 files changed

+23
-17
lines changed

4 files changed

+23
-17
lines changed

arrow-pyarrow-integration-testing/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ crate-type = ["cdylib"]
3434

3535
[dependencies]
3636
arrow = { path = "../arrow", features = ["pyarrow"] }
37-
pyo3 = { version = "0.22", features = ["extension-module"] }
37+
pyo3 = { version = "0.23", features = ["extension-module"] }

arrow-pyarrow-integration-testing/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ fn to_py_err(err: ArrowError) -> PyErr {
4343
#[pyfunction]
4444
fn double(array: &Bound<PyAny>, py: Python) -> PyResult<PyObject> {
4545
// import
46-
let array = make_array(ArrayData::from_pyarrow_bound(&array)?);
46+
let array = make_array(ArrayData::from_pyarrow_bound(array)?);
4747

4848
// perform some operation
4949
let array = array

arrow/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ arrow-select = { workspace = true }
5454
arrow-string = { workspace = true }
5555

5656
rand = { version = "0.8", default-features = false, features = ["std", "std_rng"], optional = true }
57-
pyo3 = { version = "0.22.2", default-features = false, optional = true }
57+
pyo3 = { version = "0.23", default-features = false, optional = true }
5858

5959
chrono = { workspace = true, optional = true }
6060

arrow/src/pyarrow.rs

+20-14
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ impl<T: ToPyArrow> IntoPyArrow for T {
111111
}
112112

113113
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")?;
115115
let class = pyarrow.getattr(expected)?;
116116
if !value.is_instance(&class)? {
117117
let expected_module = class.getattr("__module__")?.extract::<PyBackedStr>()?;
@@ -177,7 +177,7 @@ impl ToPyArrow for DataType {
177177
fn to_pyarrow(&self, py: Python) -> PyResult<PyObject> {
178178
let c_schema = FFI_ArrowSchema::try_from(self).map_err(to_py_err)?;
179179
let c_schema_ptr = &c_schema as *const FFI_ArrowSchema;
180-
let module = py.import_bound("pyarrow")?;
180+
let module = py.import("pyarrow")?;
181181
let class = module.getattr("DataType")?;
182182
let dtype = class.call_method1("_import_from_c", (c_schema_ptr as Py_uintptr_t,))?;
183183
Ok(dtype.into())
@@ -213,7 +213,7 @@ impl ToPyArrow for Field {
213213
fn to_pyarrow(&self, py: Python) -> PyResult<PyObject> {
214214
let c_schema = FFI_ArrowSchema::try_from(self).map_err(to_py_err)?;
215215
let c_schema_ptr = &c_schema as *const FFI_ArrowSchema;
216-
let module = py.import_bound("pyarrow")?;
216+
let module = py.import("pyarrow")?;
217217
let class = module.getattr("Field")?;
218218
let dtype = class.call_method1("_import_from_c", (c_schema_ptr as Py_uintptr_t,))?;
219219
Ok(dtype.into())
@@ -249,7 +249,7 @@ impl ToPyArrow for Schema {
249249
fn to_pyarrow(&self, py: Python) -> PyResult<PyObject> {
250250
let c_schema = FFI_ArrowSchema::try_from(self).map_err(to_py_err)?;
251251
let c_schema_ptr = &c_schema as *const FFI_ArrowSchema;
252-
let module = py.import_bound("pyarrow")?;
252+
let module = py.import("pyarrow")?;
253253
let class = module.getattr("Schema")?;
254254
let schema = class.call_method1("_import_from_c", (c_schema_ptr as Py_uintptr_t,))?;
255255
Ok(schema.into())
@@ -309,7 +309,7 @@ impl ToPyArrow for ArrayData {
309309
let array = FFI_ArrowArray::new(self);
310310
let schema = FFI_ArrowSchema::try_from(self.data_type()).map_err(to_py_err)?;
311311

312-
let module = py.import_bound("pyarrow")?;
312+
let module = py.import("pyarrow")?;
313313
let class = module.getattr("Array")?;
314314
let array = class.call_method1(
315315
"_import_from_c",
@@ -318,7 +318,7 @@ impl ToPyArrow for ArrayData {
318318
addr_of!(schema) as Py_uintptr_t,
319319
),
320320
)?;
321-
Ok(array.to_object(py))
321+
Ok(array.unbind())
322322
}
323323
}
324324

@@ -335,7 +335,7 @@ impl<T: ToPyArrow> ToPyArrow for Vec<T> {
335335
.iter()
336336
.map(|v| v.to_pyarrow(py))
337337
.collect::<PyResult<Vec<_>>>()?;
338-
Ok(values.to_object(py))
338+
Ok(PyList::new(py, values)?.unbind().into())
339339
}
340340
}
341341

@@ -451,7 +451,7 @@ impl FromPyArrow for ArrowArrayStreamReader {
451451
// make the conversion through PyArrow's private API
452452
// this changes the pointer's memory and is thus unsafe.
453453
// 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])?;
455455
value.call_method1("_export_to_c", args)?;
456456

457457
let stream_reader = ArrowArrayStreamReader::try_new(stream)
@@ -469,9 +469,9 @@ impl IntoPyArrow for Box<dyn RecordBatchReader + Send> {
469469
let mut stream = FFI_ArrowArrayStream::new(self);
470470

471471
let stream_ptr = (&mut stream) as *mut FFI_ArrowArrayStream;
472-
let module = py.import_bound("pyarrow")?;
472+
let module = py.import("pyarrow")?;
473473
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])?;
475475
let reader = class.call_method1("_import_from_c", args)?;
476476

477477
Ok(PyObject::from(reader))
@@ -500,11 +500,17 @@ impl<'source, T: FromPyArrow> FromPyObject<'source> for PyArrowType<T> {
500500
}
501501
}
502502

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> {
505511
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),
508514
}
509515
}
510516
}

0 commit comments

Comments
 (0)