You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2021/08/11 15:17:35 UTC

[GitHub] [arrow-datafusion] kszucs commented on a change in pull request #856: Rework the python bindings [WIP]

kszucs commented on a change in pull request #856:
URL: https://github.com/apache/arrow-datafusion/pull/856#discussion_r686931737



##########
File path: python/src/pyarrow.rs
##########
@@ -0,0 +1,205 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use std::convert::TryFrom;
+use std::sync::Arc;
+
+use libc::uintptr_t;
+use pyo3::exceptions::PyNotImplementedError;
+use pyo3::prelude::*;
+use pyo3::types::PyList;
+
+use datafusion::arrow::array::{make_array_from_raw, ArrayRef};
+use datafusion::arrow::datatypes::{DataType, Field, Schema};
+use datafusion::arrow::ffi;
+use datafusion::arrow::ffi::FFI_ArrowSchema;
+use datafusion::arrow::record_batch::RecordBatch;
+use datafusion::scalar::ScalarValue;
+
+use crate::errors::DataFusionError;
+
+pub trait PyArrowConvert: Sized {
+    fn from_pyarrow(value: &PyAny) -> PyResult<Self>;
+    fn to_pyarrow(&self, py: Python) -> PyResult<PyObject>;
+}
+
+impl PyArrowConvert for DataType {

Review comment:
       I'm going to try adding this module to `arrow-rs` as an optional one, so we can implement the `PyO3` conversion traits, like `FromPyObject` directly for the arrow types. 
   This will further reduce the required conversion boilerplate in the python bindinds. 
   
   For example we should be able to write
   ```rust
   fn create_dataframe(
           &mut self,
           partitions: Vec<Vec<RecordBatch>>,
       ) -> PyResult<PyDataFrame> {
           // partitions are going to be converted by PyO3 automatically
   ```
   
   instead of
   
   ```rust
   fn create_dataframe(
           &mut self,
           partitions: Vec<Vec<&PyAny>>,
       ) -> PyResult<PyDataFrame> {
           let partitions: Vec<Vec<RecordBatch>> = partitions
               .into_iter()
               .map(|batches| {
                   batches
                       .into_iter()
                       .map(RecordBatch::from_pyarrow)
                       .collect::<PyResult<_>>()
               })
               .collect::<PyResult<_>>()?;
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org