Path: blob/main/crates/polars-core/src/series/implementations/string.rs
8408 views
use super::*;1use crate::chunked_array::comparison::*;2#[cfg(feature = "algorithm_group_by")]3use crate::frame::group_by::*;4use crate::prelude::*;56impl private::PrivateSeries for SeriesWrap<StringChunked> {7fn compute_len(&mut self) {8self.0.compute_len()9}10fn _field(&self) -> Cow<'_, Field> {11Cow::Borrowed(self.0.ref_field())12}13fn _dtype(&self) -> &DataType {14self.0.ref_field().dtype()15}1617fn _set_flags(&mut self, flags: StatisticsFlags) {18self.0.set_flags(flags)19}20fn _get_flags(&self) -> StatisticsFlags {21self.0.get_flags()22}23unsafe fn equal_element(&self, idx_self: usize, idx_other: usize, other: &Series) -> bool {24self.0.equal_element(idx_self, idx_other, other)25}2627#[cfg(feature = "zip_with")]28fn zip_with_same_type(&self, mask: &BooleanChunked, other: &Series) -> PolarsResult<Series> {29ChunkZip::zip_with(&self.0, mask, other.as_ref().as_ref()).map(|ca| ca.into_series())30}31fn into_total_eq_inner<'a>(&'a self) -> Box<dyn TotalEqInner + 'a> {32(&self.0).into_total_eq_inner()33}34fn into_total_ord_inner<'a>(&'a self) -> Box<dyn TotalOrdInner + 'a> {35(&self.0).into_total_ord_inner()36}3738fn vec_hash(39&self,40random_state: PlSeedableRandomStateQuality,41buf: &mut Vec<u64>,42) -> PolarsResult<()> {43self.0.vec_hash(random_state, buf)?;44Ok(())45}4647fn vec_hash_combine(48&self,49build_hasher: PlSeedableRandomStateQuality,50hashes: &mut [u64],51) -> PolarsResult<()> {52self.0.vec_hash_combine(build_hasher, hashes)?;53Ok(())54}5556#[cfg(feature = "algorithm_group_by")]57unsafe fn agg_list(&self, groups: &GroupsType) -> Series {58self.0.agg_list(groups)59}6061#[cfg(feature = "algorithm_group_by")]62unsafe fn agg_min(&self, groups: &GroupsType) -> Series {63self.0.agg_min(groups)64}6566#[cfg(feature = "algorithm_group_by")]67unsafe fn agg_max(&self, groups: &GroupsType) -> Series {68self.0.agg_max(groups)69}7071#[cfg(feature = "algorithm_group_by")]72unsafe fn agg_arg_min(&self, groups: &GroupsType) -> Series {73self.0.agg_arg_min(groups)74}7576#[cfg(feature = "algorithm_group_by")]77unsafe fn agg_arg_max(&self, groups: &GroupsType) -> Series {78self.0.agg_arg_max(groups)79}8081fn subtract(&self, rhs: &Series) -> PolarsResult<Series> {82NumOpsDispatch::subtract(&self.0, rhs)83}84fn add_to(&self, rhs: &Series) -> PolarsResult<Series> {85NumOpsDispatch::add_to(&self.0, rhs)86}87fn multiply(&self, rhs: &Series) -> PolarsResult<Series> {88NumOpsDispatch::multiply(&self.0, rhs)89}90fn divide(&self, rhs: &Series) -> PolarsResult<Series> {91NumOpsDispatch::divide(&self.0, rhs)92}93fn remainder(&self, rhs: &Series) -> PolarsResult<Series> {94NumOpsDispatch::remainder(&self.0, rhs)95}96#[cfg(feature = "algorithm_group_by")]97fn group_tuples(&self, multithreaded: bool, sorted: bool) -> PolarsResult<GroupsType> {98IntoGroupsType::group_tuples(&self.0, multithreaded, sorted)99}100101fn arg_sort_multiple(102&self,103by: &[Column],104options: &SortMultipleOptions,105) -> PolarsResult<IdxCa> {106self.0.arg_sort_multiple(by, options)107}108}109110impl SeriesTrait for SeriesWrap<StringChunked> {111fn rename(&mut self, name: PlSmallStr) {112self.0.rename(name);113}114115fn chunk_lengths(&self) -> ChunkLenIter<'_> {116self.0.chunk_lengths()117}118fn name(&self) -> &PlSmallStr {119self.0.name()120}121122fn chunks(&self) -> &Vec<ArrayRef> {123self.0.chunks()124}125unsafe fn chunks_mut(&mut self) -> &mut Vec<ArrayRef> {126self.0.chunks_mut()127}128fn shrink_to_fit(&mut self) {129self.0.shrink_to_fit()130}131132fn slice(&self, offset: i64, length: usize) -> Series {133self.0.slice(offset, length).into_series()134}135fn split_at(&self, offset: i64) -> (Series, Series) {136let (a, b) = self.0.split_at(offset);137(a.into_series(), b.into_series())138}139140fn append(&mut self, other: &Series) -> PolarsResult<()> {141polars_ensure!(self.0.dtype() == other.dtype(), append);142// todo! add object143self.0.append(other.as_ref().as_ref())?;144Ok(())145}146fn append_owned(&mut self, other: Series) -> PolarsResult<()> {147polars_ensure!(self.0.dtype() == other.dtype(), append);148// todo! add object149self.0.append_owned(other.take_inner())150}151152fn extend(&mut self, other: &Series) -> PolarsResult<()> {153polars_ensure!(154self.0.dtype() == other.dtype(),155SchemaMismatch: "cannot extend Series: data types don't match",156);157self.0.extend(other.as_ref().as_ref())?;158Ok(())159}160161fn filter(&self, filter: &BooleanChunked) -> PolarsResult<Series> {162ChunkFilter::filter(&self.0, filter).map(|ca| ca.into_series())163}164165fn take(&self, indices: &IdxCa) -> PolarsResult<Series> {166Ok(self.0.take(indices)?.into_series())167}168169unsafe fn take_unchecked(&self, indices: &IdxCa) -> Series {170self.0.take_unchecked(indices).into_series()171}172173fn take_slice(&self, indices: &[IdxSize]) -> PolarsResult<Series> {174Ok(self.0.take(indices)?.into_series())175}176177unsafe fn take_slice_unchecked(&self, indices: &[IdxSize]) -> Series {178self.0.take_unchecked(indices).into_series()179}180181fn deposit(&self, validity: &Bitmap) -> Series {182self.0.deposit(validity).into_series()183}184185fn len(&self) -> usize {186self.0.len()187}188189fn rechunk(&self) -> Series {190self.0.rechunk().into_owned().into_series()191}192193fn new_from_index(&self, index: usize, length: usize) -> Series {194ChunkExpandAtIndex::new_from_index(&self.0, index, length).into_series()195}196197fn cast(&self, dtype: &DataType, cast_options: CastOptions) -> PolarsResult<Series> {198self.0.cast_with_options(dtype, cast_options)199}200201#[inline]202unsafe fn get_unchecked(&self, index: usize) -> AnyValue<'_> {203self.0.get_any_value_unchecked(index)204}205206fn sort_with(&self, options: SortOptions) -> PolarsResult<Series> {207Ok(ChunkSort::sort_with(&self.0, options).into_series())208}209210fn arg_sort(&self, options: SortOptions) -> IdxCa {211ChunkSort::arg_sort(&self.0, options)212}213214fn null_count(&self) -> usize {215self.0.null_count()216}217218fn has_nulls(&self) -> bool {219self.0.has_nulls()220}221222#[cfg(feature = "algorithm_group_by")]223fn unique(&self) -> PolarsResult<Series> {224ChunkUnique::unique(&self.0).map(|ca| ca.into_series())225}226227#[cfg(feature = "algorithm_group_by")]228fn n_unique(&self) -> PolarsResult<usize> {229ChunkUnique::n_unique(&self.0)230}231232#[cfg(feature = "algorithm_group_by")]233fn arg_unique(&self) -> PolarsResult<IdxCa> {234ChunkUnique::arg_unique(&self.0)235}236237fn unique_id(&self) -> PolarsResult<(IdxSize, Vec<IdxSize>)> {238ChunkUnique::unique_id(&self.0)239}240241fn is_null(&self) -> BooleanChunked {242self.0.is_null()243}244245fn is_not_null(&self) -> BooleanChunked {246self.0.is_not_null()247}248249fn reverse(&self) -> Series {250ChunkReverse::reverse(&self.0).into_series()251}252253fn as_single_ptr(&mut self) -> PolarsResult<usize> {254self.0.as_single_ptr()255}256257fn shift(&self, periods: i64) -> Series {258ChunkShift::shift(&self.0, periods).into_series()259}260261fn sum_reduce(&self) -> PolarsResult<Scalar> {262Err(polars_err!(263op = "`sum`",264DataType::String,265hint = "you may mean to call `str.join` or `list.join`"266))267}268fn max_reduce(&self) -> PolarsResult<Scalar> {269Ok(ChunkAggSeries::max_reduce(&self.0))270}271fn min_reduce(&self) -> PolarsResult<Scalar> {272Ok(ChunkAggSeries::min_reduce(&self.0))273}274275#[cfg(feature = "approx_unique")]276fn approx_n_unique(&self) -> PolarsResult<IdxSize> {277Ok(ChunkApproxNUnique::approx_n_unique(&self.0))278}279280fn clone_inner(&self) -> Arc<dyn SeriesTrait> {281Arc::new(SeriesWrap(Clone::clone(&self.0)))282}283284fn find_validity_mismatch(&self, other: &Series, idxs: &mut Vec<IdxSize>) {285self.0.find_validity_mismatch(other, idxs)286}287288fn as_any(&self) -> &dyn Any {289&self.0290}291292fn as_any_mut(&mut self) -> &mut dyn Any {293&mut self.0294}295296fn as_phys_any(&self) -> &dyn Any {297&self.0298}299300fn as_arc_any(self: Arc<Self>) -> Arc<dyn Any + Send + Sync> {301self as _302}303}304305306