Struct polars::prelude::StructArray
[−]pub struct StructArray { /* private fields */ }
Expand description
A StructArray
is a nested Array
with an optional validity representing
multiple Array
with the same number of rows.
Example
use arrow2::array::*;
use arrow2::datatypes::*;
let boolean = BooleanArray::from_slice(&[false, false, true, true]).boxed();
let int = Int32Array::from_slice(&[42, 28, 19, 31]).boxed();
let fields = vec![
Field::new("b", DataType::Boolean, false),
Field::new("c", DataType::Int32, false),
];
let array = StructArray::new(DataType::Struct(fields), vec![boolean, int], None);
Implementations
impl<'a> StructArray
impl<'a> StructArray
pub fn iter(
&'a self
) -> ZipValidity<'a, Vec<Box<dyn Scalar + 'static, Global>, Global>, StructValueIter<'a>>ⓘNotable traits for ZipValidity<'a, T, I>impl<'a, T, I> Iterator for ZipValidity<'a, T, I>where
I: Iterator<Item = T>, type Item = Option<T>;
pub fn iter(
&'a self
) -> ZipValidity<'a, Vec<Box<dyn Scalar + 'static, Global>, Global>, StructValueIter<'a>>ⓘNotable traits for ZipValidity<'a, T, I>impl<'a, T, I> Iterator for ZipValidity<'a, T, I>where
I: Iterator<Item = T>, type Item = Option<T>;
I: Iterator<Item = T>, type Item = Option<T>;
Returns an iterator of Option<Box<dyn Array>>
pub fn values_iter(&'a self) -> StructValueIter<'a>
pub fn values_iter(&'a self) -> StructValueIter<'a>
Returns an iterator of Box<dyn Array>
impl StructArray
impl StructArray
pub fn try_new(
data_type: DataType,
values: Vec<Box<dyn Array + 'static, Global>, Global>,
validity: Option<Bitmap>
) -> Result<StructArray, Error>
pub fn try_new(
data_type: DataType,
values: Vec<Box<dyn Array + 'static, Global>, Global>,
validity: Option<Bitmap>
) -> Result<StructArray, Error>
Returns a new StructArray
.
Errors
This function errors iff:
data_type
’s physical type is notcrate::datatypes::PhysicalType::Struct
.- the children of
data_type
are empty - the values’s len is different from children’s length
- any of the values’s data type is different from its corresponding children’ data type
- any element of values has a different length than the first element
- the validity’s length is not equal to the length of the first element
pub fn new(
data_type: DataType,
values: Vec<Box<dyn Array + 'static, Global>, Global>,
validity: Option<Bitmap>
) -> StructArray
pub fn new(
data_type: DataType,
values: Vec<Box<dyn Array + 'static, Global>, Global>,
validity: Option<Bitmap>
) -> StructArray
Returns a new StructArray
Panics
This function panics iff:
data_type
’s physical type is notcrate::datatypes::PhysicalType::Struct
.- the children of
data_type
are empty - the values’s len is different from children’s length
- any of the values’s data type is different from its corresponding children’ data type
- any element of values has a different length than the first element
- the validity’s length is not equal to the length of the first element
pub fn from_data(
data_type: DataType,
values: Vec<Box<dyn Array + 'static, Global>, Global>,
validity: Option<Bitmap>
) -> StructArray
pub fn from_data(
data_type: DataType,
values: Vec<Box<dyn Array + 'static, Global>, Global>,
validity: Option<Bitmap>
) -> StructArray
Alias for new
pub fn new_empty(data_type: DataType) -> StructArray
pub fn new_empty(data_type: DataType) -> StructArray
Creates an empty StructArray
.
pub fn new_null(data_type: DataType, length: usize) -> StructArray
pub fn new_null(data_type: DataType, length: usize) -> StructArray
Creates a null StructArray
of length length
.
impl StructArray
impl StructArray
pub fn into_data(
self
) -> (Vec<Field, Global>, Vec<Box<dyn Array + 'static, Global>, Global>, Option<Bitmap>)
pub fn into_data(
self
) -> (Vec<Field, Global>, Vec<Box<dyn Array + 'static, Global>, Global>, Option<Bitmap>)
Deconstructs the StructArray
into its individual components.
pub fn slice(&self, offset: usize, length: usize) -> StructArray
pub fn slice(&self, offset: usize, length: usize) -> StructArray
Creates a new StructArray
that is a slice of self
.
Panics
offset + length
must be smaller thanself.len()
.
Implementation
This operation is O(F)
where F
is the number of fields.
pub unsafe fn slice_unchecked(&self, offset: usize, length: usize) -> StructArray
pub unsafe fn slice_unchecked(&self, offset: usize, length: usize) -> StructArray
Creates a new StructArray
that is a slice of self
.
Implementation
This operation is O(F)
where F
is the number of fields.
Safety
The caller must ensure that offset + length <= self.len()
.
pub fn with_validity(self, validity: Option<Bitmap>) -> StructArray
pub fn with_validity(self, validity: Option<Bitmap>) -> StructArray
Returns this StructArray
with a new validity.
Panics
This function panics iff validity.len() != self.len()
.
pub fn set_validity(&mut self, validity: Option<Bitmap>)
pub fn set_validity(&mut self, validity: Option<Bitmap>)
Sets the validity of this StructArray
.
Panics
This function panics iff validity.len() != self.len()
.
pub fn boxed(self) -> Box<dyn Array + 'static, Global>
pub fn boxed(self) -> Box<dyn Array + 'static, Global>
Boxes self into a Box<dyn Array>
.
pub fn arced(self) -> Arc<dyn Array + 'static>
pub fn arced(self) -> Arc<dyn Array + 'static>
Boxes self into a std::sync::Arc<dyn Array>
.
impl StructArray
impl StructArray
impl StructArray
impl StructArray
pub fn get_fields(data_type: &DataType) -> &[Field]
pub fn get_fields(data_type: &DataType) -> &[Field]
Returns the fields the DataType::Struct
.
Trait Implementations
impl Array for StructArray
impl Array for StructArray
fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Any
, which enables downcasting to concrete types.fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Any
, which enables mutable downcasting to concrete types.fn data_type(&self) -> &DataType
fn data_type(&self) -> &DataType
DataType
of the Array
. In combination with Array::as_any
, this can be
used to downcast trait objects (dyn Array
) to concrete arrays. Read morefn to_boxed(&self) -> Box<dyn Array + 'static, Global>
fn to_boxed(&self) -> Box<dyn Array + 'static, Global>
&dyn Array
to an owned Box<dyn Array>
.fn null_count(&self) -> usize
fn null_count(&self) -> usize
impl Clone for StructArray
impl Clone for StructArray
fn clone(&self) -> StructArray
fn clone(&self) -> StructArray
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more