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§
source§impl<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>
source§impl<K: PolarsDataType, T: PolarsDataType> Logical<K, T>where
Self: LogicalType,
impl<K: PolarsDataType, T: PolarsDataType> Logical<K, T>where
Self: LogicalType,
source§impl Logical<DateType, Int32Type>
impl Logical<DateType, Int32Type>
pub fn as_date_iter(
&self
) -> impl Iterator<Item = Option<NaiveDate>> + TrustedLen + '_
temporal
or dtype-datetime
or dtype-date
) and crate feature dtype-date
only.sourcepub fn from_naive_date<I: IntoIterator<Item = NaiveDate>>(
name: &str,
v: I
) -> Self
Available on (crate features temporal
or dtype-datetime
or dtype-date
) and crate feature dtype-date
only.
pub fn from_naive_date<I: IntoIterator<Item = NaiveDate>>(
name: &str,
v: I
) -> Self
temporal
or dtype-datetime
or dtype-date
) and crate feature dtype-date
only.Construct a new DateChunked
from an iterator over NaiveDate
.
sourcepub fn strftime(&self, fmt: &str) -> Utf8Chunked
Available on (crate features temporal
or dtype-datetime
or dtype-date
) and crate feature dtype-date
only.
pub fn strftime(&self, fmt: &str) -> Utf8Chunked
temporal
or dtype-datetime
or dtype-date
) and crate feature dtype-date
only.Format Date with a fmt
rule. See chrono strftime/strptime.
sourcepub fn from_naive_date_options<I: IntoIterator<Item = Option<NaiveDate>>>(
name: &str,
v: I
) -> Self
Available on (crate features temporal
or dtype-datetime
or dtype-date
) and crate feature dtype-date
only.
pub fn from_naive_date_options<I: IntoIterator<Item = Option<NaiveDate>>>(
name: &str,
v: I
) -> Self
temporal
or dtype-datetime
or dtype-date
) and crate feature dtype-date
only.Construct a new DateChunked
from an iterator over optional NaiveDate
.
source§impl Logical<DatetimeType, Int64Type>
impl Logical<DatetimeType, Int64Type>
pub fn as_datetime_iter(
&self
) -> impl Iterator<Item = Option<NaiveDateTime>> + TrustedLen + '_
temporal
or dtype-datetime
or dtype-date
) and crate feature dtype-datetime
only.pub fn time_unit(&self) -> TimeUnit
temporal
or dtype-datetime
or dtype-date
) and crate feature dtype-datetime
only.pub fn time_zone(&self) -> &Option<TimeZone>
temporal
or dtype-datetime
or dtype-date
) and crate feature dtype-datetime
only.pub fn apply_on_tz_corrected<F>(&self, func: F) -> PolarsResult<DatetimeChunked>where
F: FnMut(DatetimeChunked) -> PolarsResult<DatetimeChunked>,
temporal
or dtype-datetime
or dtype-date
) and crate feature dtype-datetime
only.pub fn cast_time_zone(&self, tz: &str) -> PolarsResult<DatetimeChunked>
temporal
or dtype-datetime
or dtype-date
) and crate feature dtype-datetime
and crate feature timezones
only.sourcepub fn strftime(&self, fmt: &str) -> Utf8Chunked
Available on (crate features temporal
or dtype-datetime
or dtype-date
) and crate feature dtype-datetime
only.
pub fn strftime(&self, fmt: &str) -> Utf8Chunked
temporal
or dtype-datetime
or dtype-date
) and crate feature dtype-datetime
only.Format Datetime with a fmt
rule. See chrono strftime/strptime.
sourcepub fn from_naive_datetime<I: IntoIterator<Item = NaiveDateTime>>(
name: &str,
v: I,
tu: TimeUnit
) -> Self
Available on (crate features temporal
or dtype-datetime
or dtype-date
) and crate feature dtype-datetime
only.
pub fn from_naive_datetime<I: IntoIterator<Item = NaiveDateTime>>(
name: &str,
v: I,
tu: TimeUnit
) -> Self
temporal
or dtype-datetime
or dtype-date
) and crate feature dtype-datetime
only.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
temporal
or dtype-datetime
or dtype-date
) and crate feature dtype-datetime
only.sourcepub fn cast_time_unit(&self, tu: TimeUnit) -> Self
Available on (crate features temporal
or dtype-datetime
or dtype-date
) and crate feature dtype-datetime
only.
pub fn cast_time_unit(&self, tu: TimeUnit) -> Self
temporal
or dtype-datetime
or dtype-date
) and crate feature dtype-datetime
only.Change the underlying TimeUnit
. And update the data accordingly.
sourcepub fn set_time_unit(&mut self, tu: TimeUnit)
Available on (crate features temporal
or dtype-datetime
or dtype-date
) and crate feature dtype-datetime
only.
pub fn set_time_unit(&mut self, tu: TimeUnit)
temporal
or dtype-datetime
or dtype-date
) and crate feature dtype-datetime
only.Change the underlying TimeUnit
. This does not modify the data.
sourcepub fn set_time_zone(&mut self, tz: Option<TimeZone>)
Available on (crate features temporal
or dtype-datetime
or dtype-date
) and crate feature dtype-datetime
only.
pub fn set_time_zone(&mut self, tz: Option<TimeZone>)
temporal
or dtype-datetime
or dtype-date
) and crate feature dtype-datetime
only.Change the underlying TimeZone
. This does not modify the data.
pub fn with_time_zone(self, tz: Option<TimeZone>) -> Self
temporal
or dtype-datetime
or dtype-date
) and crate feature dtype-datetime
only.source§impl Logical<DurationType, Int64Type>
impl Logical<DurationType, Int64Type>
pub fn time_unit(&self) -> TimeUnit
temporal
or dtype-datetime
or dtype-date
) and crate feature dtype-duration
only.sourcepub fn cast_time_unit(&self, tu: TimeUnit) -> Self
Available on (crate features temporal
or dtype-datetime
or dtype-date
) and crate feature dtype-duration
only.
pub fn cast_time_unit(&self, tu: TimeUnit) -> Self
temporal
or dtype-datetime
or dtype-date
) and crate feature dtype-duration
only.Change the underlying TimeUnit
. And update the data accordingly.
sourcepub fn set_time_unit(&mut self, tu: TimeUnit)
Available on (crate features temporal
or dtype-datetime
or dtype-date
) and crate feature dtype-duration
only.
pub fn set_time_unit(&mut self, tu: TimeUnit)
temporal
or dtype-datetime
or dtype-date
) and crate feature dtype-duration
only.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
Available on (crate features temporal
or dtype-datetime
or dtype-date
) and crate feature dtype-duration
only.
pub fn from_duration<I: IntoIterator<Item = ChronoDuration>>(
name: &str,
v: I,
tu: TimeUnit
) -> Self
temporal
or dtype-datetime
or dtype-date
) and crate feature dtype-duration
only.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
Available on (crate features temporal
or dtype-datetime
or dtype-date
) and crate feature dtype-duration
only.
pub fn from_duration_options<I: IntoIterator<Item = Option<ChronoDuration>>>(
name: &str,
v: I,
tu: TimeUnit
) -> Self
temporal
or dtype-datetime
or dtype-date
) and crate feature dtype-duration
only.Construct a new DurationChunked
from an iterator over optional ChronoDuration
.
source§impl Logical<TimeType, Int64Type>
impl Logical<TimeType, Int64Type>
pub fn as_time_iter(
&self
) -> impl Iterator<Item = Option<NaiveTime>> + TrustedLen + '_
temporal
or dtype-datetime
or dtype-date
) and crate feature dtype-time
only.sourcepub fn from_naive_time<I: IntoIterator<Item = NaiveTime>>(
name: &str,
v: I
) -> Self
Available on (crate features temporal
or dtype-datetime
or dtype-date
) and crate feature dtype-time
only.
pub fn from_naive_time<I: IntoIterator<Item = NaiveTime>>(
name: &str,
v: I
) -> Self
temporal
or dtype-datetime
or dtype-date
) and crate feature dtype-time
only.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
Available on (crate features temporal
or dtype-datetime
or dtype-date
) and crate feature dtype-time
only.
pub fn from_naive_time_options<I: IntoIterator<Item = Option<NaiveTime>>>(
name: &str,
v: I
) -> Self
temporal
or dtype-datetime
or dtype-date
) and crate feature dtype-time
only.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 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.
pub fn rechunk(&self) -> Self
sourcepub fn slice(&self, offset: i64, length: usize) -> Self
pub fn slice(&self, offset: i64, length: usize) -> Self
Slice the array. The chunks are reallocated the underlying data slices are zero copy.
When offset is negative it will be counted from the end of the array. This method will never error, and will slice the best match when offset, or length is out of bounds
sourcepub fn limit(&self, num_elements: usize) -> Selfwhere
Self: Sized,
pub fn limit(&self, num_elements: usize) -> Selfwhere
Self: Sized,
Take a view of top n elements
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
extend
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_apply_float<F>(
&self,
window_size: usize,
f: F
) -> PolarsResult<Self>where
F: FnMut(&mut ChunkedArray<T>) -> Option<T::Native>,
Available on crate feature rolling_window
only.
pub fn rolling_apply_float<F>(
&self,
window_size: usize,
f: F
) -> PolarsResult<Self>where
F: FnMut(&mut ChunkedArray<T>) -> Option<T::Native>,
rolling_window
only.Apply a rolling custom function. This is pretty slow because of dynamic dispatch.
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(
&mut self
) -> impl IndexedParallelIterator<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) -> PolarsResult<ArrayView1<'_, T::Native>>
Available on crate feature ndarray
only.
pub fn to_ndarray(&self) -> PolarsResult<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) -> PolarsResult<Array2<N::Native>>where
N: PolarsNumericType,
Available on crate feature ndarray
only.
pub fn to_ndarray<N>(&self) -> PolarsResult<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>> + '_>
Available on crate feature private
only.
pub fn amortized_iter(
&self
) -> AmortizedListIter<'_, impl Iterator<Item = Option<ArrayBox>> + '_>
private
only.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) -> Selfwhere
F: FnMut(UnstableSeries<'a>) -> Series,
Available on crate feature private
only.
pub fn apply_amortized<'a, F>(&'a self, f: F) -> Selfwhere
F: FnMut(UnstableSeries<'a>) -> Series,
private
only.Apply a closure F
elementwise.
pub fn try_apply_amortized<'a, F>(&'a self, f: F) -> PolarsResult<Self>where
F: FnMut(UnstableSeries<'a>) -> PolarsResult<Series>,
pub fn set_fast_explode(&mut self)
private
only.pub fn _can_fast_explode(&self) -> bool
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 sample_n(
&self,
n: usize,
with_replacement: bool,
shuffle: bool,
seed: Option<u64>
) -> PolarsResult<Self>
Available on crate feature random
only.
pub fn sample_n(
&self,
n: usize,
with_replacement: bool,
shuffle: bool,
seed: Option<u64>
) -> PolarsResult<Self>
random
only.Sample n datapoints from this ChunkedArray.
sourcepub fn sample_frac(
&self,
frac: f64,
with_replacement: bool,
shuffle: bool,
seed: Option<u64>
) -> PolarsResult<Self>
Available on crate feature random
only.
pub fn sample_frac(
&self,
frac: f64,
with_replacement: bool,
shuffle: bool,
seed: Option<u64>
) -> PolarsResult<Self>
random
only.Sample a fraction between 0.0-1.0 of this ChunkedArray.
pub fn hex_decode(&self) -> PolarsResult<Utf8Chunked>
string_encoding
and non-crate feature binary_encoding
only.pub fn hex_encode(&self) -> Utf8Chunked
string_encoding
only.pub fn base64_decode(&self) -> PolarsResult<Utf8Chunked>
string_encoding
and non-crate feature binary_encoding
only.pub fn base64_encode(&self) -> Utf8Chunked
string_encoding
only.pub fn is_sorted_flag2(&self) -> IsSorted
sourcepub fn set_sorted_flag(&mut self, sorted: IsSorted)
pub fn set_sorted_flag(&mut self, sorted: IsSorted)
Set the ‘sorted’ bit meta info.
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 last_non_null(&self) -> Option<usize>
pub fn last_non_null(&self) -> Option<usize>
Get the index of the last non null value in this ChunkedArray.
sourcepub fn iter_validities(
&self
) -> Map<Iter<'_, ArrayRef>, fn(_: &ArrayRef) -> Option<&Bitmap>>
pub fn iter_validities(
&self
) -> Map<Iter<'_, ArrayRef>, fn(_: &ArrayRef) -> 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 its length.
sourcepub fn unpack_series_matching_type(
&self,
series: &Series
) -> PolarsResult<&ChunkedArray<T>>
pub fn unpack_series_matching_type(
&self,
series: &Series
) -> PolarsResult<&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 unsafe fn chunks_mut(&mut self) -> &mut Vec<ArrayRef> ⓘ
pub unsafe fn chunks_mut(&mut self) -> &mut Vec<ArrayRef> ⓘ
A mutable reference to the chunks
Safety
The caller must ensure to not change the DataType
or length
of any of 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 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 cont_slice(&self) -> PolarsResult<&[T::Native]>
pub fn cont_slice(&self) -> PolarsResult<&[T::Native]>
Contiguous slice
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.
pub fn set_inner_dtype(&mut self, dtype: DataType)
Trait Implementations§
source§impl<K: PolarsDataType, T: PolarsDataType> Clone for Logical<K, T>
impl<K: PolarsDataType, T: PolarsDataType> Clone for Logical<K, T>
source§impl<K: PolarsDataType, T: PolarsDataType> Deref for Logical<K, T>
impl<K: PolarsDataType, T: PolarsDataType> Deref for Logical<K, T>
source§impl<K: PolarsDataType, T: PolarsDataType> DerefMut for Logical<K, T>
impl<K: PolarsDataType, T: PolarsDataType> DerefMut for Logical<K, T>
source§impl From<Logical<DateType, Int32Type>> for Series
Available on crate feature dtype-date
only.
impl From<Logical<DateType, Int32Type>> for Series
dtype-date
only.source§fn from(a: DateChunked) -> Self
fn from(a: DateChunked) -> Self
source§impl From<Logical<DatetimeType, Int64Type>> for Series
Available on crate feature dtype-datetime
only.
impl From<Logical<DatetimeType, Int64Type>> for Series
dtype-datetime
only.