Skip to content

Commit

Permalink
Update pyo3-arrow (#916)
Browse files Browse the repository at this point in the history
Closes #915
  • Loading branch information
kylebarron authored Dec 7, 2024
1 parent 2696846 commit b661c17
Show file tree
Hide file tree
Showing 18 changed files with 72 additions and 72 deletions.
3 changes: 1 addition & 2 deletions python/Cargo.lock

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

3 changes: 2 additions & 1 deletion python/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ numpy = "0.23"
object_store = "0.11"
parquet = "53"
pyo3 = { version = "0.23.0", features = ["hashbrown", "serde", "anyhow"] }
pyo3-arrow = "0.6"
# pyo3-arrow = "0.6"
pyo3-arrow = { git = "https://github.com/kylebarron/arro3", rev = "3709db90908795f10caed6be1509483ca3f9e7c0" }
pyo3-geoarrow = { path = "./pyo3-geoarrow" }
serde_json = "1"
thiserror = "1"
5 changes: 3 additions & 2 deletions python/geoarrow-compute/src/algorithm/native/explode.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use geoarrow::algorithm::native::ExplodeTable;
use pyo3::prelude::*;
use pyo3_arrow::export::Arro3Table;
use pyo3_arrow::PyTable;
use pyo3_geoarrow::PyGeoArrowResult;

use crate::util::{pytable_to_table, table_to_pytable};

#[pyfunction]
pub fn explode(py: Python, input: PyTable) -> PyGeoArrowResult<PyObject> {
pub fn explode(py: Python, input: PyTable) -> PyGeoArrowResult<Arro3Table> {
let table = pytable_to_table(input)?;
let exploded_table = py.allow_threads(|| table.explode(None))?;
Ok(table_to_pytable(exploded_table).to_arro3(py)?)
Ok(table_to_pytable(exploded_table).into())
}
4 changes: 2 additions & 2 deletions python/geoarrow-compute/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ pub(crate) fn return_chunked_geometry_array(
}

pub(crate) fn return_array(py: Python, arr: PyArray) -> PyGeoArrowResult<PyObject> {
Ok(arr.to_arro3(py)?)
Ok(arr.to_arro3(py)?.unbind())
}

pub(crate) fn return_chunked_array(py: Python, arr: PyChunkedArray) -> PyGeoArrowResult<PyObject> {
Ok(arr.to_arro3(py)?)
Ok(arr.to_arro3(py)?.unbind())
}
6 changes: 4 additions & 2 deletions python/geoarrow-core/src/interop/geopandas/from_geopandas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ use pyo3::intern;
use pyo3::prelude::*;
use pyo3::types::{PyDict, PyTuple};
use pyo3::PyAny;
use pyo3_arrow::export::Arro3Table;
use pyo3_arrow::PyTable;
use pyo3_geoarrow::PyGeoArrowResult;

#[pyfunction]
pub fn from_geopandas(py: Python, input: &Bound<PyAny>) -> PyGeoArrowResult<PyObject> {
pub fn from_geopandas(py: Python, input: &Bound<PyAny>) -> PyGeoArrowResult<Arro3Table> {
let geopandas_mod = import_geopandas(py)?;
let geodataframe_class = geopandas_mod.getattr(intern!(py, "GeoDataFrame"))?;
if !input.is_instance(&geodataframe_class)? {
Expand All @@ -26,7 +27,8 @@ pub fn from_geopandas(py: Python, input: &Bound<PyAny>) -> PyGeoArrowResult<PyOb
Some(&kwargs),
)?
.extract::<PyTable>()?;

let table = pytable_to_table(table)?;
let table = table.parse_serialized_geometry(table.default_geometry_column_idx()?, None)?;
Ok(table_to_pytable(table).to_arro3(py)?)
Ok(table_to_pytable(table).into())
}
2 changes: 1 addition & 1 deletion python/geoarrow-core/src/interop/pyogrio/from_pyogrio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub fn read_pyogrio(
Ok(table) => {
let none = py.None();
context_manager.call_method1("__exit__", (&none, &none, &none))?;
Ok(table.to_arro3(py)?)
Ok(table.to_arro3(py)?.unbind())
}
Err(py_err) => {
context_manager.call_method1(
Expand Down
8 changes: 6 additions & 2 deletions python/geoarrow-core/src/interop/wkb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,16 @@ pub fn to_wkb(py: Python, input: AnyNativeInput) -> PyGeoArrowResult<PyObject> {
AnyNativeInput::Array(arr) => {
let wkb_arr = _to_wkb::<i32>(arr.as_ref());
let field = wkb_arr.extension_field();
Ok(PyArray::new(wkb_arr.into_array_ref(), field).to_arro3(py)?)
Ok(PyArray::new(wkb_arr.into_array_ref(), field)
.to_arro3(py)?
.unbind())
}
AnyNativeInput::Chunked(s) => {
let out = s.as_ref().to_wkb::<i32>();
let field = out.extension_field();
Ok(PyChunkedArray::try_new(out.array_refs(), field)?.to_arro3(py)?)
Ok(PyChunkedArray::try_new(out.array_refs(), field)?
.to_arro3(py)?
.unbind())
}
}
}
4 changes: 2 additions & 2 deletions python/geoarrow-core/src/interop/wkt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ pub fn to_wkt(py: Python, input: AnyNativeInput) -> PyGeoArrowResult<PyObject> {
}

pub(crate) fn return_array(py: Python, arr: PyArray) -> PyGeoArrowResult<PyObject> {
Ok(arr.to_arro3(py)?)
Ok(arr.to_arro3(py)?.unbind())
}

pub(crate) fn return_chunked_array(py: Python, arr: PyChunkedArray) -> PyGeoArrowResult<PyObject> {
Ok(arr.to_arro3(py)?)
Ok(arr.to_arro3(py)?.unbind())
}
6 changes: 4 additions & 2 deletions python/geoarrow-io/src/io/csv.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use crate::error::PyGeoArrowResult;
use crate::io::input::sync::{FileReader, FileWriter};
use crate::util::Arro3Table;
use crate::util::to_arro3_table;

use geoarrow::io::csv::read_csv as _read_csv;
use geoarrow::io::csv::write_csv as _write_csv;
use geoarrow::io::csv::CSVReaderOptions;
use pyo3::prelude::*;
use pyo3_arrow::export::Arro3Table;
use pyo3_arrow::input::AnyRecordBatch;

#[pyfunction]
Expand All @@ -16,7 +18,7 @@ pub fn read_csv(
) -> PyGeoArrowResult<Arro3Table> {
let options = CSVReaderOptions::new(Default::default(), batch_size);
let table = _read_csv(&mut file, geometry_column_name, options)?;
Ok(Arro3Table::from_geoarrow(table))
Ok(to_arro3_table(table))
}

#[pyfunction]
Expand Down
5 changes: 3 additions & 2 deletions python/geoarrow-io/src/io/flatgeobuf/async.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::error::PyGeoArrowError;
use crate::io::input::construct_async_reader;
use crate::util::Arro3Table;
use crate::util::to_arro3_table;

use geoarrow::io::flatgeobuf::read_flatgeobuf_async as _read_flatgeobuf_async;
use geoarrow::io::flatgeobuf::FlatGeobufReaderOptions;
use pyo3::prelude::*;
Expand All @@ -27,6 +28,6 @@ pub fn read_flatgeobuf_async<'py>(
let table = _read_flatgeobuf_async(reader.store, reader.path, options)
.await
.map_err(PyGeoArrowError::GeoArrowError)?;
Ok(Arro3Table::from_geoarrow(table))
Ok(to_arro3_table(table))
})
}
8 changes: 5 additions & 3 deletions python/geoarrow-io/src/io/flatgeobuf/sync.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use crate::error::{PyGeoArrowError, PyGeoArrowResult};
use crate::io::input::sync::FileWriter;
use crate::io::input::{construct_reader, AnyFileReader};
use crate::util::Arro3Table;
use crate::util::to_arro3_table;

use geoarrow::io::flatgeobuf::{
read_flatgeobuf as _read_flatgeobuf, write_flatgeobuf_with_options as _write_flatgeobuf,
FlatGeobufReaderOptions, FlatGeobufWriterOptions,
};
use pyo3::prelude::*;
use pyo3_arrow::export::Arro3Table;
use pyo3_arrow::input::AnyRecordBatch;
use pyo3_geoarrow::PyprojCRSTransform;

Expand Down Expand Up @@ -39,7 +41,7 @@ pub fn read_flatgeobuf(
.await
.map_err(PyGeoArrowError::GeoArrowError)?;

Ok(Arro3Table::from_geoarrow(table))
Ok(to_arro3_table(table))
})
}
AnyFileReader::Sync(mut sync_reader) => {
Expand All @@ -49,7 +51,7 @@ pub fn read_flatgeobuf(
..Default::default()
};
let table = _read_flatgeobuf(&mut sync_reader, options)?;
Ok(Arro3Table::from_geoarrow(table))
Ok(to_arro3_table(table))
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions python/geoarrow-io/src/io/geojson.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
use crate::error::PyGeoArrowResult;
use crate::io::input::sync::{FileReader, FileWriter};
use crate::util::Arro3Table;
use crate::util::to_arro3_table;

use geoarrow::io::geojson::read_geojson as _read_geojson;
use geoarrow::io::geojson::write_geojson as _write_geojson;
use pyo3::prelude::*;
use pyo3_arrow::export::Arro3Table;
use pyo3_arrow::PyRecordBatchReader;

#[pyfunction]
#[pyo3(signature = (file, *, batch_size=65536))]
pub fn read_geojson(mut file: FileReader, batch_size: usize) -> PyGeoArrowResult<Arro3Table> {
let table = _read_geojson(&mut file, Some(batch_size))?;
Ok(Arro3Table::from_geoarrow(table))
Ok(to_arro3_table(table))
}

#[pyfunction]
Expand Down
6 changes: 4 additions & 2 deletions python/geoarrow-io/src/io/geojson_lines.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
use crate::error::PyGeoArrowResult;
use crate::io::input::sync::{FileReader, FileWriter};
use crate::util::Arro3Table;
use crate::util::to_arro3_table;

use geoarrow::io::geojson_lines::read_geojson_lines as _read_geojson_lines;
use geoarrow::io::geojson_lines::write_geojson_lines as _write_geojson_lines;
use pyo3::prelude::*;
use pyo3_arrow::export::Arro3Table;
use pyo3_arrow::input::AnyRecordBatch;

#[pyfunction]
#[pyo3(signature = (file, *, batch_size=65536))]
pub fn read_geojson_lines(mut file: FileReader, batch_size: usize) -> PyGeoArrowResult<Arro3Table> {
let table = _read_geojson_lines(&mut file, Some(batch_size))?;
Ok(Arro3Table::from_geoarrow(table))
Ok(to_arro3_table(table))
}

#[pyfunction]
Expand Down
27 changes: 16 additions & 11 deletions python/geoarrow-io/src/io/parquet/async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::io::input::{construct_reader, AnyFileReader, AsyncFileReader};
use crate::io::parquet::options::create_options;
#[cfg(feature = "async")]
use crate::runtime::get_runtime;
use crate::util::Arro3Table;
use crate::util::to_arro3_table;

use arrow::datatypes::SchemaRef;
use geo_traits::CoordTrait;
Expand All @@ -23,7 +23,8 @@ use parquet::arrow::arrow_reader::{ArrowReaderMetadata, ArrowReaderOptions};
use parquet::arrow::async_reader::ParquetObjectReader;
use pyo3::exceptions::PyValueError;
use pyo3::prelude::*;
use pyo3_arrow::{PyArray, PySchema};
use pyo3_arrow::export::{Arro3Schema, Arro3Table};
use pyo3_arrow::PyArray;
use pyo3_async_runtimes::tokio::future_into_py;
use pyo3_geoarrow::CRS;
use pyo3_object_store::PyObjectStore;
Expand Down Expand Up @@ -74,7 +75,7 @@ async fn read_parquet_async_inner(
.read_table()
.await?;

Ok(Arro3Table::from_geoarrow(table))
Ok(to_arro3_table(table))
}

/// Reader interface for a single Parquet file.
Expand Down Expand Up @@ -122,9 +123,9 @@ impl ParquetFile {
}

#[getter]
fn schema_arrow(&self, py: Python) -> PyGeoArrowResult<PyObject> {
fn schema_arrow(&self) -> PyGeoArrowResult<Arro3Schema> {
let schema = self.geoparquet_meta.resolved_schema(Default::default())?;
Ok(PySchema::new(schema).to_arro3(py)?)
Ok(schema.into())
}

#[pyo3(signature = (column_name=None))]
Expand Down Expand Up @@ -171,7 +172,11 @@ impl ParquetFile {
let paths: Option<GeoParquetBboxCovering> =
bbox_paths.map(|x| depythonize(&x)).transpose()?;
let bounds = self.geoparquet_meta.row_groups_bounds(paths.as_ref())?;
Ok(PyArray::new(bounds.to_array_ref(), bounds.extension_field()).to_arro3(py)?)
Ok(
PyArray::new(bounds.to_array_ref(), bounds.extension_field())
.to_arro3(py)?
.unbind(),
)
}

#[pyo3(signature = (column_name=None))]
Expand Down Expand Up @@ -202,7 +207,7 @@ impl ParquetFile {
.read_table()
.await
.map_err(PyGeoArrowError::GeoArrowError)?;
Ok(Arro3Table::from_geoarrow(table))
Ok(to_arro3_table(table))
})?;
Ok(fut.into())
}
Expand Down Expand Up @@ -231,7 +236,7 @@ impl ParquetFile {
.read_table()
.await
.map_err(PyGeoArrowError::GeoArrowError)?;
Ok(Arro3Table::from_geoarrow(table))
Ok(to_arro3_table(table))
})
}
}
Expand Down Expand Up @@ -369,7 +374,7 @@ impl ParquetDataset {
});
let table =
Table::try_new(all_batches, output_schema).map_err(PyGeoArrowError::GeoArrowError)?;
Ok(Arro3Table::from_geoarrow(table))
Ok(to_arro3_table(table))
}
}

