Struct polars_core::datatypes::Logical
source · [−]pub struct Logical<Logical: PolarsDataType, Physical: PolarsDataType>(pub ChunkedArray<Physical>, _, pub Option<DataType>);
Expand description
Maps a logical type to a a chunked array implementation of the physical type. This saves a lot of compiler bloat and allows us to reuse functionality.
Tuple Fields
0: ChunkedArray<Physical>
2: Option<DataType>
Implementations
sourceimpl<K: PolarsDataType, T: PolarsDataType> Logical<K, T>
impl<K: PolarsDataType, T: PolarsDataType> Logical<K, T>
pub fn new_logical<J: PolarsDataType>(ca: ChunkedArray<T>) -> Logical<J, T>
sourceimpl<K: PolarsDataType, T: PolarsDataType> Logical<K, T> where
Self: LogicalType,
impl<K: PolarsDataType, T: PolarsDataType> Logical<K, T> where
Self: LogicalType,
Methods from Deref<Target = ChunkedArray<T>>
sourcepub fn append(&mut self, other: &Self)
pub fn append(&mut self, other: &Self)
Append in place. This is done by adding the chunks of other
to this ChunkedArray
.
See also extend
for appends to the underlying memory
sourcepub fn cast_and_apply_in_place<F, S>(&self, f: F) -> ChunkedArray<S> where
F: Fn(S::Native) -> S::Native + Copy,
S: PolarsNumericType,
pub fn cast_and_apply_in_place<F, S>(&self, f: F) -> ChunkedArray<S> where
F: Fn(S::Native) -> S::Native + Copy,
S: PolarsNumericType,
Cast a numeric array to another numeric data type and apply a function in place. This saves an allocation.
sourcepub fn extend(&mut self, other: &Self)
pub fn extend(&mut self, other: &Self)
Extend the memory backed by this array with the values from other
.
Different from ChunkedArray::append
which adds chunks to this ChunkedArray
extent
appends the data from other
to the underlying PrimitiveArray
and thus may cause a reallocation.
However if this does not cause a reallocation, the resulting data structure will not have any extra chunks and thus will yield faster queries.
Prefer extend
over append
when you want to do a query after a single append. For instance during
online operations where you add n
rows and rerun a query.
Prefer append
over extend
when you want to append many times before doing a query. For instance
when you read in multiple files and when to store them in a single DataFrame
.
In the latter case finish the sequence of append
operations with a rechunk
.
sourcepub fn rolling_mean(&self, options: RollingOptions) -> Result<Series>
pub fn rolling_mean(&self, options: RollingOptions) -> Result<Series>
Apply a rolling mean (moving mean) over the values in this array.
A window of length window_size
will traverse the array. The values that fill this window
will (optionally) be multiplied with the weights given by the weights
vector. The resulting
values will be aggregated to their mean.
sourcepub fn rolling_sum(&self, options: RollingOptions) -> Result<Series>
pub fn rolling_sum(&self, options: RollingOptions) -> Result<Series>
Apply a rolling sum (moving sum) over the values in this array.
A window of length window_size
will traverse the array. The values that fill this window
will (optionally) be multiplied with the weights given by the weights
vector. The resulting
values will be aggregated to their sum.
sourcepub fn rolling_min(&self, options: RollingOptions) -> Result<Series>
pub fn rolling_min(&self, options: RollingOptions) -> Result<Series>
Apply a rolling min (moving min) over the values in this array.
A window of length window_size
will traverse the array. The values that fill this window
will (optionally) be multiplied with the weights given by the weights
vector. The resulting
values will be aggregated to their min.
sourcepub fn rolling_max(&self, options: RollingOptions) -> Result<Series>
pub fn rolling_max(&self, options: RollingOptions) -> Result<Series>
Apply a rolling max (moving max) over the values in this array.
A window of length window_size
will traverse the array. The values that fill this window
will (optionally) be multiplied with the weights given by the weights
vector. The resulting
values will be aggregated to their max.
sourcepub fn rolling_median(&self, options: RollingOptions) -> Result<Series>
pub fn rolling_median(&self, options: RollingOptions) -> Result<Series>
Apply a rolling median (moving median) over the values in this array.
A window of length window_size
will traverse the array. The values that fill this window
will (optionally) be weighted according to the weights
vector.
sourcepub fn rolling_quantile(
&self,
quantile: f64,
interpolation: QuantileInterpolOptions,
options: RollingOptions
) -> Result<Series>
pub fn rolling_quantile(
&self,
quantile: f64,
interpolation: QuantileInterpolOptions,
options: RollingOptions
) -> Result<Series>
Apply a rolling quantile (moving quantile) over the values in this array.
A window of length window_size
will traverse the array. The values that fill this window
will (optionally) be weighted according to the weights
vector.
sourcepub fn rolling_mean(&self, options: RollingOptions) -> Result<Series>
pub fn rolling_mean(&self, options: RollingOptions) -> Result<Series>
Apply a rolling mean (moving mean) over the values in this array.
A window of length window_size
will traverse the array. The values that fill this window
will (optionally) be multiplied with the weights given by the weights
vector. The resulting
values will be aggregated to their mean.
sourcepub fn rolling_sum(&self, options: RollingOptions) -> Result<Series>
pub fn rolling_sum(&self, options: RollingOptions) -> Result<Series>
Apply a rolling sum (moving sum) over the values in this array.
A window of length window_size
will traverse the array. The values that fill this window
will (optionally) be multiplied with the weights given by the weights
vector. The resulting
values will be aggregated to their sum.
sourcepub fn rolling_min(&self, options: RollingOptions) -> Result<Series>
pub fn rolling_min(&self, options: RollingOptions) -> Result<Series>
Apply a rolling min (moving min) over the values in this array.
A window of length window_size
will traverse the array. The values that fill this window
will (optionally) be multiplied with the weights given by the weights
vector. The resulting
values will be aggregated to their min.
sourcepub fn rolling_max(&self, options: RollingOptions) -> Result<Series>
pub fn rolling_max(&self, options: RollingOptions) -> Result<Series>
Apply a rolling max (moving max) over the values in this array.
A window of length window_size
will traverse the array. The values that fill this window
will (optionally) be multiplied with the weights given by the weights
vector. The resulting
values will be aggregated to their max.
sourcepub fn rolling_median(&self, options: RollingOptions) -> Result<Series>
pub fn rolling_median(&self, options: RollingOptions) -> Result<Series>
Apply a rolling median (moving median) over the values in this array.
A window of length window_size
will traverse the array. The values that fill this window
will (optionally) be weighted according to the weights
vector.
sourcepub fn rolling_quantile(
&self,
quantile: f64,
interpolation: QuantileInterpolOptions,
options: RollingOptions
) -> Result<Series>
pub fn rolling_quantile(
&self,
quantile: f64,
interpolation: QuantileInterpolOptions,
options: RollingOptions
) -> Result<Series>
Apply a rolling quantile (moving quantile) over the values in this array.
A window of length window_size
will traverse the array. The values that fill this window
will (optionally) be weighted according to the weights
vector.
sourcepub fn rolling_sum(&self, options: RollingOptions) -> Result<Series>
pub fn rolling_sum(&self, options: RollingOptions) -> Result<Series>
Apply a rolling sum (moving sum) over the values in this array.
A window of length window_size
will traverse the array. The values that fill this window
will (optionally) be multiplied with the weights given by the weights
vector. The resulting
values will be aggregated to their sum.
sourcepub fn rolling_median(&self, options: RollingOptions) -> Result<Series>
pub fn rolling_median(&self, options: RollingOptions) -> Result<Series>
Apply a rolling median (moving median) over the values in this array.
A window of length window_size
will traverse the array. The values that fill this window
will (optionally) be weighted according to the weights
vector.
sourcepub fn rolling_quantile(
&self,
quantile: f64,
interpolation: QuantileInterpolOptions,
options: RollingOptions
) -> Result<Series>
pub fn rolling_quantile(
&self,
quantile: f64,
interpolation: QuantileInterpolOptions,
options: RollingOptions
) -> Result<Series>
Apply a rolling quantile (moving quantile) over the values in this array.
A window of length window_size
will traverse the array. The values that fill this window
will (optionally) be weighted according to the weights
vector.
sourcepub fn rolling_min(&self, options: RollingOptions) -> Result<Series>
pub fn rolling_min(&self, options: RollingOptions) -> Result<Series>
Apply a rolling min (moving min) over the values in this array.
A window of length window_size
will traverse the array. The values that fill this window
will (optionally) be multiplied with the weights given by the weights
vector. The resulting
values will be aggregated to their min.
sourcepub fn rolling_max(&self, options: RollingOptions) -> Result<Series>
pub fn rolling_max(&self, options: RollingOptions) -> Result<Series>
Apply a rolling max (moving max) over the values in this array.
A window of length window_size
will traverse the array. The values that fill this window
will (optionally) be multiplied with the weights given by the weights
vector. The resulting
values will be aggregated to their max.
sourcepub fn rolling_apply_float<F>(&self, window_size: usize, f: F) -> Result<Self> where
F: Fn(&ChunkedArray<T>) -> Option<T::Native>,
pub fn rolling_apply_float<F>(&self, window_size: usize, f: F) -> Result<Self> where
F: Fn(&ChunkedArray<T>) -> Option<T::Native>,
Apply a rolling custom function. This is pretty slow because of dynamic dispatch.
sourcepub fn rolling_var(&self, options: RollingOptions) -> Result<Series>
pub fn rolling_var(&self, options: RollingOptions) -> Result<Series>
Apply a rolling var (moving var) over the values in this array.
A window of length window_size
will traverse the array. The values that fill this window
will (optionally) be multiplied with the weights given by the weights
vector. The resulting
values will be aggregated to their var.
sourcepub fn rolling_std(&self, options: RollingOptions) -> Result<Series>
pub fn rolling_std(&self, options: RollingOptions) -> Result<Series>
Apply a rolling std (moving std) over the values in this array.
A window of length window_size
will traverse the array. The values that fill this window
will (optionally) be multiplied with the weights given by the weights
vector. The resulting
values will be aggregated to their std.
pub fn is_nan(&self) -> BooleanChunked
pub fn is_not_nan(&self) -> BooleanChunked
pub fn is_finite(&self) -> BooleanChunked
pub fn is_infinite(&self) -> BooleanChunked
sourcepub fn none_to_nan(&self) -> Self
pub fn none_to_nan(&self) -> Self
Convert missing values to NaN
values.
pub fn par_iter(&self) -> impl ParallelIterator<Item = Option<Series>> + '_
pub fn par_iter_indexed(
&self
) -> impl IndexedParallelIterator<Item = Option<&str>>
pub fn par_iter(&self) -> impl ParallelIterator<Item = Option<&str>> + '_
sourcepub fn to_ndarray(&self) -> Result<ArrayView1<'_, T::Native>>
Available on crate feature ndarray
only.
pub fn to_ndarray(&self) -> Result<ArrayView1<'_, T::Native>>
ndarray
only.If data is aligned in a single chunk and has no Null values a zero copy view is returned
as an ndarray
sourcepub fn to_ndarray<N>(&self) -> Result<Array2<N::Native>> where
N: PolarsNumericType,
Available on crate feature ndarray
only.
pub fn to_ndarray<N>(&self) -> Result<Array2<N::Native>> where
N: PolarsNumericType,
ndarray
only.If all nested Series
have the same length, a 2 dimensional ndarray::Array
is returned.
sourcepub fn amortized_iter(
&self
) -> AmortizedListIter<'_, impl Iterator<Item = Option<ArrayBox>> + '_>
pub fn amortized_iter(
&self
) -> AmortizedListIter<'_, impl Iterator<Item = Option<ArrayBox>> + '_>
This is an iterator over a ListChunked that save allocations.
A Series is:
1. Arc
The ArrayRef we indicated with 3. will be updated during iteration. The Series will be pinned in memory, saving an allocation for
- Arc<..>
- Vec<…>
Warning
Though memory safe in the sense that it will not read unowned memory, UB, or memory leaks
this function still needs precautions. The returned should never be cloned or taken longer
than a single iteration, as every call on next
of the iterator will change the contents of
that Series.
sourcepub fn apply_amortized<'a, F>(&'a self, f: F) -> Self where
F: FnMut(UnstableSeries<'a>) -> Series,
pub fn apply_amortized<'a, F>(&'a self, f: F) -> Self where
F: FnMut(UnstableSeries<'a>) -> Series,
Apply a closure F
elementwise.
pub fn try_apply_amortized<'a, F>(&'a self, f: F) -> Result<Self> where
F: FnMut(UnstableSeries<'a>) -> Result<Series>,
sourcepub fn lst_join(&self, separator: &str) -> Result<Utf8Chunked>
Available on crate feature list
only.
pub fn lst_join(&self, separator: &str) -> Result<Utf8Chunked>
list
only.In case the inner dtype DataType::Utf8
, the individual items will be joined into a
single string separated by separator
.
pub fn lst_max(&self) -> Series
list
only.pub fn lst_min(&self) -> Series
list
only.pub fn lst_sum(&self) -> Series
list
only.pub fn lst_mean(&self) -> Float64Chunked
list
only.pub fn lst_sort(&self, reverse: bool) -> ListChunked
list
only.pub fn lst_reverse(&self) -> ListChunked
list
only.pub fn lst_unique(&self) -> Result<ListChunked>
list
only.pub fn lst_arg_min(&self) -> IdxCa
list
only.pub fn lst_arg_max(&self) -> IdxCa
list
only.pub fn lst_diff(&self, n: usize, null_behavior: NullBehavior) -> ListChunked
list
and diff
only.pub fn lst_shift(&self, periods: i64) -> ListChunked
list
only.pub fn lst_slice(&self, offset: i64, length: usize) -> ListChunked
list
only.pub fn lst_lengths(&self) -> UInt32Chunked
list
only.sourcepub fn lst_get(&self, idx: i64) -> Result<Series>
Available on crate feature list
only.
pub fn lst_get(&self, idx: i64) -> Result<Series>
list
only.Get the value by index in the sublists.
So index 0
would return the first item of every sublist
and index -1
would return the last item of every sublist
if an index is out of bounds, it will return a None
.
pub fn lst_concat(&self, other: &[Series]) -> Result<ListChunked>
list
only.pub fn set_fast_explode(&mut self)
pub fn to_logical(&mut self, inner_dtype: DataType)
sourcepub unsafe fn get_object_unchecked(
&self,
index: usize
) -> Option<&dyn PolarsObjectSafe>
Available on crate feature object
only.
pub unsafe fn get_object_unchecked(
&self,
index: usize
) -> Option<&dyn PolarsObjectSafe>
object
only.Get a hold to an object that can be formatted or downcasted via the Any trait.
Safety
No bounds checks
sourcepub fn get_object(&self, index: usize) -> Option<&dyn PolarsObjectSafe>
Available on crate feature object
only.
pub fn get_object(&self, index: usize) -> Option<&dyn PolarsObjectSafe>
object
only.Get a hold to an object that can be formatted or downcasted via the Any trait.
sourcepub fn json_path_match(&self, json_path: &str) -> Result<Utf8Chunked>
Available on crate feature strings
only.
pub fn json_path_match(&self, json_path: &str) -> Result<Utf8Chunked>
strings
only.Extract json path, first match Refer to https://goessner.net/articles/JsonPath/
pub fn hex_decode(&self, strict: Option<bool>) -> Result<Utf8Chunked>
strings
only.pub fn hex_encode(&self) -> Utf8Chunked
strings
only.pub fn base64_decode(&self, strict: Option<bool>) -> Result<Utf8Chunked>
strings
only.pub fn base64_encode(&self) -> Utf8Chunked
strings
only.sourcepub fn str_lengths(&self) -> UInt32Chunked
Available on crate feature strings
only.
pub fn str_lengths(&self) -> UInt32Chunked
strings
only.Get the length of the string values.
sourcepub fn contains(&self, pat: &str) -> Result<BooleanChunked>
Available on crate feature strings
only.
pub fn contains(&self, pat: &str) -> Result<BooleanChunked>
strings
only.Check if strings contain a regex pattern
sourcepub fn replace(&self, pat: &str, val: &str) -> Result<Utf8Chunked>
Available on crate feature strings
only.
pub fn replace(&self, pat: &str, val: &str) -> Result<Utf8Chunked>
strings
only.Replace the leftmost (sub)string by a regex pattern
sourcepub fn replace_all(&self, pat: &str, val: &str) -> Result<Utf8Chunked>
Available on crate feature strings
only.
pub fn replace_all(&self, pat: &str, val: &str) -> Result<Utf8Chunked>
strings
only.Replace all (sub)strings by a regex pattern
sourcepub fn extract(&self, pat: &str, group_index: usize) -> Result<Utf8Chunked>
Available on crate feature strings
only.
pub fn extract(&self, pat: &str, group_index: usize) -> Result<Utf8Chunked>
strings
only.Extract the nth capture group from pattern
sourcepub fn to_lowercase(&self) -> Utf8Chunked
Available on crate feature strings
only.
pub fn to_lowercase(&self) -> Utf8Chunked
strings
only.Modify the strings to their lowercase equivalent
sourcepub fn to_uppercase(&self) -> Utf8Chunked
Available on crate feature strings
only.
pub fn to_uppercase(&self) -> Utf8Chunked
strings
only.Modify the strings to their uppercase equivalent
sourcepub fn concat(&self, other: &Utf8Chunked) -> Self
Available on crate feature strings
only.
pub fn concat(&self, other: &Utf8Chunked) -> Self
strings
only.Concat with the values from a second Utf8Chunked
sourcepub fn str_slice(&self, start: i64, length: Option<u64>) -> Result<Self>
Available on crate feature strings
only.
pub fn str_slice(&self, start: i64, length: Option<u64>) -> Result<Self>
strings
only.Slice the string values
Determines a substring starting from start
and with optional length length
of each of the elements in array
.
start
can be negative, in which case the start counts from the end of the string.
sourcepub fn first_non_null(&self) -> Option<usize>
pub fn first_non_null(&self) -> Option<usize>
Get the index of the first non null value in this ChunkedArray.
sourcepub fn iter_validities(&self) -> impl Iterator<Item = Option<&Bitmap>> + '_
pub fn iter_validities(&self) -> impl Iterator<Item = Option<&Bitmap>> + '_
Get the buffer of bits representing null values
sourcepub fn has_validity(&self) -> bool
pub fn has_validity(&self) -> bool
Return if any the chunks in this [ChunkedArray]
have a validity bitmap.
no bitmap means no null values.
sourcepub fn shrink_to_fit(&mut self)
pub fn shrink_to_fit(&mut self)
Shrink the capacity of this array to fit it’s length.
sourcepub fn unpack_series_matching_type(
&self,
series: &Series
) -> Result<&ChunkedArray<T>>
pub fn unpack_series_matching_type(
&self,
series: &Series
) -> Result<&ChunkedArray<T>>
Series to ChunkedArray
sourcepub fn chunk_id(&self) -> ChunkIdIter<'_>
pub fn chunk_id(&self) -> ChunkIdIter<'_>
Unique id representing the number of chunks
sourcepub fn chunks(&self) -> &Vec<ArrayRef>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
pub fn chunks(&self) -> &Vec<ArrayRef>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
A reference to the chunks
sourcepub fn is_optimal_aligned(&self) -> bool
pub fn is_optimal_aligned(&self) -> bool
Returns true if contains a single chunk and has no null values
sourcepub fn null_count(&self) -> usize
pub fn null_count(&self) -> usize
Count the null values.
sourcepub fn append_array(&mut self, other: ArrayRef) -> Result<()>
pub fn append_array(&mut self, other: ArrayRef) -> Result<()>
Append arrow array in place.
let mut array = Int32Chunked::new("array", &[1, 2]);
let array_2 = Int32Chunked::new("2nd", &[3]);
array.append(&array_2);
assert_eq!(Vec::from(&array), [Some(1), Some(2), Some(3)])
sourcepub fn is_null(&self) -> BooleanChunked
pub fn is_null(&self) -> BooleanChunked
Get a mask of the null values.
sourcepub fn is_not_null(&self) -> BooleanChunked
pub fn is_not_null(&self) -> BooleanChunked
Get a mask of the valid values.
sourcepub fn data_views(
&self
) -> impl Iterator<Item = &[T::Native]> + DoubleEndedIterator
pub fn data_views(
&self
) -> impl Iterator<Item = &[T::Native]> + DoubleEndedIterator
Get slices of the underlying arrow data. NOTE: null values should be taken into account by the user of these slices as they are handled separately
pub fn into_no_null_iter(
&self
) -> impl Iterator<Item = T::Native> + '_ + Send + Sync + ExactSizeIterator + DoubleEndedIterator + TrustedLen
sourcepub fn inner_dtype(&self) -> DataType
pub fn inner_dtype(&self) -> DataType
Get the inner data type of the list.
Trait Implementations
sourceimpl<K: PolarsDataType, T: PolarsDataType> Clone for Logical<K, T>
impl<K: PolarsDataType, T: PolarsDataType> Clone for Logical<K, T>
sourceimpl<K: PolarsDataType, T: PolarsDataType> Deref for Logical<K, T>
impl<K: PolarsDataType, T: PolarsDataType> Deref for Logical<K, T>
type Target = ChunkedArray<T>
type Target = ChunkedArray<T>
The resulting type after dereferencing.
sourceimpl<K: PolarsDataType, T: PolarsDataType> DerefMut for Logical<K, T>
impl<K: PolarsDataType, T: PolarsDataType> DerefMut for Logical<K, T>
Auto Trait Implementations
impl<Logical, Physical> !RefUnwindSafe for Logical<Logical, Physical>
impl<Logical, Physical> Send for Logical<Logical, Physical>
impl<Logical, Physical> Sync for Logical<Logical, Physical>
impl<Logical, Physical> Unpin for Logical<Logical, Physical> where
Logical: Unpin,
Physical: Unpin,
impl<Logical, Physical> !UnwindSafe for Logical<Logical, Physical>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<T> Pointable for T
impl<T> Pointable for T
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more