Skip to content

Commit

Permalink
Bump to pyo3 0.22 (#848)
Browse files Browse the repository at this point in the history
Preparatory work for testing integration with pyo3-object-store.
  • Loading branch information
kylebarron authored Nov 4, 2024
1 parent e74b291 commit c5b0bf2
Show file tree
Hide file tree
Showing 23 changed files with 91 additions and 86 deletions.
44 changes: 22 additions & 22 deletions python/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions python/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ geoarrow = { path = "../rust/geoarrow" }
# geoarrow = { version = "0.4.0-beta.1" }
geozero = "0.14"
indexmap = "2.5.0"
numpy = "0.22"
object_store = "0.11"
parquet = "53"
pyo3 = { version = "0.21.0", features = ["hashbrown", "serde", "anyhow"] }
pyo3-arrow = "0.4"
pyo3 = { version = "0.22.0", features = ["hashbrown", "serde", "anyhow"] }
pyo3-arrow = "0.5.1"
serde_json = "1"
thiserror = "1"
2 changes: 1 addition & 1 deletion python/geoarrow-compute/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pyo3-geoarrow = { path = "../pyo3-geoarrow" }
geo = "0.28"
geoarrow = { workspace = true }
geozero = { version = "0.14", features = ["with-svg"] }
numpy = "0.21"
numpy = { workspace = true }
serde_json = "1"
thiserror = "1"
url = "2.5"
2 changes: 1 addition & 1 deletion python/geoarrow-compute/src/algorithm/geo/area.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub enum AreaMethod {
}

impl<'a> FromPyObject<'a> for AreaMethod {
fn extract(ob: &'a PyAny) -> PyResult<Self> {
fn extract_bound(ob: &Bound<'a, PyAny>) -> PyResult<Self> {
let s: String = ob.extract()?;
match s.to_lowercase().as_str() {
"ellipsoidal" => Ok(Self::Geodesic),
Expand Down
2 changes: 1 addition & 1 deletion python/geoarrow-compute/src/broadcasting/primitive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use pyo3::prelude::*;
pub struct BroadcastableFloat(pub(crate) BroadcastablePrimitive<Float64Type>);

impl<'a> FromPyObject<'a> for BroadcastableFloat {
fn extract(_ob: &'a PyAny) -> PyResult<Self> {
fn extract_bound(_ob: &Bound<'a, PyAny>) -> PyResult<Self> {
todo!()
// Python::with_gil(|py| {
// let pa = py.import_bound("pyarrow")?;
Expand Down
2 changes: 1 addition & 1 deletion python/geoarrow-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pyo3-geoarrow = { path = "../pyo3-geoarrow" }
geo = "0.28"
geoarrow = { workspace = true }
geozero = { version = "0.14", features = ["with-svg"] }
numpy = "0.21"
numpy = { workspace = true }
serde_json = "1"
thiserror = "1"
url = "2.5"
9 changes: 5 additions & 4 deletions python/geoarrow-core/src/interop/shapely/from_shapely.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ use geoarrow::datatypes::{Dimension, NativeType};
use pyo3::exceptions::PyValueError;
use pyo3::intern;
use pyo3::prelude::*;
use pyo3::types::{PyBytes, PyDict, PyString, PyTuple};
use pyo3::pybacked::PyBackedBytes;
use pyo3::types::{PyDict, PyString, PyTuple};
use pyo3::PyAny;
use pyo3_geoarrow::PyGeoArrowResult;

Expand Down Expand Up @@ -90,7 +91,7 @@ pub fn from_shapely(
shapely_mod.call_method(intern!(py, "to_ragged_array"), (input,), Some(&kwargs))
{
let (geom_type, coords, offsets) =
ragged_array_output.extract::<(&PyAny, Bound<PyAny>, PyObject)>()?;
ragged_array_output.extract::<(Bound<PyAny>, Bound<PyAny>, PyObject)>()?;
let coords = numpy_mod.call_method1(
intern!(py, "ascontiguousarray"),
PyTuple::new_bound(py, vec![coords]),
Expand Down Expand Up @@ -181,8 +182,8 @@ fn make_wkb_arr(
let mut builder = BinaryBuilder::with_capacity(wkb_result.len()?, 0);

for item in wkb_result.iter()? {
let x = item?.extract::<&PyBytes>()?;
builder.append_value(x.as_bytes());
let buf = item?.extract::<PyBackedBytes>()?;
builder.append_value(buf.as_ref());
}

Ok(geoarrow::array::WKBArray::new(builder.finish(), metadata))
Expand Down
6 changes: 3 additions & 3 deletions python/geoarrow-io/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async = [
"dep:futures",
"dep:object_store",
"parquet/object_store",
"dep:pyo3-asyncio-0-21",
"dep:pyo3-async-runtimes",
"geoarrow/flatgeobuf_async",
"geoarrow/parquet_async",
"geoarrow/postgis",
Expand All @@ -45,10 +45,10 @@ object_store = { workspace = true, features = [
parquet = { workspace = true }
pyo3 = { workspace = true }
pyo3-arrow = { workspace = true }
pyo3-asyncio-0-21 = { version = "0.21", features = [
pyo3-async-runtimes = { version = "0.22", features = [
"tokio-runtime",
], optional = true }
pythonize = "0.21"
pythonize = "0.22"
geo = "0.28"
geo-traits = { workspace = true }
geoarrow = { workspace = true, features = [
Expand Down
14 changes: 7 additions & 7 deletions python/geoarrow-io/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use pyo3::prelude::*;

pub enum PyGeoArrowError {
GeoArrowError(geoarrow::error::GeoArrowError),
PyErr(PyErr),
PyArrowError(pyo3_arrow::error::PyArrowError),
PyErr(PyErr),
PythonizeError(pythonize::PythonizeError),
#[cfg(feature = "async")]
ObjectStoreError(object_store::Error),
Expand Down Expand Up @@ -75,15 +75,15 @@ impl From<url::ParseError> for PyGeoArrowError {
}
}

impl From<PyTypeError> for PyGeoArrowError {
fn from(other: PyTypeError) -> Self {
Self::PyErr((&other).into())
impl From<Bound<'_, PyTypeError>> for PyGeoArrowError {
fn from(other: Bound<'_, PyTypeError>) -> Self {
Self::PyErr(other.into())
}
}

impl From<PyValueError> for PyGeoArrowError {
fn from(other: PyValueError) -> Self {
Self::PyErr((&other).into())
impl From<Bound<'_, PyValueError>> for PyGeoArrowError {
fn from(other: Bound<'_, PyValueError>) -> Self {
Self::PyErr((other).into())
}
}

Expand Down
3 changes: 2 additions & 1 deletion python/geoarrow-io/src/io/flatgeobuf/async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use geoarrow::io::flatgeobuf::read_flatgeobuf_async as _read_flatgeobuf_async;
use geoarrow::io::flatgeobuf::FlatGeobufReaderOptions;
use pyo3::exceptions::PyValueError;
use pyo3::prelude::*;
use pyo3_async_runtimes::tokio::future_into_py;

#[pyfunction]
#[pyo3(signature = (path, *, fs=None, batch_size=65536, bbox=None))]
Expand All @@ -18,7 +19,7 @@ pub fn read_flatgeobuf_async(
let reader = construct_reader(py, path, fs)?;
match reader {
AnyFileReader::Async(async_reader) => {
let fut = pyo3_asyncio_0_21::tokio::future_into_py(py, async move {
let fut = future_into_py(py, async move {
let options = FlatGeobufReaderOptions {
batch_size: Some(batch_size),
bbox,
Expand Down
36 changes: 14 additions & 22 deletions python/geoarrow-io/src/io/input/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,22 @@ use std::path::{Path, PathBuf};

#[derive(Debug)]
pub struct PyFileLikeObject {
// We use PyObject instead of Bound<PyAny> because Bound<PyAny> is a GIL-bound type.
// We want to avoid holding the GIL when creating the struct.
// The GIL will be re-taken when the methods are called.
inner: PyObject,
is_text_io: bool,
}

impl Clone for PyFileLikeObject {
fn clone(&self) -> Self {
Python::with_gil(|py| PyFileLikeObject {
inner: self.inner.clone_ref(py),
is_text_io: self.is_text_io,
})
}
}

/// Wraps a `PyObject`, and implements read, seek, and write for it.
impl PyFileLikeObject {
/// Creates an instance of a `PyFileLikeObject` from a `PyObject`.
Expand Down Expand Up @@ -89,14 +101,6 @@ impl PyFileLikeObject {
}
}

impl Clone for PyFileLikeObject {
fn clone(&self) -> Self {
Python::with_gil(|py| {
PyFileLikeObject::new(self.inner.clone_ref(py)).expect("Failed to clone")
})
}
}

/// Extracts a string repr from, and returns an IO error to send back to rust.
fn pyerr_to_io_err(e: PyErr) -> io::Error {
Python::with_gil(|py| {
Expand Down Expand Up @@ -326,13 +330,7 @@ impl<'py> FromPyObject<'py> for FileReader {
Ok(Self::File(path.clone(), BufReader::new(File::open(path)?)))
} else {
Ok(Self::FileLike(BufReader::new(
PyFileLikeObject::with_requirements(
ob.as_gil_ref().into(),
true,
false,
true,
false,
)?,
PyFileLikeObject::with_requirements(ob.clone().unbind(), true, false, true, false)?,
)))
}
}
Expand Down Expand Up @@ -406,13 +404,7 @@ impl<'py> FromPyObject<'py> for FileWriter {
))
} else {
Ok(Self::FileLike(BufWriter::new(
PyFileLikeObject::with_requirements(
ob.as_gil_ref().into(),
false,
true,
true,
false,
)?,
PyFileLikeObject::with_requirements(ob.clone().unbind(), false, true, true, false)?,
)))
}
}
Expand Down
1 change: 1 addition & 0 deletions python/geoarrow-io/src/io/object_store/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ impl PyObjectStore {
/// options: a dict of options (e.g. authentication settings) for connecting to the object
/// store.
#[new]
#[pyo3(signature = (root, options = None, client_options = None))]
fn new(
root: String,
options: Option<HashMap<String, String>>,
Expand Down
Loading

0 comments on commit c5b0bf2

Please sign in to comment.