Expand Down Expand Up @@ -401,9 +406,9 @@ impl ParquetDataset {
}

#[getter]
fn schema_arrow(&self, py: Python) -> PyGeoArrowResult<PyObject> {
fn schema_arrow(&self) -> PyGeoArrowResult<Arro3Schema> {
let schema = self.meta.resolved_schema(Default::default())?;
Ok(PySchema::new(schema).to_arro3(py)?)
Ok(schema.into())
}

#[pyo3(signature = (column_name=None))]
Expand Down
7 changes: 4 additions & 3 deletions python/geoarrow-io/src/io/parquet/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ use std::sync::Mutex;
use crate::error::{PyGeoArrowError, PyGeoArrowResult};
use crate::io::input::sync::FileWriter;
use crate::io::input::{construct_reader, AnyFileReader};
use crate::util::Arro3Table;
use crate::util::to_arro3_table;

use geoarrow::io::parquet::{GeoParquetReaderOptions, GeoParquetRecordBatchReaderBuilder};
use parquet::arrow::arrow_reader::ArrowReaderOptions;
use pyo3::exceptions::PyValueError;
use pyo3::prelude::*;
use pyo3_arrow::export::Arro3Table;
use pyo3_arrow::PyRecordBatch;
use pyo3_arrow::PySchema;

Expand Down Expand Up @@ -62,7 +63,7 @@ pub fn read_parquet(
.read_table()
.await?;

Ok::<_, PyGeoArrowError>(Arro3Table::from_geoarrow(table))
Ok::<_, PyGeoArrowError>(to_arro3_table(table))
})?;
Ok(table)
}
Expand All @@ -80,7 +81,7 @@ pub fn read_parquet(
)?
.build()?
.read_table()?;
Ok(Arro3Table::from_geoarrow(table))
Ok(to_arro3_table(table))
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions python/geoarrow-io/src/io/postgis.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use crate::error::PyGeoArrowError;
use crate::util::Arro3Table;
use crate::util::to_arro3_table;

