pub struct Utf8Array<O: Offset> { /* private fields */ }
Expand description
A Utf8Array
is arrow’s semantic equivalent of an immutable Vec<Option<String>>
.
Cloning and slicing this struct is O(1)
.
§Example
use polars_arrow::bitmap::Bitmap;
use polars_arrow::buffer::Buffer;
use polars_arrow::array::Utf8Array;
let array = Utf8Array::<i32>::from([Some("hi"), None, Some("there")]);
assert_eq!(array.value(0), "hi");
assert_eq!(array.iter().collect::<Vec<_>>(), vec![Some("hi"), None, Some("there")]);
assert_eq!(array.values_iter().collect::<Vec<_>>(), vec!["hi", "", "there"]);
// the underlying representation
assert_eq!(array.validity(), Some(&Bitmap::from([true, false, true])));
assert_eq!(array.values(), &Buffer::from(b"hithere".to_vec()));
assert_eq!(array.offsets().buffer(), &Buffer::from(vec![0, 2, 2, 2 + 5]));
§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
. - A slice of
values
taken from two consecutivesoffsets
is validutf8
. len
is equal tovalidity.len()
, when defined.
Implementations§
Source§impl<O: Offset> Utf8Array<O>
impl<O: Offset> Utf8Array<O>
Sourcepub fn try_new(
dtype: ArrowDataType,
offsets: OffsetsBuffer<O>,
values: Buffer<u8>,
validity: Option<Bitmap>,
) -> PolarsResult<Self>
pub fn try_new( dtype: ArrowDataType, offsets: OffsetsBuffer<O>, values: Buffer<u8>, validity: Option<Bitmap>, ) -> PolarsResult<Self>
Returns a Utf8Array
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
dtype
’scrate::datatypes::PhysicalType
is not equal to eitherUtf8
orLargeUtf8
. - The
values
between two consecutiveoffsets
are not valid utf8
§Implementation
This function is O(N)
- checking utf8 is O(N)
Sourcepub fn from_slice<T: AsRef<str>, P: AsRef<[T]>>(slice: P) -> Self
pub fn from_slice<T: AsRef<str>, P: AsRef<[T]>>(slice: P) -> Self
Returns a Utf8Array
from a slice of &str
.
A convenience method that uses Self::from_trusted_len_values_iter
.
Sourcepub fn from<T: AsRef<str>, P: AsRef<[Option<T>]>>(slice: P) -> Self
pub fn from<T: AsRef<str>, P: AsRef<[Option<T>]>>(slice: P) -> Self
Returns a new Utf8Array
from a slice of &str
.
A convenience method that uses Self::from_trusted_len_iter
.
Sourcepub fn iter(&self) -> ZipValidity<&str, Utf8ValuesIter<'_, O>, BitmapIter<'_>> ⓘ
pub fn iter(&self) -> ZipValidity<&str, Utf8ValuesIter<'_, O>, BitmapIter<'_>> ⓘ
Returns an iterator of Option<&str>
Sourcepub fn values_iter(&self) -> Utf8ValuesIter<'_, O>
pub fn values_iter(&self) -> Utf8ValuesIter<'_, O>
Returns an iterator of &str
Sourcepub fn non_null_values_iter(&self) -> NonNullValuesIter<'_, Utf8Array<O>> ⓘ
pub fn non_null_values_iter(&self) -> NonNullValuesIter<'_, Utf8Array<O>> ⓘ
Returns an iterator of the non-null values `&str.
Sourcepub fn value(&self, i: usize) -> &str
pub fn value(&self, i: usize) -> &str
Returns the value of the element at index i
, ignoring the array’s validity.
§Panic
This function panics iff i >= self.len
.
Sourcepub unsafe fn value_unchecked(&self, i: usize) -> &str
pub unsafe fn value_unchecked(&self, i: usize) -> &str
Returns the value of the element at index i
, ignoring the array’s validity.
§Safety
This function is safe iff i < self.len
.
Sourcepub fn dtype(&self) -> &ArrowDataType
pub fn dtype(&self) -> &ArrowDataType
Returns the ArrowDataType
of this array.
Sourcepub fn offsets(&self) -> &OffsetsBuffer<O>
pub fn offsets(&self) -> &OffsetsBuffer<O>
Returns the offsets of this Utf8Array
.
Sourcepub unsafe fn slice_unchecked(&mut self, offset: usize, length: usize)
pub unsafe fn slice_unchecked(&mut self, offset: usize, length: usize)
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, MutableUtf8Array<O>> ⓘ
pub fn into_mut(self) -> Either<Self, MutableUtf8Array<O>> ⓘ
Try to convert this Utf8Array
to a MutableUtf8Array
Sourcepub fn new_empty(dtype: ArrowDataType) -> Self
pub fn new_empty(dtype: ArrowDataType) -> Self
Returns a new empty Utf8Array
.
The array is guaranteed to have no elements nor validity.
Sourcepub fn new_null(dtype: ArrowDataType, length: usize) -> Self
pub fn new_null(dtype: ArrowDataType, length: usize) -> Self
Returns a new Utf8Array
whose all slots are null / None
.
Sourcepub fn default_dtype() -> ArrowDataType
pub fn default_dtype() -> ArrowDataType
Returns a default ArrowDataType
of this array, which depends on the generic parameter O
: DataType::Utf8
or DataType::LargeUtf8
Sourcepub unsafe fn new_unchecked(
dtype: ArrowDataType,
offsets: OffsetsBuffer<O>,
values: Buffer<u8>,
validity: Option<Bitmap>,
) -> Self
pub unsafe fn new_unchecked( dtype: ArrowDataType, offsets: OffsetsBuffer<O>, values: Buffer<u8>, validity: Option<Bitmap>, ) -> Self
Creates a new Utf8Array
without checking for offsets monotinicity nor utf8-validity
§Panic
This function panics (in debug mode only) iff:
- The last offset is not equal to the values’ length.
- the validity’s length is not equal to
offsets.len()
. - The
dtype
’scrate::datatypes::PhysicalType
is not equal to eitherUtf8
orLargeUtf8
.
§Safety
This function is unsound iff:
- The
values
between two consecutiveoffsets
are not valid utf8
§Implementation
This function is O(1)
Sourcepub fn new(
dtype: ArrowDataType,
offsets: OffsetsBuffer<O>,
values: Buffer<u8>,
validity: Option<Bitmap>,
) -> Self
pub fn new( dtype: ArrowDataType, offsets: OffsetsBuffer<O>, values: Buffer<u8>, validity: Option<Bitmap>, ) -> Self
Creates a new Utf8Array
.
§Panics
This function panics iff:
- The last offset is not equal to the values’ length.
- the validity’s length is not equal to
offsets.len()
. - The
dtype
’scrate::datatypes::PhysicalType
is not equal to eitherUtf8
orLargeUtf8
. - The
values
between two consecutiveoffsets
are not valid utf8
§Implementation
This function is O(N)
- checking utf8 is O(N)
Sourcepub fn from_trusted_len_values_iter<T: AsRef<str>, I: TrustedLen<Item = T>>(
iterator: I,
) -> Self
pub fn from_trusted_len_values_iter<T: AsRef<str>, I: TrustedLen<Item = T>>( iterator: I, ) -> Self
Returns a (non-null) Utf8Array
created from a TrustedLen
of &str
.
§Implementation
This function is O(N)
Sourcepub fn from_iter_values<T: AsRef<str>, I: Iterator<Item = T>>(
iterator: I,
) -> Self
pub fn from_iter_values<T: AsRef<str>, I: Iterator<Item = T>>( iterator: I, ) -> Self
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 Utf8Array
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 Utf8Array
from an iterator of trusted length.
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 Utf8Array
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 Utf8Array
from an fallible iterator of trusted length.
Sourcepub fn apply_validity<F: FnOnce(Bitmap) -> Bitmap>(&mut self, f: F)
pub fn apply_validity<F: FnOnce(Bitmap) -> Bitmap>(&mut self, f: F)
pub fn to_binary(&self) -> BinaryArray<O>
Trait Implementations§
Source§impl<O: Offset> Array for Utf8Array<O>
impl<O: Offset> Array for Utf8Array<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 dtype(&self) -> &ArrowDataType
fn dtype(&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)
fn has_nulls(&self) -> bool
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 Utf8Array<O>
impl<'a, O: Offset> ArrayAccessor<'a> for Utf8Array<O>
Source§impl<T: StrIntoBytes> ArrayFromIter<Option<T>> for Utf8Array<i64>
impl<T: StrIntoBytes> ArrayFromIter<Option<T>> for Utf8Array<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: IntoIterator<Item = Result<Option<T>, E>>>( iter: I, ) -> Result<Self, E>
Source§impl<T: StrIntoBytes> ArrayFromIter<T> for Utf8Array<i64>
impl<T: StrIntoBytes> ArrayFromIter<T> for Utf8Array<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: IntoIterator<Item = Result<T, E>>>( iter: I, ) -> Result<Self, E>
Source§impl<'a, O: Offset> From<GrowableUtf8<'a, O>> for Utf8Array<O>
impl<'a, O: Offset> From<GrowableUtf8<'a, O>> for Utf8Array<O>
Source§fn from(val: GrowableUtf8<'a, O>) -> Self
fn from(val: GrowableUtf8<'a, O>) -> Self
Source§impl<O: Offset> From<MutableUtf8Array<O>> for Utf8Array<O>
impl<O: Offset> From<MutableUtf8Array<O>> for Utf8Array<O>
Source§fn from(other: MutableUtf8Array<O>) -> Self
fn from(other: MutableUtf8Array<O>) -> Self
Source§impl<O: Offset> From<MutableUtf8ValuesArray<O>> for Utf8Array<O>
impl<O: Offset> From<MutableUtf8ValuesArray<O>> for Utf8Array<O>
Source§fn from(other: MutableUtf8ValuesArray<O>) -> Self
fn from(other: MutableUtf8ValuesArray<O>) -> Self
Source§impl FromDataUtf8 for Utf8Array<i64>
impl FromDataUtf8 for Utf8Array<i64>
Source§impl<O: Offset> GenericBinaryArray<O> for Utf8Array<O>
impl<O: Offset> GenericBinaryArray<O> for Utf8Array<O>
Source§impl<'a, O: Offset> IntoIterator for &'a Utf8Array<O>
impl<'a, O: Offset> IntoIterator for &'a Utf8Array<O>
Source§type IntoIter = ZipValidity<&'a str, ArrayValuesIter<'a, Utf8Array<O>>, BitmapIter<'a>>
type IntoIter = ZipValidity<&'a str, ArrayValuesIter<'a, Utf8Array<O>>, BitmapIter<'a>>
Source§impl ParameterFreeDtypeStaticArray for Utf8Array<i64>
impl ParameterFreeDtypeStaticArray for Utf8Array<i64>
fn get_dtype() -> ArrowDataType
Source§impl<O: Offset> Splitable for Utf8Array<O>
impl<O: Offset> Splitable for Utf8Array<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§impl StaticArray for Utf8Array<i64>
impl StaticArray for Utf8Array<i64>
type ValueT<'a> = &'a str
type ZeroableValueT<'a> = Option<&'a str>
type ValueIterT<'a> = ArrayValuesIter<'a, Utf8Array<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 Utf8FromIter for Utf8Array<i64>
impl Utf8FromIter for Utf8Array<i64>
Source§impl ValueSize for Utf8Array<i64>
impl ValueSize for Utf8Array<i64>
Source§fn get_values_size(&self) -> usize
fn get_values_size(&self) -> usize
impl ArrowArray for Utf8Array<i64>
Auto Trait Implementations§
impl<O> !Freeze for Utf8Array<O>
impl<O> RefUnwindSafe for Utf8Array<O>
impl<O> Send for Utf8Array<O>
impl<O> Sync for Utf8Array<O>
impl<O> Unpin for Utf8Array<O>where
O: Unpin,
impl<O> UnwindSafe for Utf8Array<O>where
O: UnwindSafe,
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§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