Path: blob/main/crates/polars-core/src/series/implementations/array.rs
6940 views
use std::any::Any;1use std::borrow::Cow;23use self::compare_inner::{TotalEqInner, TotalOrdInner};4use self::sort::arg_sort_row_fmt;5use super::{IsSorted, StatisticsFlags, private};6use crate::chunked_array::AsSinglePtr;7use crate::chunked_array::cast::CastOptions;8use crate::chunked_array::comparison::*;9#[cfg(feature = "algorithm_group_by")]10use crate::frame::group_by::*;11use crate::prelude::row_encode::_get_rows_encoded_ca_unordered;12use crate::prelude::*;13use crate::series::implementations::SeriesWrap;1415impl private::PrivateSeries for SeriesWrap<ArrayChunked> {16fn compute_len(&mut self) {17self.0.compute_len()18}19fn _field(&self) -> Cow<'_, Field> {20Cow::Borrowed(self.0.ref_field())21}22fn _dtype(&self) -> &DataType {23self.0.ref_field().dtype()24}2526fn _get_flags(&self) -> StatisticsFlags {27self.0.get_flags()28}2930fn _set_flags(&mut self, flags: StatisticsFlags) {31self.0.set_flags(flags)32}3334unsafe fn equal_element(&self, idx_self: usize, idx_other: usize, other: &Series) -> bool {35self.0.equal_element(idx_self, idx_other, other)36}3738fn vec_hash(39&self,40build_hasher: PlSeedableRandomStateQuality,41buf: &mut Vec<u64>,42) -> PolarsResult<()> {43_get_rows_encoded_ca_unordered(PlSmallStr::EMPTY, &[self.0.clone().into_column()])?44.vec_hash(build_hasher, buf)45}4647fn vec_hash_combine(48&self,49build_hasher: PlSeedableRandomStateQuality,50hashes: &mut [u64],51) -> PolarsResult<()> {52_get_rows_encoded_ca_unordered(PlSmallStr::EMPTY, &[self.0.clone().into_column()])?53.vec_hash_combine(build_hasher, hashes)54}5556#[cfg(feature = "zip_with")]57fn zip_with_same_type(&self, mask: &BooleanChunked, other: &Series) -> PolarsResult<Series> {58ChunkZip::zip_with(&self.0, mask, other.as_ref().as_ref()).map(|ca| ca.into_series())59}6061#[cfg(feature = "algorithm_group_by")]62unsafe fn agg_list(&self, groups: &GroupsType) -> Series {63self.0.agg_list(groups)64}6566#[cfg(feature = "algorithm_group_by")]67fn group_tuples(&self, multithreaded: bool, sorted: bool) -> PolarsResult<GroupsType> {68IntoGroupsType::group_tuples(&self.0, multithreaded, sorted)69}7071fn add_to(&self, rhs: &Series) -> PolarsResult<Series> {72self.0.add_to(rhs)73}7475fn subtract(&self, rhs: &Series) -> PolarsResult<Series> {76self.0.subtract(rhs)77}7879fn multiply(&self, rhs: &Series) -> PolarsResult<Series> {80self.0.multiply(rhs)81}82fn divide(&self, rhs: &Series) -> PolarsResult<Series> {83self.0.divide(rhs)84}85fn remainder(&self, rhs: &Series) -> PolarsResult<Series> {86self.0.remainder(rhs)87}8889fn into_total_eq_inner<'a>(&'a self) -> Box<dyn TotalEqInner + 'a> {90invalid_operation_panic!(into_total_eq_inner, self)91}92fn into_total_ord_inner<'a>(&'a self) -> Box<dyn TotalOrdInner + 'a> {93invalid_operation_panic!(into_total_ord_inner, self)94}95}9697impl SeriesTrait for SeriesWrap<ArrayChunked> {98fn rename(&mut self, name: PlSmallStr) {99self.0.rename(name);100}101102fn chunk_lengths(&self) -> ChunkLenIter<'_> {103self.0.chunk_lengths()104}105fn name(&self) -> &PlSmallStr {106self.0.name()107}108109fn chunks(&self) -> &Vec<ArrayRef> {110self.0.chunks()111}112unsafe fn chunks_mut(&mut self) -> &mut Vec<ArrayRef> {113self.0.chunks_mut()114}115fn shrink_to_fit(&mut self) {116self.0.shrink_to_fit()117}118119fn arg_sort(&self, options: SortOptions) -> IdxCa {120let slf = (*self).clone();121let slf = slf.into_column();122arg_sort_row_fmt(123&[slf],124options.descending,125options.nulls_last,126options.multithreaded,127)128.unwrap()129}130131fn sort_with(&self, options: SortOptions) -> PolarsResult<Series> {132let idxs = self.arg_sort(options);133let mut result = unsafe { self.take_unchecked(&idxs) };134result.set_sorted_flag(if options.descending {135IsSorted::Descending136} else {137IsSorted::Ascending138});139Ok(result)140}141142fn slice(&self, offset: i64, length: usize) -> Series {143self.0.slice(offset, length).into_series()144}145146fn split_at(&self, offset: i64) -> (Series, Series) {147let (a, b) = self.0.split_at(offset);148(a.into_series(), b.into_series())149}150151fn append(&mut self, other: &Series) -> PolarsResult<()> {152polars_ensure!(self.0.dtype() == other.dtype(), append);153let other = other.array()?;154self.0.append(other)155}156fn append_owned(&mut self, other: Series) -> PolarsResult<()> {157polars_ensure!(self.0.dtype() == other.dtype(), append);158self.0.append_owned(other.take_inner())159}160161fn extend(&mut self, other: &Series) -> PolarsResult<()> {162polars_ensure!(self.0.dtype() == other.dtype(), extend);163self.0.extend(other.as_ref().as_ref())164}165166fn filter(&self, filter: &BooleanChunked) -> PolarsResult<Series> {167ChunkFilter::filter(&self.0, filter).map(|ca| ca.into_series())168}169170fn take(&self, indices: &IdxCa) -> PolarsResult<Series> {171Ok(self.0.take(indices)?.into_series())172}173174unsafe fn take_unchecked(&self, indices: &IdxCa) -> Series {175self.0.take_unchecked(indices).into_series()176}177178fn take_slice(&self, indices: &[IdxSize]) -> PolarsResult<Series> {179Ok(self.0.take(indices)?.into_series())180}181182unsafe fn take_slice_unchecked(&self, indices: &[IdxSize]) -> Series {183self.0.take_unchecked(indices).into_series()184}185186fn len(&self) -> usize {187self.0.len()188}189190fn rechunk(&self) -> Series {191self.0.rechunk().into_owned().into_series()192}193194fn new_from_index(&self, index: usize, length: usize) -> Series {195ChunkExpandAtIndex::new_from_index(&self.0, index, length).into_series()196}197198fn trim_lists_to_normalized_offsets(&self) -> Option<Series> {199self.0200.trim_lists_to_normalized_offsets()201.map(IntoSeries::into_series)202}203204fn propagate_nulls(&self) -> Option<Series> {205self.0.propagate_nulls().map(IntoSeries::into_series)206}207208fn cast(&self, dtype: &DataType, options: CastOptions) -> PolarsResult<Series> {209self.0.cast_with_options(dtype, options)210}211212#[inline]213unsafe fn get_unchecked(&self, index: usize) -> AnyValue<'_> {214self.0.get_any_value_unchecked(index)215}216217fn null_count(&self) -> usize {218self.0.null_count()219}220221fn has_nulls(&self) -> bool {222self.0.has_nulls()223}224225fn is_null(&self) -> BooleanChunked {226self.0.is_null()227}228229fn is_not_null(&self) -> BooleanChunked {230self.0.is_not_null()231}232233fn reverse(&self) -> Series {234ChunkReverse::reverse(&self.0).into_series()235}236237fn as_single_ptr(&mut self) -> PolarsResult<usize> {238self.0.as_single_ptr()239}240241fn shift(&self, periods: i64) -> Series {242ChunkShift::shift(&self.0, periods).into_series()243}244245fn clone_inner(&self) -> Arc<dyn SeriesTrait> {246Arc::new(SeriesWrap(Clone::clone(&self.0)))247}248249fn find_validity_mismatch(&self, other: &Series, idxs: &mut Vec<IdxSize>) {250self.0.find_validity_mismatch(other, idxs)251}252253fn as_any(&self) -> &dyn Any {254&self.0255}256257fn as_any_mut(&mut self) -> &mut dyn Any {258&mut self.0259}260261fn as_phys_any(&self) -> &dyn Any {262&self.0263}264265fn as_arc_any(self: Arc<Self>) -> Arc<dyn Any + Send + Sync> {266self as _267}268}269270271