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(
dtype: ArrowDataType,
values: Vec<T>,
validity: Option<MutableBitmap>,
) -> PolarsResult<Self>
pub fn try_new( dtype: 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
None
and its length is different fromvalues
’s length - The
dtype
’scrate::datatypes::PhysicalType
is 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, dtype: ArrowDataType) -> Self
pub fn with_capacity_from(capacity: usize, dtype: ArrowDataType) -> Self
Creates a new MutablePrimitiveArray
from a capacity and ArrowDataType
.
pub fn push_value(&mut self, value: T)
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, dtype: ArrowDataType) -> Self
pub fn to(self, dtype: 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
.
pub fn freeze(self) -> PrimitiveArray<T>
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clears the array, removing all values.
Note that this method has no effect on the allocated capacity of the array.
Sourcepub fn with_freeze<K, F: FnOnce(&PrimitiveArray<T>) -> K>(&mut self, f: F) -> K
pub fn with_freeze<K, F: FnOnce(&PrimitiveArray<T>) -> K>(&mut self, f: F) -> K
Apply a function that temporarily freezes this MutableArray
into a PrimitiveArray
.
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 >= 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>)
Sets the validity.
§Panic
Panics iff the validity’s len is not equal to the existing values’ length.
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(dtype: ArrowDataType) -> Self
fn from(dtype: 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 dtype(&self) -> &ArrowDataType
fn dtype(&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>
type Freeze = PrimitiveArray<T>
fn reserve(&mut self, additional: usize)
fn push(&mut self, value: Option<T>)
fn len(&self) -> usize
fn push_null(&mut self)
fn extend_constant(&mut self, additional: usize, value: Option<T>)
fn extend_null_constant(&mut self, additional: usize)
fn freeze(self) -> Self::Freeze
fn with_capacity(capacity: usize) -> Self
fn extend_n(&mut self, n: usize, iter: impl Iterator<Item = 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.Source§impl<T: NativeType> TryPush<Option<T>> for MutablePrimitiveArray<T>
impl<T: NativeType> TryPush<Option<T>> for MutablePrimitiveArray<T>
Auto Trait Implementations§
impl<T> Freeze for MutablePrimitiveArray<T>
impl<T> RefUnwindSafe for MutablePrimitiveArray<T>
impl<T> Send for MutablePrimitiveArray<T>
impl<T> Sync for MutablePrimitiveArray<T>
impl<T> Unpin for MutablePrimitiveArray<T>where
T: Unpin,
impl<T> UnwindSafe for MutablePrimitiveArray<T>where
T: UnwindSafe,
Blanket Implementations§
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§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)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