pub trait ChunkApply<'a, T> {
type FuncRet;
// Required methods
fn apply_values<F>(&'a self, f: F) -> Self
where F: Fn(T) -> Self::FuncRet + Copy;
fn apply<F>(&'a self, f: F) -> Self
where F: Fn(Option<T>) -> Option<Self::FuncRet> + Copy;
fn apply_to_slice<F, S>(&'a self, f: F, slice: &mut [S])
where F: Fn(Option<T>, &S) -> S;
}
Expand description
Fastest way to do elementwise operations on a ChunkedArray<T>
when the operation is cheaper than
branching due to null checking.
Required Associated Types§
Required Methods§
Sourcefn apply_values<F>(&'a self, f: F) -> Self
fn apply_values<F>(&'a self, f: F) -> Self
Apply a closure elementwise. This is fastest when the null check branching is more expensive than the closure application. Often it is.
Null values remain null.
§Example
use polars_core::prelude::*;
fn double(ca: &UInt32Chunked) -> UInt32Chunked {
ca.apply_values(|v| v * 2)
}
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementors§
Source§impl<'a> ChunkApply<'a, &'a str> for ChunkedArray<StringType>
impl<'a> ChunkApply<'a, &'a str> for ChunkedArray<StringType>
Source§impl<'a> ChunkApply<'a, &'a [u8]> for ChunkedArray<BinaryType>
impl<'a> ChunkApply<'a, &'a [u8]> for ChunkedArray<BinaryType>
Source§impl<'a> ChunkApply<'a, bool> for ChunkedArray<BooleanType>
impl<'a> ChunkApply<'a, bool> for ChunkedArray<BooleanType>
Source§impl<'a> ChunkApply<'a, Series> for ChunkedArray<ListType>
impl<'a> ChunkApply<'a, Series> for ChunkedArray<ListType>
Source§impl<'a, T> ChunkApply<'a, <T as PolarsNumericType>::Native> for ChunkedArray<T>where
T: PolarsNumericType,
impl<'a, T> ChunkApply<'a, <T as PolarsNumericType>::Native> for ChunkedArray<T>where
T: PolarsNumericType,
type FuncRet = <T as PolarsNumericType>::Native
Source§impl<'a, T> ChunkApply<'a, &'a T> for ChunkedArray<ObjectType<T>>where
T: PolarsObject,
Available on crate feature object
only.
impl<'a, T> ChunkApply<'a, &'a T> for ChunkedArray<ObjectType<T>>where
T: PolarsObject,
Available on crate feature
object
only.