Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
kszucs committed Aug 31, 2021
1 parent 043511b commit 713935f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
3 changes: 1 addition & 2 deletions arrow/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ hex = "0.4"
comfy-table = { version = "4.0", optional = true, default-features = false }
prettytable-rs = { version = "0.8.0", optional = true }
pyo3 = { version = "0.14", optional = true }
libc = { version = "0.2", optional = true }
lexical-core = "^0.7"
multiversion = "0.6.1"
bitflags = "1.2.1"
Expand All @@ -73,7 +72,7 @@ test_utils = ["rand"]
# all allocated memory is being released (no memory leaks).
# See README for details
memory-check = []
pyarrow = ["pyo3", "libc"]
pyarrow = ["pyo3"]

[dev-dependencies]
rand = "0.8"
Expand Down
26 changes: 17 additions & 9 deletions arrow/src/pyarrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
use std::convert::{From, TryFrom};
use std::sync::Arc;

use libc::uintptr_t;
use pyo3::ffi::Py_uintptr_t;
use pyo3::import_exception;
use pyo3::prelude::*;
use pyo3::types::PyList;
Expand Down Expand Up @@ -51,7 +51,7 @@ impl PyArrowConvert for DataType {
fn from_pyarrow(value: &PyAny) -> PyResult<Self> {
let c_schema = FFI_ArrowSchema::empty();
let c_schema_ptr = &c_schema as *const FFI_ArrowSchema;
value.call_method1("_export_to_c", (c_schema_ptr as uintptr_t,))?;
value.call_method1("_export_to_c", (c_schema_ptr as Py_uintptr_t,))?;
let dtype = DataType::try_from(&c_schema)?;
Ok(dtype)
}
Expand All @@ -61,7 +61,8 @@ impl PyArrowConvert for DataType {
let c_schema_ptr = &c_schema as *const FFI_ArrowSchema;
let module = py.import("pyarrow")?;
let class = module.getattr("DataType")?;
let dtype = class.call_method1("_import_from_c", (c_schema_ptr as uintptr_t,))?;
let dtype =
class.call_method1("_import_from_c", (c_schema_ptr as Py_uintptr_t,))?;
Ok(dtype.into())
}
}
Expand All @@ -70,7 +71,7 @@ impl PyArrowConvert for Field {
fn from_pyarrow(value: &PyAny) -> PyResult<Self> {
let c_schema = FFI_ArrowSchema::empty();
let c_schema_ptr = &c_schema as *const FFI_ArrowSchema;
value.call_method1("_export_to_c", (c_schema_ptr as uintptr_t,))?;
value.call_method1("_export_to_c", (c_schema_ptr as Py_uintptr_t,))?;
let field = Field::try_from(&c_schema)?;
Ok(field)
}
Expand All @@ -80,7 +81,8 @@ impl PyArrowConvert for Field {
let c_schema_ptr = &c_schema as *const FFI_ArrowSchema;
let module = py.import("pyarrow")?;
let class = module.getattr("Field")?;
let dtype = class.call_method1("_import_from_c", (c_schema_ptr as uintptr_t,))?;
let dtype =
class.call_method1("_import_from_c", (c_schema_ptr as Py_uintptr_t,))?;
Ok(dtype.into())
}
}
Expand All @@ -89,7 +91,7 @@ impl PyArrowConvert for Schema {
fn from_pyarrow(value: &PyAny) -> PyResult<Self> {
let c_schema = FFI_ArrowSchema::empty();
let c_schema_ptr = &c_schema as *const FFI_ArrowSchema;
value.call_method1("_export_to_c", (c_schema_ptr as uintptr_t,))?;
value.call_method1("_export_to_c", (c_schema_ptr as Py_uintptr_t,))?;
let schema = Schema::try_from(&c_schema)?;
Ok(schema)
}
Expand All @@ -100,7 +102,7 @@ impl PyArrowConvert for Schema {
let module = py.import("pyarrow")?;
let class = module.getattr("Schema")?;
let schema =
class.call_method1("_import_from_c", (c_schema_ptr as uintptr_t,))?;
class.call_method1("_import_from_c", (c_schema_ptr as Py_uintptr_t,))?;
Ok(schema.into())
}
}
Expand All @@ -116,7 +118,10 @@ impl PyArrowConvert for ArrayData {
// In particular, `_export_to_c` can go out of bounds
value.call_method1(
"_export_to_c",
(array_pointer as uintptr_t, schema_pointer as uintptr_t),
(
array_pointer as Py_uintptr_t,
schema_pointer as Py_uintptr_t,
),
)?;

let ffi_array =
Expand All @@ -134,7 +139,10 @@ impl PyArrowConvert for ArrayData {
let class = module.getattr("Array")?;
let array = class.call_method1(
"_import_from_c",
(array_pointer as uintptr_t, schema_pointer as uintptr_t),
(
array_pointer as Py_uintptr_t,
schema_pointer as Py_uintptr_t,
),
)?;
Ok(array.to_object(py))
}
Expand Down

0 comments on commit 713935f

Please sign in to comment.