Struct polars_arrow::array::BinaryArray
source · pub struct BinaryArray<O: Offset> { /* private fields */ }
Expand description
A BinaryArray
is Arrow’s semantically equivalent of an immutable Vec<Option<Vec<u8>>>
.
It implements Array
.
The size of this struct is O(1)
, as all data is stored behind an std::sync::Arc
.
§Example
use polars_arrow::array::BinaryArray;
use polars_arrow::bitmap::Bitmap;
use polars_arrow::buffer::Buffer;
let array = BinaryArray::<i32>::from([Some([1, 2].as_ref()), None, Some([3].as_ref())]);
assert_eq!(array.value(0), &[1, 2]);
assert_eq!(array.iter().collect::<Vec<_>>(), vec![Some([1, 2].as_ref()), None, Some([3].as_ref())]);
assert_eq!(array.values_iter().collect::<Vec<_>>(), vec![[1, 2].as_ref(), &[], &[3]]);
// the underlying representation:
assert_eq!(array.values(), &Buffer::from(vec![1, 2, 3]));
assert_eq!(array.offsets().buffer(), &Buffer::from(vec![0, 2, 2, 3]));
assert_eq!(array.validity(), Some(&Bitmap::from([true, false, true])));
§Generic parameter
The generic parameter Offset
can only be i32
or i64
and tradeoffs maximum array length with
memory usage:
- the sum of lengths of all elements cannot exceed
Offset::MAX
- the total size of the underlying data is
array.len() * size_of::<Offset>() + sum of lengths of all elements
§Safety
The following invariants hold:
- Two consecutives
offsets
casted (as
) tousize
are valid slices ofvalues
. len
is equal tovalidity.len()
, when defined.
Implementations§
source§impl<O: Offset> BinaryArray<O>
impl<O: Offset> BinaryArray<O>
sourcepub fn try_new(
data_type: ArrowDataType,
offsets: OffsetsBuffer<O>,
values: Buffer<u8>,
validity: Option<Bitmap>,
) -> PolarsResult<Self>
pub fn try_new( data_type: ArrowDataType, offsets: OffsetsBuffer<O>, values: Buffer<u8>, validity: Option<Bitmap>, ) -> PolarsResult<Self>
Returns a BinaryArray
created from its internal representation.
§Errors
This function returns an error iff:
- The last offset is not equal to the values’ length.
- the validity’s length is not equal to
offsets.len()
. - The
data_type
’scrate::datatypes::PhysicalType
is not equal to eitherBinary
orLargeBinary
.
§Implementation
This function is O(1)
sourcepub unsafe fn new_unchecked(
data_type: ArrowDataType,
offsets: OffsetsBuffer<O>,
values: Buffer<u8>,
validity: Option<Bitmap>,
) -> Self
pub unsafe fn new_unchecked( data_type: ArrowDataType, offsets: OffsetsBuffer<O>, values: Buffer<u8>, validity: Option<Bitmap>, ) -> Self
Creates a new BinaryArray
without checking invariants.
§Safety
The invariants must be valid (see try_new).
sourcepub fn from_slice<T: AsRef<[u8]>, P: AsRef<[T]>>(slice: P) -> Self
pub fn from_slice<T: AsRef<[u8]>, P: AsRef<[T]>>(slice: P) -> Self
Creates a new BinaryArray
from slices of &[u8]
.
sourcepub fn from<T: AsRef<[u8]>, P: AsRef<[Option<T>]>>(slice: P) -> Self
pub fn from<T: AsRef<[u8]>, P: AsRef<[Option<T>]>>(slice: P) -> Self
Creates a new BinaryArray
from a slice of optional &[u8]
.
sourcepub fn iter(&self) -> ZipValidity<&[u8], BinaryValueIter<'_, O>, BitmapIter<'_>> ⓘ
pub fn iter(&self) -> ZipValidity<&[u8], BinaryValueIter<'_, O>, BitmapIter<'_>> ⓘ
Returns an iterator of Option<&[u8]>
over every element of this array.
sourcepub fn values_iter(&self) -> BinaryValueIter<'_, O>
pub fn values_iter(&self) -> BinaryValueIter<'_, O>
Returns an iterator of &[u8]
over every element of this array, ignoring the validity
sourcepub fn non_null_values_iter(&self) -> NonNullValuesIter<'_, BinaryArray<O>> ⓘ
pub fn non_null_values_iter(&self) -> NonNullValuesIter<'_, BinaryArray<O>> ⓘ
Returns an iterator of the non-null values.
sourcepub unsafe fn value_unchecked(&self, i: usize) -> &[u8] ⓘ
pub unsafe fn value_unchecked(&self, i: usize) -> &[u8] ⓘ
sourcepub fn data_type(&self) -> &ArrowDataType
pub fn data_type(&self) -> &ArrowDataType
Returns the ArrowDataType
of this array.
sourcepub fn values(&self) -> &Buffer<u8>
pub fn values(&self) -> &Buffer<u8>
Returns the values of this BinaryArray
.
sourcepub fn offsets(&self) -> &OffsetsBuffer<O>
pub fn offsets(&self) -> &OffsetsBuffer<O>
Returns the offsets of this BinaryArray
.
sourcepub fn slice(&mut self, offset: usize, length: usize)
pub fn slice(&mut self, offset: usize, length: usize)
Slices this BinaryArray
.
§Implementation
This function is O(1)
.
§Panics
iff offset + length > self.len()
.
sourcepub unsafe fn slice_unchecked(&mut self, offset: usize, length: usize)
pub unsafe fn slice_unchecked(&mut self, offset: usize, length: usize)
Slices this BinaryArray
.
§Implementation
This function is O(1)
.
§Safety
The caller must ensure that offset + length <= self.len()
.
sourcepub unsafe fn sliced_unchecked(self, offset: usize, length: usize) -> Self
pub unsafe fn sliced_unchecked(self, offset: usize, length: usize) -> Self
sourcepub fn with_validity(self, validity: Option<Bitmap>) -> Self
pub fn with_validity(self, validity: Option<Bitmap>) -> Self
sourcepub fn set_validity(&mut self, validity: Option<Bitmap>)
pub fn set_validity(&mut self, validity: Option<Bitmap>)
sourcepub fn take_validity(&mut self) -> Option<Bitmap>
pub fn take_validity(&mut self) -> Option<Bitmap>
Takes the validity of this array, leaving it without a validity mask.
sourcepub fn boxed(self) -> Box<dyn Array>
pub fn boxed(self) -> Box<dyn Array>
Boxes this array into a Box<dyn Array>
.
sourcepub fn arced(self) -> Arc<dyn Array>
pub fn arced(self) -> Arc<dyn Array>
Arcs this array into a std::sync::Arc<dyn Array>
.
sourcepub fn into_inner(
self,
) -> (ArrowDataType, OffsetsBuffer<O>, Buffer<u8>, Option<Bitmap>)
pub fn into_inner( self, ) -> (ArrowDataType, OffsetsBuffer<O>, Buffer<u8>, Option<Bitmap>)
Returns its internal representation
sourcepub fn into_mut(self) -> Either<Self, MutableBinaryArray<O>> ⓘ
pub fn into_mut(self) -> Either<Self, MutableBinaryArray<O>> ⓘ
Try to convert this BinaryArray
to a MutableBinaryArray
sourcepub fn new_empty(data_type: ArrowDataType) -> Self
pub fn new_empty(data_type: ArrowDataType) -> Self
Creates an empty BinaryArray
, i.e. whose .len
is zero.
sourcepub fn new_null(data_type: ArrowDataType, length: usize) -> Self
pub fn new_null(data_type: ArrowDataType, length: usize) -> Self
Creates an null BinaryArray
, i.e. whose .null_count() == .len()
.
sourcepub fn default_data_type() -> ArrowDataType
pub fn default_data_type() -> ArrowDataType
Returns the default ArrowDataType
, DataType::Binary
or DataType::LargeBinary
sourcepub fn new(
data_type: ArrowDataType,
offsets: OffsetsBuffer<O>,
values: Buffer<u8>,
validity: Option<Bitmap>,
) -> Self
pub fn new( data_type: ArrowDataType, offsets: OffsetsBuffer<O>, values: Buffer<u8>, validity: Option<Bitmap>, ) -> Self
Alias for unwrapping Self::try_new
sourcepub fn from_trusted_len_values_iter<T: AsRef<[u8]>, I: TrustedLen<Item = T>>(
iterator: I,
) -> Self
pub fn from_trusted_len_values_iter<T: AsRef<[u8]>, I: TrustedLen<Item = T>>( iterator: I, ) -> Self
Returns a BinaryArray
from an iterator of trusted length.
The BinaryArray
is guaranteed to not have a validity
sourcepub fn from_iter_values<T: AsRef<[u8]>, I: Iterator<Item = T>>(
iterator: I,
) -> Self
pub fn from_iter_values<T: AsRef<[u8]>, I: Iterator<Item = T>>( iterator: I, ) -> Self
Returns a new BinaryArray
from a Iterator
of &[u8]
.
The BinaryArray
is guaranteed to not have a validity
sourcepub unsafe fn from_trusted_len_iter_unchecked<I, P>(iterator: I) -> Self
pub unsafe fn from_trusted_len_iter_unchecked<I, P>(iterator: I) -> Self
Creates a BinaryArray
from an iterator of trusted length.
§Safety
The iterator must be TrustedLen
.
I.e. that size_hint().1
correctly reports its length.
sourcepub fn from_trusted_len_iter<I, P>(iterator: I) -> Self
pub fn from_trusted_len_iter<I, P>(iterator: I) -> Self
Creates a BinaryArray
from a TrustedLen
sourcepub unsafe fn try_from_trusted_len_iter_unchecked<E, I, P>(
iterator: I,
) -> Result<Self, E>
pub unsafe fn try_from_trusted_len_iter_unchecked<E, I, P>( iterator: I, ) -> Result<Self, E>
Creates a BinaryArray
from an falible iterator of trusted length.
§Safety
The iterator must be TrustedLen
.
I.e. that size_hint().1
correctly reports its length.
sourcepub fn try_from_trusted_len_iter<E, I, P>(iter: I) -> Result<Self, E>
pub fn try_from_trusted_len_iter<E, I, P>(iter: I) -> Result<Self, E>
Creates a BinaryArray
from an fallible iterator of trusted length.
Trait Implementations§
source§impl<O: Offset> Array for BinaryArray<O>
impl<O: Offset> Array for BinaryArray<O>
source§fn as_any(&self) -> &dyn Any
fn as_any(&self) -> &dyn Any
Any
, which enables downcasting to concrete types.source§fn as_any_mut(&mut self) -> &mut dyn Any
fn as_any_mut(&mut self) -> &mut dyn Any
Any
, which enables mutable downcasting to concrete types.source§fn len(&self) -> usize
fn len(&self) -> usize
Array
. Every array has a length corresponding to the number of
elements (slots).source§fn data_type(&self) -> &ArrowDataType
fn data_type(&self) -> &ArrowDataType
ArrowDataType
of the Array
. In combination with Array::as_any
, this can be
used to downcast trait objects (dyn Array
) to concrete arrays.source§unsafe fn split_at_boxed_unchecked(
&self,
offset: usize,
) -> (Box<dyn Array>, Box<dyn Array>)
unsafe fn split_at_boxed_unchecked( &self, offset: usize, ) -> (Box<dyn Array>, Box<dyn Array>)
source§unsafe fn slice_unchecked(&mut self, offset: usize, length: usize)
unsafe fn slice_unchecked(&mut self, offset: usize, length: usize)
source§unsafe fn is_null_unchecked(&self, i: usize) -> bool
unsafe fn is_null_unchecked(&self, i: usize) -> bool
i
is null. Read moresource§impl<'a, O: Offset> ArrayAccessor<'a> for BinaryArray<O>
impl<'a, O: Offset> ArrayAccessor<'a> for BinaryArray<O>
source§impl<T: IntoBytes> ArrayFromIter<Option<T>> for BinaryArray<i64>
impl<T: IntoBytes> ArrayFromIter<Option<T>> for BinaryArray<i64>
fn arr_from_iter<I: IntoIterator<Item = Option<T>>>(iter: I) -> Self
fn arr_from_iter_trusted<I>(iter: I) -> Self
fn try_arr_from_iter<E, I: IntoIterator<Item = Result<Option<T>, E>>>( iter: I, ) -> Result<Self, E>
fn try_arr_from_iter_trusted<E, I>(iter: I) -> Result<Self, E>
source§impl<T: IntoBytes> ArrayFromIter<T> for BinaryArray<i64>
impl<T: IntoBytes> ArrayFromIter<T> for BinaryArray<i64>
fn arr_from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self
fn arr_from_iter_trusted<I>(iter: I) -> Self
fn try_arr_from_iter<E, I: IntoIterator<Item = Result<T, E>>>( iter: I, ) -> Result<Self, E>
fn try_arr_from_iter_trusted<E, I>(iter: I) -> Result<Self, E>
source§impl<O: Offset> Arrow2Arrow for BinaryArray<O>
impl<O: Offset> Arrow2Arrow for BinaryArray<O>
source§impl BinaryFromIter for BinaryArray<i64>
impl BinaryFromIter for BinaryArray<i64>
fn from_values_iter<I, S>( iter: I, len: usize, value_cap: usize, ) -> BinaryArray<i64>
source§impl<O: Clone + Offset> Clone for BinaryArray<O>
impl<O: Clone + Offset> Clone for BinaryArray<O>
source§fn clone(&self) -> BinaryArray<O>
fn clone(&self) -> BinaryArray<O>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<O: Offset> Debug for BinaryArray<O>
impl<O: Offset> Debug for BinaryArray<O>
source§impl<'a, O: Offset> From<GrowableBinary<'a, O>> for BinaryArray<O>
impl<'a, O: Offset> From<GrowableBinary<'a, O>> for BinaryArray<O>
source§fn from(val: GrowableBinary<'a, O>) -> Self
fn from(val: GrowableBinary<'a, O>) -> Self
source§impl<O: Offset> From<MutableBinaryArray<O>> for BinaryArray<O>
impl<O: Offset> From<MutableBinaryArray<O>> for BinaryArray<O>
source§fn from(other: MutableBinaryArray<O>) -> Self
fn from(other: MutableBinaryArray<O>) -> Self
source§impl<O: Offset> From<MutableBinaryValuesArray<O>> for BinaryArray<O>
impl<O: Offset> From<MutableBinaryValuesArray<O>> for BinaryArray<O>
source§fn from(other: MutableBinaryValuesArray<O>) -> Self
fn from(other: MutableBinaryValuesArray<O>) -> Self
source§impl FromDataBinary for BinaryArray<i64>
impl FromDataBinary for BinaryArray<i64>
source§impl<O: Offset, P: AsRef<[u8]>> FromIterator<Option<P>> for BinaryArray<O>
impl<O: Offset, P: AsRef<[u8]>> FromIterator<Option<P>> for BinaryArray<O>
source§impl<O: Offset> GenericBinaryArray<O> for BinaryArray<O>
impl<O: Offset> GenericBinaryArray<O> for BinaryArray<O>
source§impl<'a, O: Offset> IntoIterator for &'a BinaryArray<O>
impl<'a, O: Offset> IntoIterator for &'a BinaryArray<O>
§type IntoIter = ZipValidity<&'a [u8], ArrayValuesIter<'a, BinaryArray<O>>, BitmapIter<'a>>
type IntoIter = ZipValidity<&'a [u8], ArrayValuesIter<'a, BinaryArray<O>>, BitmapIter<'a>>
source§impl ParameterFreeDtypeStaticArray for BinaryArray<i64>
impl ParameterFreeDtypeStaticArray for BinaryArray<i64>
fn get_dtype() -> ArrowDataType
source§impl<O: Offset> PartialEq<&(dyn Array + 'static)> for BinaryArray<O>
impl<O: Offset> PartialEq<&(dyn Array + 'static)> for BinaryArray<O>
source§impl<O: Offset> PartialEq<BinaryArray<O>> for &dyn Array
impl<O: Offset> PartialEq<BinaryArray<O>> for &dyn Array
source§fn eq(&self, other: &BinaryArray<O>) -> bool
fn eq(&self, other: &BinaryArray<O>) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl<O: Offset> PartialEq for BinaryArray<O>
impl<O: Offset> PartialEq for BinaryArray<O>
source§impl<O: Offset> Splitable for BinaryArray<O>
impl<O: Offset> Splitable for BinaryArray<O>
fn check_bound(&self, offset: usize) -> bool
source§unsafe fn _split_at_unchecked(&self, offset: usize) -> (Self, Self)
unsafe fn _split_at_unchecked(&self, offset: usize) -> (Self, Self)
split_at_unchecked
. For any usage, prefer the using
split_at
or split_at_unchecked
. Read moresource§fn split_at(&self, offset: usize) -> (Self, Self)
fn split_at(&self, offset: usize) -> (Self, Self)
source§unsafe fn split_at_unchecked(&self, offset: usize) -> (Self, Self)
unsafe fn split_at_unchecked(&self, offset: usize) -> (Self, Self)
source§impl StaticArray for BinaryArray<i64>
impl StaticArray for BinaryArray<i64>
type ValueT<'a> = &'a [u8]
type ZeroableValueT<'a> = Option<&'a [u8]>
type ValueIterT<'a> = ArrayValuesIter<'a, BinaryArray<i64>>
fn values_iter(&self) -> Self::ValueIterT<'_>
fn iter( &self, ) -> ZipValidity<Self::ValueT<'_>, Self::ValueIterT<'_>, BitmapIter<'_>> ⓘ
fn with_validity_typed(self, validity: Option<Bitmap>) -> Self
fn full_null(length: usize, dtype: ArrowDataType) -> Self
fn get(&self, idx: usize) -> Option<Self::ValueT<'_>>
fn last(&self) -> Option<Self::ValueT<'_>>
fn value(&self, idx: usize) -> Self::ValueT<'_>
fn as_slice(&self) -> Option<&[Self::ValueT<'_>]>
fn from_vec(v: Vec<Self::ValueT<'_>>, dtype: ArrowDataType) -> Self
fn from_zeroable_vec( v: Vec<Self::ZeroableValueT<'_>>, dtype: ArrowDataType, ) -> Self
fn full(length: usize, value: Self::ValueT<'_>, dtype: ArrowDataType) -> Self
source§impl<O: Offset> ValueSize for BinaryArray<O>
impl<O: Offset> ValueSize for BinaryArray<O>
source§fn get_values_size(&self) -> usize
fn get_values_size(&self) -> usize
impl ArrowArray for BinaryArray<i64>
Auto Trait Implementations§
impl<O> !Freeze for BinaryArray<O>
impl<O> RefUnwindSafe for BinaryArray<O>
impl<O> Send for BinaryArray<O>
impl<O> Sync for BinaryArray<O>
impl<O> Unpin for BinaryArray<O>
impl<O> UnwindSafe for BinaryArray<O>
Blanket Implementations§
source§impl<T, A> ArrayFromIterDtype<T> for Awhere
A: ParameterFreeDtypeStaticArray + ArrayFromIter<T>,
impl<T, A> ArrayFromIterDtype<T> for Awhere
A: ParameterFreeDtypeStaticArray + ArrayFromIter<T>,
fn arr_from_iter_with_dtype<I>(dtype: ArrowDataType, iter: I) -> Awhere
I: IntoIterator<Item = T>,
fn arr_from_iter_trusted_with_dtype<I>(dtype: ArrowDataType, iter: I) -> A
fn try_arr_from_iter_with_dtype<E, I>(
dtype: ArrowDataType,
iter: I,
) -> Result<A, E>where
I: IntoIterator<Item = Result<T, E>>,
fn try_arr_from_iter_trusted_with_dtype<E, I>( dtype: ArrowDataType, iter: I, ) -> Result<A, E>
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<A, T, E> FromFallibleIterator<A, E> for Twhere
T: FromIterator<A>,
E: Error,
impl<A, T, E> FromFallibleIterator<A, E> for Twhere
T: FromIterator<A>,
E: Error,
fn from_fallible_iter<F>(iter: F) -> Result<T, E>where
F: FallibleIterator<E, Item = A>,
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more