[−][src]Trait polars::chunked_array::ops::ChunkSet
Create a ChunkedArray
with new values by index or by boolean mask.
Note that these operations clone data. This is however the only way we can modify at mask or
index level as the underlying Arrow arrays are immutable.
Required methods
pub fn set_at_idx<T: AsTakeIndex>(
&'a self,
idx: &T,
opt_value: Option<A>
) -> Result<Self> where
Self: Sized,
[src]
&'a self,
idx: &T,
opt_value: Option<A>
) -> Result<Self> where
Self: Sized,
Set the values at indexes idx
to some optional value Option<T>
.
Example
let ca = Int32Chunked::new_from_slice("a", &[1, 2, 3]); let new = ca.set_at_idx(&[0, 1], Some(10)).unwrap(); assert_eq!(Vec::from(&new), &[Some(10), Some(10), Some(3)]);
pub fn set_at_idx_with<T: AsTakeIndex, F>(
&'a self,
idx: &T,
f: F
) -> Result<Self> where
Self: Sized,
F: Fn(Option<A>) -> Option<B>,
[src]
&'a self,
idx: &T,
f: F
) -> Result<Self> where
Self: Sized,
F: Fn(Option<A>) -> Option<B>,
Set the values at indexes idx
by applying a closure to these values.
Example
let ca = Int32Chunked::new_from_slice("a", &[1, 2, 3]); let new = ca.set_at_idx_with(&[0, 1], |opt_v| opt_v.map(|v| v - 5)).unwrap(); assert_eq!(Vec::from(&new), &[Some(-4), Some(-3), Some(3)]);
pub fn set(
&'a self,
mask: &BooleanChunked,
opt_value: Option<A>
) -> Result<Self> where
Self: Sized,
[src]
&'a self,
mask: &BooleanChunked,
opt_value: Option<A>
) -> Result<Self> where
Self: Sized,
Set the values where the mask evaluates to true
to some optional value Option<T>
.
Example
let ca = Int32Chunked::new_from_slice("a", &[1, 2, 3]); let mask = BooleanChunked::new_from_slice("mask", &[false, true, false]); let new = ca.set(&mask, Some(5)).unwrap(); assert_eq!(Vec::from(&new), &[Some(1), Some(5), Some(3)]);
pub fn set_with<F>(&'a self, mask: &BooleanChunked, f: F) -> Result<Self> where
Self: Sized,
F: Fn(Option<A>) -> Option<B>,
[src]
Self: Sized,
F: Fn(Option<A>) -> Option<B>,
Set the values where the mask evaluates to true
by applying a closure to these values.
Example
let ca = Int32Chunked::new_from_slice("a", &[1, 2, 3]); let mask = BooleanChunked::new_from_slice("mask", &[false, true, false]); let new = ca.set_with(&mask, |opt_v| opt_v.map( |v| v * 2 )).unwrap(); assert_eq!(Vec::from(&new), &[Some(1), Some(4), Some(3)]);
Implementors
impl<'a> ChunkSet<'a, &'a str, String> for Utf8Chunked
[src]
pub fn set_at_idx<T: AsTakeIndex>(
&'a self,
idx: &T,
opt_value: Option<&'a str>
) -> Result<Self> where
Self: Sized,
[src]
&'a self,
idx: &T,
opt_value: Option<&'a str>
) -> Result<Self> where
Self: Sized,
pub fn set_at_idx_with<T: AsTakeIndex, F>(
&'a self,
idx: &T,
f: F
) -> Result<Self> where
Self: Sized,
F: Fn(Option<&'a str>) -> Option<String>,
[src]
&'a self,
idx: &T,
f: F
) -> Result<Self> where
Self: Sized,
F: Fn(Option<&'a str>) -> Option<String>,
pub fn set(
&'a self,
mask: &BooleanChunked,
opt_value: Option<&'a str>
) -> Result<Self> where
Self: Sized,
[src]
&'a self,
mask: &BooleanChunked,
opt_value: Option<&'a str>
) -> Result<Self> where
Self: Sized,
pub fn set_with<F>(&'a self, mask: &BooleanChunked, f: F) -> Result<Self> where
Self: Sized,
F: Fn(Option<&'a str>) -> Option<String>,
[src]
Self: Sized,
F: Fn(Option<&'a str>) -> Option<String>,
impl<'a> ChunkSet<'a, bool, bool> for BooleanChunked
[src]
pub fn set_at_idx<I: AsTakeIndex>(
&'a self,
idx: &I,
value: Option<bool>
) -> Result<Self>
[src]
&'a self,
idx: &I,
value: Option<bool>
) -> Result<Self>
pub fn set_at_idx_with<I: AsTakeIndex, F>(
&'a self,
idx: &I,
f: F
) -> Result<Self> where
F: Fn(Option<bool>) -> Option<bool>,
[src]
&'a self,
idx: &I,
f: F
) -> Result<Self> where
F: Fn(Option<bool>) -> Option<bool>,
pub fn set(&'a self, mask: &BooleanChunked, value: Option<bool>) -> Result<Self>
[src]
pub fn set_with<F>(&'a self, mask: &BooleanChunked, f: F) -> Result<Self> where
F: Fn(Option<bool>) -> Option<bool>,
[src]
F: Fn(Option<bool>) -> Option<bool>,
impl<'a, T> ChunkSet<'a, <T as ArrowPrimitiveType>::Native, <T as ArrowPrimitiveType>::Native> for ChunkedArray<T> where
T: PolarsNumericType,
[src]
T: PolarsNumericType,
pub fn set_at_idx<I: AsTakeIndex>(
&'a self,
idx: &I,
value: Option<T::Native>
) -> Result<Self>
[src]
&'a self,
idx: &I,
value: Option<T::Native>
) -> Result<Self>
pub fn set_at_idx_with<I: AsTakeIndex, F>(
&'a self,
idx: &I,
f: F
) -> Result<Self> where
F: Fn(Option<T::Native>) -> Option<T::Native>,
[src]
&'a self,
idx: &I,
f: F
) -> Result<Self> where
F: Fn(Option<T::Native>) -> Option<T::Native>,
pub fn set(
&'a self,
mask: &BooleanChunked,
value: Option<T::Native>
) -> Result<Self>
[src]
&'a self,
mask: &BooleanChunked,
value: Option<T::Native>
) -> Result<Self>
pub fn set_with<F>(&'a self, mask: &BooleanChunked, f: F) -> Result<Self> where
F: Fn(Option<T::Native>) -> Option<T::Native>,
[src]
F: Fn(Option<T::Native>) -> Option<T::Native>,