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,
sourceimpl Logical<DateType, Int32Type>
impl Logical<DateType, Int32Type>
pub fn as_date_iter(
&self
) -> impl Iterator<Item = Option<NaiveDate>> + TrustedLen + '_
sourcepub fn from_naive_date<I: IntoIterator<Item = NaiveDate>>(
name: &str,
v: I
) -> Self
pub fn from_naive_date<I: IntoIterator<Item = NaiveDate>>(
name: &str,
v: I
) -> Self
Construct a new DateChunked
from an iterator over NaiveDate
.
sourcepub fn from_naive_date_options<I: IntoIterator<Item = Option<NaiveDate>>>(
name: &str,
v: I
) -> Self
pub fn from_naive_date_options<I: IntoIterator<Item = Option<NaiveDate>>>(
name: &str,
v: I
) -> Self
Construct a new DateChunked
from an iterator over optional NaiveDate
.
sourceimpl Logical<DatetimeType, Int64Type>
impl Logical<DatetimeType, Int64Type>
pub fn as_datetime_iter(
&self
) -> impl Iterator<Item = Option<NaiveDateTime>> + TrustedLen + '_
pub fn time_unit(&self) -> TimeUnit
pub fn time_zone(&self) -> &Option<TimeZone>
sourcepub fn from_naive_datetime<I: IntoIterator<Item = NaiveDateTime>>(
name: &str,
v: I,
tu: TimeUnit
) -> Self
pub fn from_naive_datetime<I: IntoIterator<Item = NaiveDateTime>>(
name: &str,
v: I,
tu: TimeUnit
) -> Self
Construct a new DatetimeChunked
from an iterator over NaiveDateTime
.
pub fn from_naive_datetime_options<I: IntoIterator<Item = Option<NaiveDateTime>>>(
name: &str,
v: I,
tu: TimeUnit
) -> Self
sourcepub fn cast_time_unit(&self, tu: TimeUnit) -> Self
pub fn cast_time_unit(&self, tu: TimeUnit) -> Self
Change the underlying TimeUnit
. And update the data accordingly.
sourcepub fn set_time_unit(&mut self, tu: TimeUnit)
pub fn set_time_unit(&mut self, tu: TimeUnit)
Change the underlying TimeUnit
. This does not modify the data.
sourcepub fn set_time_zone(&mut self, tz: Option<TimeZone>)
pub fn set_time_zone(&mut self, tz: Option<TimeZone>)
Change the underlying TimeZone
. This does not modify the data.
sourceimpl Logical<DurationType, Int64Type>
impl Logical<DurationType, Int64Type>
pub fn time_unit(&self) -> TimeUnit
sourcepub fn cast_time_unit(&self, tu: TimeUnit) -> Self
pub fn cast_time_unit(&self, tu: TimeUnit) -> Self
Change the underlying TimeUnit
. And update the data accordingly.
sourcepub fn set_time_unit(&mut self, tu: TimeUnit)
pub fn set_time_unit(&mut self, tu: TimeUnit)
Change the underlying TimeUnit
. This does not modify the data.
sourcepub fn from_duration<I: IntoIterator<Item = ChronoDuration>>(
name: &str,
v: I,
tu: TimeUnit
) -> Self
pub fn from_duration<I: IntoIterator<Item = ChronoDuration>>(
name: &str,
v: I,
tu: TimeUnit
) -> Self
Construct a new DurationChunked
from an iterator over ChronoDuration
.
sourcepub fn from_duration_options<I: IntoIterator<Item = Option<ChronoDuration>>>(
name: &str,
v: I,
tu: TimeUnit
) -> Self
pub fn from_duration_options<I: IntoIterator<Item = Option<ChronoDuration>>>(
name: &str,
v: I,
tu: TimeUnit
) -> Self
Construct a new DurationChunked
from an iterator over optional ChronoDuration
.
sourceimpl Logical<TimeType, Int64Type>
impl Logical<TimeType, Int64Type>
pub fn as_time_iter(
&self
) -> impl Iterator<Item = Option<NaiveTime>> + TrustedLen + '_
sourcepub fn from_naive_time<I: IntoIterator<Item = NaiveTime>>(
name: &str,
v: I
) -> Self
pub fn from_naive_time<I: IntoIterator<Item = NaiveTime>>(
name: &str,
v: I
) -> Self
Construct a new TimeChunked
from an iterator over NaiveTime
.
sourcepub fn from_naive_time_options<I: IntoIterator<Item = Option<NaiveTime>>>(
name: &str,
v: I
) -> Self
pub fn from_naive_time_options<I: IntoIterator<Item = Option<NaiveTime>>>(
name: &str,
v: I
) -> Self
Construct a new TimeChunked
from an iterator over optional NaiveTime
.
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 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_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.
sourcepub fn to_ndarray(&self) -> Result<ArrayView1<'_, T::Native>>
pub fn to_ndarray(&self) -> Result<ArrayView1<'_, T::Native>>
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,
pub fn to_ndarray<N>(&self) -> Result<Array2<N::Native>> where
N: PolarsNumericType,
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>
pub fn lst_join(&self, separator: &str) -> Result<Utf8Chunked>
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
pub fn lst_min(&self) -> Series
pub fn lst_sum(&self) -> Series
pub fn lst_mean(&self) -> Float64Chunked
pub fn lst_sort(&self, reverse: bool) -> ListChunked
pub fn lst_reverse(&self) -> ListChunked
pub fn lst_unique(&self) -> Result<ListChunked>
pub fn lst_arg_min(&self) -> IdxCa
pub fn lst_arg_max(&self) -> IdxCa
pub fn lst_diff(&self, n: usize, null_behavior: NullBehavior) -> ListChunked
pub fn lst_shift(&self, periods: i64) -> ListChunked
pub fn lst_slice(&self, offset: i64, length: usize) -> ListChunked
pub fn lst_lengths(&self) -> UInt32Chunked
sourcepub fn lst_get(&self, idx: i64) -> Result<Series>
pub fn lst_get(&self, idx: i64) -> Result<Series>
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>
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>
pub unsafe fn get_object_unchecked(
&self,
index: usize
) -> Option<&dyn PolarsObjectSafe>
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>
pub fn get_object(&self, index: usize) -> Option<&dyn PolarsObjectSafe>
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>
pub fn json_path_match(&self, json_path: &str) -> Result<Utf8Chunked>
Extract json path, first match Refer to https://goessner.net/articles/JsonPath/
pub fn hex_decode(&self, strict: Option<bool>) -> Result<Utf8Chunked>
pub fn hex_encode(&self) -> Utf8Chunked
pub fn base64_decode(&self, strict: Option<bool>) -> Result<Utf8Chunked>
pub fn base64_encode(&self) -> Utf8Chunked
sourcepub fn str_lengths(&self) -> UInt32Chunked
pub fn str_lengths(&self) -> UInt32Chunked
Get the length of the string values.
sourcepub fn contains(&self, pat: &str) -> Result<BooleanChunked>
pub fn contains(&self, pat: &str) -> Result<BooleanChunked>
Check if strings contain a regex pattern
sourcepub fn replace(&self, pat: &str, val: &str) -> Result<Utf8Chunked>
pub fn replace(&self, pat: &str, val: &str) -> Result<Utf8Chunked>
Replace the leftmost (sub)string by a regex pattern
sourcepub fn replace_all(&self, pat: &str, val: &str) -> Result<Utf8Chunked>
pub fn replace_all(&self, pat: &str, val: &str) -> Result<Utf8Chunked>
Replace all (sub)strings by a regex pattern
sourcepub fn extract(&self, pat: &str, group_index: usize) -> Result<Utf8Chunked>
pub fn extract(&self, pat: &str, group_index: usize) -> Result<Utf8Chunked>
Extract the nth capture group from pattern
sourcepub fn to_lowercase(&self) -> Utf8Chunked
pub fn to_lowercase(&self) -> Utf8Chunked
Modify the strings to their lowercase equivalent
sourcepub fn to_uppercase(&self) -> Utf8Chunked
pub fn to_uppercase(&self) -> Utf8Chunked
Modify the strings to their uppercase equivalent
sourcepub fn concat(&self, other: &Utf8Chunked) -> Self
pub fn concat(&self, other: &Utf8Chunked) -> Self
Concat with the values from a second Utf8Chunked
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>
sourceimpl From<Logical<DateType, Int32Type>> for Series
impl From<Logical<DateType, Int32Type>> for Series
sourcefn from(a: DateChunked) -> Self
fn from(a: DateChunked) -> Self
Performs the conversion.
sourceimpl From<Logical<DatetimeType, Int64Type>> for Series
impl From<Logical<DatetimeType, Int64Type>> for Series
sourcefn from(a: DatetimeChunked) -> Self
fn from(a: DatetimeChunked) -> Self
Performs the conversion.
sourceimpl From<Logical<DurationType, Int64Type>> for Series
impl From<Logical<DurationType, Int64Type>> for Series
sourcefn from(a: DurationChunked) -> Self
fn from(a: DurationChunked) -> Self
Performs the conversion.
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
sourceimpl<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