pub struct MapChunked { /* private fields */ }Expand description
A Map backed by a List(Struct {key, value}) Series.
§Storage safety contract
Every MapChunked must satisfy:
- The storage dtype is the
DataType::map_storage_dtypeof a Map dtype that passesDataType::ensure_valid_map_dtype. - Child arrays are valid over their entire extent, including outside the list offsets:
categorical codes in range for every non-null slot, no
Object. - Entries and keys are non-null within the offset window of every non-null row of every chunk.
Map values are nullable. Everything a live row does not own – entries under null rows or
outside the offsets – is unconstrained, as for any ListChunked. Flat accessors mask
those entries and Arrow export drops them; repairs never clear entry or key validity,
which would expose arbitrary payloads.
§Canonical semantics
Validated ingestion (Self::try_from_storage, List(Struct) -> Map, from_any_values,
Parquet) deduplicates keys within each row. Whole-row operations and value-only replacements
preserve uniqueness; key-changing operations re-establish it. Arrow, IPC and FFI imports
trust the producer and may contain duplicates. Uniqueness is never a safety requirement;
callers that need it must canonicalize first.
Equality is entry-order-sensitive on the storage.
Implementations§
Source§impl MapChunked
impl MapChunked
Sourcepub unsafe fn from_storage_unchecked(
dtype: DataType,
storage: Series,
) -> MapChunked
pub unsafe fn from_storage_unchecked( dtype: DataType, storage: Series, ) -> MapChunked
§Safety
storage must satisfy the MapChunked storage safety contract for dtype.
Sourcepub fn try_from_storage(
dtype: DataType,
storage: Series,
) -> Result<MapChunked, PolarsError>
pub fn try_from_storage( dtype: DataType, storage: Series, ) -> Result<MapChunked, PolarsError>
Validate map storage and canonicalize duplicate keys.
Rejects null entries or keys that a live row owns. Duplicate keys keep their first position and last value.
pub fn name(&self) -> &PlSmallStr
pub fn rename(&mut self, name: PlSmallStr)
pub fn field(&self) -> Field
pub fn dtype(&self) -> &DataType
pub fn key_dtype(&self) -> &DataType
pub fn value_dtype(&self) -> &DataType
Sourcepub fn storage(&self) -> &Series
pub fn storage(&self) -> &Series
The raw List(Struct {key, value}) storage, including entries that no live row owns.
Entries and keys are non-null within the offset windows of live rows. Null rows and
slicing can hide arbitrary entries, as they can for any ListChunked;
Self::live_storage empties the null rows.
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
Sourcepub fn any_value_iter(&self) -> impl PolarsIterator
pub fn any_value_iter(&self) -> impl PolarsIterator
One freshly-allocated AnyValue::Map per row.
pub fn get_any_value(&self, i: usize) -> Result<AnyValue<'_>, PolarsError>
Sourcepub unsafe fn get_any_value_unchecked(&self, i: usize) -> AnyValue<'_>
pub unsafe fn get_any_value_unchecked(&self, i: usize) -> AnyValue<'_>
§Safety
i must be in bounds.
Sourcepub fn live_row_lengths(&self) -> impl Iterator<Item = usize>
pub fn live_row_lengths(&self) -> impl Iterator<Item = usize>
Entries each row contributes to Self::keys and Self::values, in row order.
A null row contributes none, whatever its offset window retains. Reads the offsets in place, so pairing this with a flat accessor never materializes the other field.
Sourcepub fn key_lists(&self) -> ChunkedArray<ListType>
pub fn key_lists(&self) -> ChunkedArray<ListType>
One list of keys per row: List(key_dtype).
Preserves rows, validity and entry order; null rows have empty windows.
Sourcepub fn value_lists(&self) -> ChunkedArray<ListType>
pub fn value_lists(&self) -> ChunkedArray<ListType>
One list of values per row: List(value_dtype).
Preserves rows, validity and entry order; null rows have empty windows.
Sourcepub fn with_values(&self, values: &Series) -> Result<MapChunked, PolarsError>
pub fn with_values(&self, values: &Series) -> Result<MapChunked, PolarsError>
Replace live entry values.
Requires one value per live entry, in Self::values order, and a valid Map value
dtype. This also applies to list-valued entries.
Preserves row count, validity, live keys and entry order. Drops entries that no live row owns and may rebase offsets.
Sourcepub fn entries(&self) -> Series
pub fn entries(&self) -> Series
All entries in live rows, flattened in row order.
Excludes entries retained by null rows or sliced away.
Sourcepub fn live_storage(&self) -> Cow<'_, ChunkedArray<ListType>>
pub fn live_storage(&self) -> Cow<'_, ChunkedArray<ListType>>
Storage with empty windows for null rows.
Preserves row count, validity and live entries. Borrows if no compaction is needed.
Mutating the returned Cow affects only its owned copy.
pub fn cast_with_options( &self, dtype: &DataType, options: CastOptions, ) -> Result<Series, PolarsError>
Trait Implementations§
Source§impl Clone for MapChunked
impl Clone for MapChunked
Source§fn clone(&self) -> MapChunked
fn clone(&self) -> MapChunked
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl IntoSeries for MapChunked
impl IntoSeries for MapChunked
Auto Trait Implementations§
impl !RefUnwindSafe for MapChunked
impl !UnwindSafe for MapChunked
impl Freeze for MapChunked
impl Send for MapChunked
impl Sync for MapChunked
impl Unpin for MapChunked
impl UnsafeUnpin for MapChunked
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoColumn for Twhere
T: IntoSeries,
impl<T> IntoColumn for Twhere
T: IntoSeries,
fn into_column(self) -> Column
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