use geoarrow::error::GeoArrowError;
use geoarrow::io::postgis::read_postgis as _read_postgis;
use pyo3::prelude::*;
use pyo3_arrow::export::Arro3Table;
use pyo3_async_runtimes::tokio::future_into_py;
use sqlx::postgres::PgPoolOptions;

Expand Down Expand Up @@ -37,5 +39,5 @@ async fn read_postgis_inner(connection_url: String, sql: String) -> PyResult<Opt
.await
.map_err(PyGeoArrowError::GeoArrowError)?;

Ok(table.map(Arro3Table::from_geoarrow))
Ok(table.map(to_arro3_table))
}
5 changes: 3 additions & 2 deletions python/geoarrow-io/src/io/shapefile.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use crate::error::PyGeoArrowResult;
use crate::io::input::sync::FileReader;
use crate::util::Arro3Table;
use crate::util::to_arro3_table;
use geoarrow::io::shapefile::read_shapefile as _read_shapefile;
use pyo3::prelude::*;
use pyo3_arrow::export::Arro3Table;

#[pyfunction]
// #[pyo3(signature = (file, *, batch_size=65536))]
Expand All @@ -11,5 +12,5 @@ pub fn read_shapefile(
mut dbf_file: FileReader,
) -> PyGeoArrowResult<Arro3Table> {
let table = _read_shapefile(&mut shp_file, &mut dbf_file)?;
Ok(Arro3Table::from_geoarrow(table))
Ok(to_arro3_table(table))
}
Loading

0 comments on commit b661c17

Please sign in to comment.