Struct polars_arrow::array::MutablePrimitiveArray
source · pub struct MutablePrimitiveArray<T: NativeType> { /* private fields */ }Expand description
The Arrow’s equivalent to Vec<Option<T>> where T is byte-size (e.g. i32).
Converting a MutablePrimitiveArray into a PrimitiveArray is O(1).
Implementations§
source§impl<'a, T: NativeType> MutablePrimitiveArray<T>
impl<'a, T: NativeType> MutablePrimitiveArray<T>
sourcepub fn iter(&'a self) -> ZipValidity<&'a T, Iter<'a, T>, BitmapIter<'a>> ⓘ
pub fn iter(&'a self) -> ZipValidity<&'a T, Iter<'a, T>, BitmapIter<'a>> ⓘ
Returns an iterator over Option<T>
sourcepub fn values_iter(&'a self) -> Iter<'a, T>
pub fn values_iter(&'a self) -> Iter<'a, T>
Returns an iterator of T
source§impl<T: NativeType> MutablePrimitiveArray<T>
impl<T: NativeType> MutablePrimitiveArray<T>
sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new empty MutablePrimitiveArray.
sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Creates a new MutablePrimitiveArray with a capacity.
sourcepub fn try_new(
data_type: ArrowDataType,
values: Vec<T>,
validity: Option<MutableBitmap>
) -> PolarsResult<Self>
pub fn try_new( data_type: ArrowDataType, values: Vec<T>, validity: Option<MutableBitmap> ) -> PolarsResult<Self>
The canonical method to create a MutablePrimitiveArray out of its internal components.
Implementation
This function is O(1).
Errors
This function errors iff:
- The validity is not
Noneand its length is different fromvalues’s length - The
data_type’scrate::datatypes::PhysicalTypeis not equal to [crate::datatypes::PhysicalType::Primitive(T::PRIMITIVE)]
sourcepub fn into_inner(self) -> (ArrowDataType, Vec<T>, Option<MutableBitmap>)
pub fn into_inner(self) -> (ArrowDataType, Vec<T>, Option<MutableBitmap>)
Extract the low-end APIs from the MutablePrimitiveArray.
sourcepub fn apply_values<F: Fn(&mut [T])>(&mut self, f: F)
pub fn apply_values<F: Fn(&mut [T])>(&mut self, f: F)
Applies a function f to the values of this array, cloning the values
iff they are being shared with others
This is an API to use clone-on-write
Implementation
This function is O(f) if the data is not being shared, and O(N) + O(f)
if it is being shared (since it results in a O(N) memcopy).
Panics
This function panics iff f panics
source§impl<T: NativeType> MutablePrimitiveArray<T>
impl<T: NativeType> MutablePrimitiveArray<T>
sourcepub fn with_capacity_from(capacity: usize, data_type: ArrowDataType) -> Self
pub fn with_capacity_from(capacity: usize, data_type: ArrowDataType) -> Self
Creates a new MutablePrimitiveArray from a capacity and ArrowDataType.
sourcepub fn pop(&mut self) -> Option<T>
pub fn pop(&mut self) -> Option<T>
Pop a value from the array. Note if the values is empty, this method will return None.
sourcepub fn extend_constant(&mut self, additional: usize, value: Option<T>)
pub fn extend_constant(&mut self, additional: usize, value: Option<T>)
Extends the MutablePrimitiveArray with a constant
sourcepub fn extend_trusted_len<P, I>(&mut self, iterator: I)
pub fn extend_trusted_len<P, I>(&mut self, iterator: I)
Extends the MutablePrimitiveArray from an iterator of trusted len.
sourcepub unsafe fn extend_trusted_len_unchecked<P, I>(&mut self, iterator: I)
pub unsafe fn extend_trusted_len_unchecked<P, I>(&mut self, iterator: I)
Extends the MutablePrimitiveArray from an iterator of trusted len.
Safety
The iterator must be trusted len.
sourcepub fn extend_trusted_len_values<I>(&mut self, iterator: I)where
I: TrustedLen<Item = T>,
pub fn extend_trusted_len_values<I>(&mut self, iterator: I)where
I: TrustedLen<Item = T>,
Extends the MutablePrimitiveArray from an iterator of values of trusted len.
This differs from extend_trusted_len which accepts in iterator of optional values.
sourcepub unsafe fn extend_trusted_len_values_unchecked<I>(&mut self, iterator: I)where
I: Iterator<Item = T>,
pub unsafe fn extend_trusted_len_values_unchecked<I>(&mut self, iterator: I)where
I: Iterator<Item = T>,
Extends the MutablePrimitiveArray from an iterator of values of trusted len.
This differs from extend_trusted_len_unchecked which accepts in iterator of optional values.
Safety
The iterator must be trusted len.
sourcepub fn extend_from_slice(&mut self, items: &[T])
pub fn extend_from_slice(&mut self, items: &[T])
Extends the MutablePrimitiveArray from a slice
sourcepub fn to(self, data_type: ArrowDataType) -> Self
pub fn to(self, data_type: ArrowDataType) -> Self
Changes the arrays’ ArrowDataType, returning a new MutablePrimitiveArray.
Use to change the logical type without changing the corresponding physical Type.
Implementation
This operation is O(1).
sourcepub fn shrink_to_fit(&mut self)
pub fn shrink_to_fit(&mut self)
Shrinks the capacity of the MutablePrimitiveArray to fit its current length.
sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Returns the capacity of this MutablePrimitiveArray.
source§impl<T: NativeType> MutablePrimitiveArray<T>
impl<T: NativeType> MutablePrimitiveArray<T>
Accessors
source§impl<T: NativeType> MutablePrimitiveArray<T>
impl<T: NativeType> MutablePrimitiveArray<T>
Setters
sourcepub fn set(&mut self, index: usize, value: Option<T>)
pub fn set(&mut self, index: usize, value: Option<T>)
Sets position index to value.
Note that if it is the first time a null appears in this array,
this initializes the validity bitmap (O(N)).
Panic
Panics iff index is larger than self.len().
sourcepub unsafe fn set_unchecked(&mut self, index: usize, value: Option<T>)
pub unsafe fn set_unchecked(&mut self, index: usize, value: Option<T>)
Sets position index to value.
Note that if it is the first time a null appears in this array,
this initializes the validity bitmap (O(N)).
Safety
Caller must ensure index < self.len()
sourcepub fn set_validity(&mut self, validity: Option<MutableBitmap>)
pub fn set_validity(&mut self, validity: Option<MutableBitmap>)
sourcepub fn set_values(&mut self, values: Vec<T>)
pub fn set_values(&mut self, values: Vec<T>)
source§impl<T: NativeType> MutablePrimitiveArray<T>
impl<T: NativeType> MutablePrimitiveArray<T>
sourcepub fn from_slice<P: AsRef<[T]>>(slice: P) -> Self
pub fn from_slice<P: AsRef<[T]>>(slice: P) -> Self
Creates a MutablePrimitiveArray from a slice of values.
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 MutablePrimitiveArray from an iterator of trusted length.
Safety
The iterator must be TrustedLen.
I.e. 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 MutablePrimitiveArray from a TrustedLen.
sourcepub unsafe fn try_from_trusted_len_iter_unchecked<E, I, P>(
iter: I
) -> Result<Self, E>
pub unsafe fn try_from_trusted_len_iter_unchecked<E, I, P>( iter: I ) -> Result<Self, E>
Creates a MutablePrimitiveArray from an fallible 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>(iterator: I) -> Result<Self, E>
pub fn try_from_trusted_len_iter<E, I, P>(iterator: I) -> Result<Self, E>
Creates a MutablePrimitiveArray from an fallible iterator of trusted length.
sourcepub fn from_trusted_len_values_iter<I: TrustedLen<Item = T>>(iter: I) -> Self
pub fn from_trusted_len_values_iter<I: TrustedLen<Item = T>>(iter: I) -> Self
Creates a new MutablePrimitiveArray out an iterator over values
sourcepub fn from_vec(values: Vec<T>) -> Self
pub fn from_vec(values: Vec<T>) -> Self
Creates a (non-null) MutablePrimitiveArray from a vector of values.
This does not have memcopy and is the fastest way to create a PrimitiveArray.
sourcepub unsafe fn from_trusted_len_values_iter_unchecked<I: Iterator<Item = T>>(
iter: I
) -> Self
pub unsafe fn from_trusted_len_values_iter_unchecked<I: Iterator<Item = T>>( iter: I ) -> Self
Creates a new MutablePrimitiveArray from an iterator over values
Safety
The iterator must be TrustedLen.
I.e. that size_hint().1 correctly reports its length.
Trait Implementations§
source§impl<T: Clone + NativeType> Clone for MutablePrimitiveArray<T>
impl<T: Clone + NativeType> Clone for MutablePrimitiveArray<T>
source§fn clone(&self) -> MutablePrimitiveArray<T>
fn clone(&self) -> MutablePrimitiveArray<T>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl<T: Debug + NativeType> Debug for MutablePrimitiveArray<T>
impl<T: Debug + NativeType> Debug for MutablePrimitiveArray<T>
source§impl<T: NativeType> Default for MutablePrimitiveArray<T>
impl<T: NativeType> Default for MutablePrimitiveArray<T>
source§impl<T: NativeType> Extend<Option<T>> for MutablePrimitiveArray<T>
impl<T: NativeType> Extend<Option<T>> for MutablePrimitiveArray<T>
source§fn extend<I: IntoIterator<Item = Option<T>>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = Option<T>>>(&mut self, iter: I)
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)source§impl<T: NativeType> From<ArrowDataType> for MutablePrimitiveArray<T>
impl<T: NativeType> From<ArrowDataType> for MutablePrimitiveArray<T>
source§fn from(data_type: ArrowDataType) -> Self
fn from(data_type: ArrowDataType) -> Self
source§impl<T: NativeType> From<MutablePrimitiveArray<T>> for PrimitiveArray<T>
impl<T: NativeType> From<MutablePrimitiveArray<T>> for PrimitiveArray<T>
source§fn from(other: MutablePrimitiveArray<T>) -> Self
fn from(other: MutablePrimitiveArray<T>) -> Self
source§impl<T: NativeType, P: AsRef<[Option<T>]>> From<P> for MutablePrimitiveArray<T>
impl<T: NativeType, P: AsRef<[Option<T>]>> From<P> for MutablePrimitiveArray<T>
source§impl<T: NativeType, Ptr: Borrow<Option<T>>> FromIterator<Ptr> for MutablePrimitiveArray<T>
impl<T: NativeType, Ptr: Borrow<Option<T>>> FromIterator<Ptr> for MutablePrimitiveArray<T>
source§fn from_iter<I: IntoIterator<Item = Ptr>>(iter: I) -> Self
fn from_iter<I: IntoIterator<Item = Ptr>>(iter: I) -> Self
source§impl<T: NativeType> MutableArray for MutablePrimitiveArray<T>
impl<T: NativeType> MutableArray for MutablePrimitiveArray<T>
source§fn validity(&self) -> Option<&MutableBitmap>
fn validity(&self) -> Option<&MutableBitmap>
source§fn as_arc(&mut self) -> Arc<dyn Array>
fn as_arc(&mut self) -> Arc<dyn Array>
Array.source§fn data_type(&self) -> &ArrowDataType
fn data_type(&self) -> &ArrowDataType
ArrowDataType of the array.source§fn as_mut_any(&mut self) -> &mut dyn Any
fn as_mut_any(&mut self) -> &mut dyn Any
Any, to enable dynamic casting.source§fn shrink_to_fit(&mut self)
fn shrink_to_fit(&mut self)
source§impl<T: NativeType> PartialEq for MutablePrimitiveArray<T>
impl<T: NativeType> PartialEq for MutablePrimitiveArray<T>
source§impl<T: NativeType> Pushable<Option<T>> for MutablePrimitiveArray<T>
impl<T: NativeType> Pushable<Option<T>> for MutablePrimitiveArray<T>
source§impl<T: NativeType> TryExtend<Option<T>> for MutablePrimitiveArray<T>
impl<T: NativeType> TryExtend<Option<T>> for MutablePrimitiveArray<T>
source§fn try_extend<I: IntoIterator<Item = Option<T>>>(
&mut self,
iter: I
) -> PolarsResult<()>
fn try_extend<I: IntoIterator<Item = Option<T>>>( &mut self, iter: I ) -> PolarsResult<()>
This is infallible and is implemented for consistency with all other types
source§impl<T: NativeType> TryExtendFromSelf for MutablePrimitiveArray<T>
impl<T: NativeType> TryExtendFromSelf for MutablePrimitiveArray<T>
source§fn try_extend_from_self(&mut self, other: &Self) -> PolarsResult<()>
fn try_extend_from_self(&mut self, other: &Self) -> PolarsResult<()>
other, failing only on overflow.