Skip to content

Commit 05b08b4

Browse files
psvrialamb
authored andcommitted
update to pyo3 0.23.0 (apache#6745)
1 parent 9fade5f commit 05b08b4

File tree

4 files changed

+23
-17
lines changed

4 files changed

+23
-17
lines changed

arrow-pyarrow-integration-testing/Cargo.toml

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ impl<T: ToPyArrow> IntoPyArrow for T {
132132
}
133133

134134
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")?;
136136
let class = pyarrow.getattr(expected)?;
137137
if !value.is_instance(&class)? {
138138
let expected_module = class.getattr("__module__")?.extract::<PyBackedStr>()?;
@@ -198,7 +198,7 @@ impl ToPyArrow for DataType {
198198
fn to_pyarrow(&self, py: Python) -> PyResult<PyObject> {
199199
let c_schema = FFI_ArrowSchema::try_from(self).map_err(to_py_err)?;
200200
let c_schema_ptr = &c_schema as *const FFI_ArrowSchema;
201-
let module = py.import_bound("pyarrow")?;
201+
let module = py.import("pyarrow")?;
202202
let class = module.getattr("DataType")?;
203203
let dtype = class.call_method1("_import_from_c", (c_schema_ptr as Py_uintptr_t,))?;
204204
Ok(dtype.into())
@@ -234,7 +234,7 @@ impl ToPyArrow for Field {
234234
fn to_pyarrow(&self, py: Python) -> PyResult<PyObject> {
235235
let c_schema = FFI_ArrowSchema::try_from(self).map_err(to_py_err)?;
236236
let c_schema_ptr = &c_schema as *const FFI_ArrowSchema;
237-
let module = py.import_bound("pyarrow")?;
237+
let module = py.import("pyarrow")?;
238238
let class = module.getattr("Field")?;
239239
let dtype = class.call_method1("_import_from_c", (c_schema_ptr as Py_uintptr_t,))?;
240240
Ok(dtype.into())
@@ -270,7 +270,7 @@ impl ToPyArrow for Schema {
270270
fn to_pyarrow(&self, py: Python) -> PyResult<PyObject> {
271271
let c_schema = FFI_ArrowSchema::try_from(self).map_err(to_py_err)?;
272272
let c_schema_ptr = &c_schema as *const FFI_ArrowSchema;
273-
let module = py.import_bound("pyarrow")?;
273+
let module = py.import("pyarrow")?;
274274
let class = module.getattr("Schema")?;
275275
let schema = class.call_method1("_import_from_c", (c_schema_ptr as Py_uintptr_t,))?;
276276
Ok(schema.into())
@@ -330,7 +330,7 @@ impl ToPyArrow for ArrayData {
330330
let array = FFI_ArrowArray::new(self);
331331
let schema = FFI_ArrowSchema::try_from(self.data_type()).map_err(to_py_err)?;
332332

333-
let module = py.import_bound("pyarrow")?;
333+
let module = py.import("pyarrow")?;
334334
let class = module.getattr("Array")?;
335335
let array = class.call_method1(
336336
"_import_from_c",
@@ -339,7 +339,7 @@ impl ToPyArrow for ArrayData {
339339
addr_of!(schema) as Py_uintptr_t,
340340
),
341341
)?;
342-
Ok(array.to_object(py))
342+
Ok(array.unbind())
343343
}
344344
}
345345

@@ -356,7 +356,7 @@ impl<T: ToPyArrow> ToPyArrow for Vec<T> {
356356
.iter()
357357
.map(|v| v.to_pyarrow(py))
358358
.collect::<PyResult<Vec<_>>>()?;
359-
Ok(values.to_object(py))
359+
Ok(PyList::new(py, values)?.unbind().into())
360360
}
361361
}
362362

@@ -472,7 +472,7 @@ impl FromPyArrow for ArrowArrayStreamReader {
472472
// make the conversion through PyArrow's private API
473473
// this changes the pointer's memory and is thus unsafe.
474474
// 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])?;
476476
value.call_method1("_export_to_c", args)?;
477477

478478
let stream_reader = ArrowArrayStreamReader::try_new(stream)
@@ -490,9 +490,9 @@ impl IntoPyArrow for Box<dyn RecordBatchReader + Send> {
490490
let mut stream = FFI_ArrowArrayStream::new(self);
491491

492492
let stream_ptr = (&mut stream) as *mut FFI_ArrowArrayStream;
493-
let module = py.import_bound("pyarrow")?;
493+
let module = py.import("pyarrow")?;
494494
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])?;
496496
let reader = class.call_method1("_import_from_c", args)?;
497497

498498
Ok(PyObject::from(reader))
@@ -521,11 +521,17 @@ impl<'source, T: FromPyArrow> FromPyObject<'source> for PyArrowType<T> {
521521
}
522522
}
523523

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> {
526532
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),
529535
}
530536
}
531537
}

0 commit comments

Comments
 (0)