You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Polars plugin providing a Map extension type and functions.
Maps represent a mapping from unique keys of any type to values, and are stored as List(Struct({key, value})) columns.
All function in the .map namespace can be used on the extension type or on the
underlying list.
Installation
pip install polars-map
Supported operations (.map.*)
Category
Methods
Accessors
entries, keys, values, len, get, contains_key
Filtering
filter, filter_keys, filter_values
Transform
eval, eval_keys, eval_values
Set ops
merge, intersection, difference
Conversion
from_entries
Iteration
__iter__, to_list (Series only)
Arrow conversion
Function
Description
from_arrow(table)
Arrow Table/RecordBatch to Polars DataFrame, preserving map<> as Map
from_arrow_array(array)
Arrow Array to Polars Series, preserving map<> as Map
to_arrow(frame)
Polars DataFrame to Arrow Table, converting Map back to map<>
to_arrow_array(series)
Polars Series to Arrow Array, converting Map back to map<>
scan_arrow(source)
Lazy scan from an Arrow source with Map preservation
Extension types — used to wrap the underlying List(Struct) storage with a semantic Map dtype, are not yet stabilized and may change across Polars releases.
pl.dtype_of — used to efficiently cast to the extension type after some operations is also unstable.
GIL - is required to automatically wrap an expression as the extension type, and so operations which could change the underlying key or value types will briefly lock the GIL to do the cast. This may also prevent the polars engine from reasoning about the type.
LongMap - arrow currently only support Map, not LongMap. Polars generlly uses LongList, but if a frame is every converted to arrow with offsets that don't fit in a u32, this will exproting will error.