From e388617aef557db067e2d0b187a73a0f58285714 Mon Sep 17 00:00:00 2001 From: Kyle Barron Date: Tue, 27 Aug 2024 10:44:13 -0400 Subject: [PATCH] implement Datum for PyScalar and PyArray (#173) --- pyo3-arrow/src/array.rs | 8 +++++++- pyo3-arrow/src/scalar.rs | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/pyo3-arrow/src/array.rs b/pyo3-arrow/src/array.rs index e8411a6..fe64f36 100644 --- a/pyo3-arrow/src/array.rs +++ b/pyo3-arrow/src/array.rs @@ -8,7 +8,7 @@ use arrow::datatypes::{ UInt64Type, UInt8Type, }; use arrow_array::{ - Array, ArrayRef, BinaryArray, BinaryViewArray, BooleanArray, LargeBinaryArray, + Array, ArrayRef, BinaryArray, BinaryViewArray, BooleanArray, Datum, LargeBinaryArray, LargeStringArray, PrimitiveArray, StringArray, StringViewArray, }; use arrow_buffer::ScalarBuffer; @@ -139,6 +139,12 @@ impl Display for PyArray { } } +impl Datum for PyArray { + fn get(&self) -> (&dyn Array, bool) { + (self.array.as_ref(), false) + } +} + #[pymethods] impl PyArray { #[new] diff --git a/pyo3-arrow/src/scalar.rs b/pyo3-arrow/src/scalar.rs index 37b1779..f760301 100644 --- a/pyo3-arrow/src/scalar.rs +++ b/pyo3-arrow/src/scalar.rs @@ -5,7 +5,7 @@ use std::sync::Arc; use arrow::array::AsArray; use arrow::datatypes::*; use arrow_array::timezone::Tz; -use arrow_array::{Array, ArrayRef, UnionArray}; +use arrow_array::{Array, ArrayRef, Datum, UnionArray}; use arrow_schema::{ArrowError, DataType, FieldRef}; use indexmap::IndexMap; use pyo3::prelude::*; @@ -65,6 +65,12 @@ impl Display for PyScalar { } } +impl Datum for PyScalar { + fn get(&self) -> (&dyn Array, bool) { + (self.array.as_ref(), true) + } +} + #[pymethods] impl PyScalar { fn __repr__(&self) -> String {