polars_core::export::cast

Function primitive_to_dictionary

pub fn primitive_to_dictionary<T, K>(
    from: &PrimitiveArray<T>,
) -> Result<DictionaryArray<K>, PolarsError>
where T: NativeType + Eq + Hash, K: DictionaryKey,
Expand description

Cast [PrimitiveArray] to [DictionaryArray]. Also known as packing.

ยงErrors

This function errors if the maximum key is smaller than the number of distinct elements in the array.