Trait polars_core::chunked_array::ops::ChunkApply
source · pub trait ChunkApply<'a, A, B> {
fn apply_cast_numeric<F, S>(&'a self, f: F) -> ChunkedArray<S>
where
F: Fn(A) -> S::Native + Copy,
S: PolarsNumericType;
fn branch_apply_cast_numeric_no_null<F, S>(&'a self, f: F) -> ChunkedArray<S>
where
F: Fn(Option<A>) -> S::Native + Copy,
S: PolarsNumericType;
fn apply<F>(&'a self, f: F) -> Self
where
F: Fn(A) -> B + Copy;
fn try_apply<F>(&'a self, f: F) -> PolarsResult<Self>
where
F: Fn(A) -> PolarsResult<B> + Copy,
Self: Sized;
fn apply_on_opt<F>(&'a self, f: F) -> Self
where
F: Fn(Option<A>) -> Option<B> + Copy;
fn apply_with_idx<F>(&'a self, f: F) -> Self
where
F: Fn((usize, A)) -> B + Copy;
fn apply_with_idx_on_opt<F>(&'a self, f: F) -> Self
where
F: Fn((usize, Option<A>)) -> Option<B> + Copy;
fn apply_to_slice<F, T>(&'a self, f: F, slice: &mut [T])
where
F: Fn(Option<A>, &T) -> T;
}
Expand description
Fastest way to do elementwise operations on a ChunkedArray
Required Methods§
sourcefn apply_cast_numeric<F, S>(&'a self, f: F) -> ChunkedArray<S>where
F: Fn(A) -> S::Native + Copy,
S: PolarsNumericType,
fn apply_cast_numeric<F, S>(&'a self, f: F) -> ChunkedArray<S>where
F: Fn(A) -> S::Native + Copy,
S: PolarsNumericType,
Apply a closure elementwise and cast to a Numeric ChunkedArray. This is fastest when the null check branching is more expensive than the closure application.
Null values remain null.
sourcefn branch_apply_cast_numeric_no_null<F, S>(&'a self, f: F) -> ChunkedArray<S>where
F: Fn(Option<A>) -> S::Native + Copy,
S: PolarsNumericType,
fn branch_apply_cast_numeric_no_null<F, S>(&'a self, f: F) -> ChunkedArray<S>where
F: Fn(Option<A>) -> S::Native + Copy,
S: PolarsNumericType,
Apply a closure on optional values and cast to Numeric ChunkedArray without null values.
sourcefn apply<F>(&'a self, f: F) -> Selfwhere
F: Fn(A) -> B + Copy,
fn apply<F>(&'a self, f: F) -> Selfwhere
F: Fn(A) -> B + Copy,
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(|v| v * 2)
}
fn try_apply<F>(&'a self, f: F) -> PolarsResult<Self>where
F: Fn(A) -> PolarsResult<B> + Copy,
Self: Sized,
sourcefn apply_on_opt<F>(&'a self, f: F) -> Selfwhere
F: Fn(Option<A>) -> Option<B> + Copy,
fn apply_on_opt<F>(&'a self, f: F) -> Selfwhere
F: Fn(Option<A>) -> Option<B> + Copy,
Apply a closure elementwise including null values.
sourcefn apply_with_idx<F>(&'a self, f: F) -> Selfwhere
F: Fn((usize, A)) -> B + Copy,
fn apply_with_idx<F>(&'a self, f: F) -> Selfwhere
F: Fn((usize, A)) -> B + Copy,
Apply a closure elementwise. The closure gets the index of the element as first argument.
Implementors§
impl<'a> ChunkApply<'a, &'a str, Cow<'a, str>> for Utf8Chunked
impl<'a> ChunkApply<'a, &'a [u8], Cow<'a, [u8]>> for BinaryChunked
Available on crate feature
dtype-binary
only.impl<'a> ChunkApply<'a, bool, bool> for BooleanChunked
impl<'a> ChunkApply<'a, Series, Series> for ListChunked
impl<'a, T> ChunkApply<'a, <T as PolarsNumericType>::Native, <T as PolarsNumericType>::Native> for ChunkedArray<T>where
T: PolarsNumericType,
impl<'a, T> ChunkApply<'a, &'a T, T> for ObjectChunked<T>where
T: PolarsObject,
Available on crate feature
object
only.